CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Signed Long and Constant Multiplication

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nikolai



Joined: 28 Apr 2010
Posts: 5
Location: Houston

View user's profile Send private message

Signed Long and Constant Multiplication
PostPosted: Wed Apr 28, 2010 7:08 am     Reply with quote

I am using an older version of the compiler: v3.249

I believe I may have found a bug, which may have actually been corrected in recent releases, but I don't want to pay for the upgrade unless I am sure that it will resolve the issue. When I multiple a signed int16 (long) with a value of -1 (65535) by a constant, the result is not what I am expecting.

Code:
void main()
{
   signed long i=-1;
   signed long r=0;
   
   r = i * 1000;   // result should be -1000
                   // but I get -744, which is 256 too low
}


I have tried performing the calculation by hand and truncating the 32bit result with no success in finding the source of the error. Can someone try this on a more recent version of the compiler to confirm that this issue has been addressed already?
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Wed Apr 28, 2010 7:16 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=29773&highlight=math

I ran across something similar a few years ago. Read through the posts for a fix that may work for you.
nikolai



Joined: 28 Apr 2010
Posts: 5
Location: Houston

View user's profile Send private message

PostPosted: Wed Apr 28, 2010 7:32 am     Reply with quote

Thanks. Changing the order does give me the correct results. I wonder if this was ever fixed.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group