[Z88dk-users] Conversion from double to int

Bridge to the z88dk-users mailing list
Post Reply
James King

[Z88dk-users] Conversion from double to int

Post by James King »

Hey,
I've got an easy question for you for a change! When you typecast doubles to ints, does the compiler truncate the value or round the value? If I remember correctly this is compiler specific.
Example:

...
double num1=10.5;
int num2=(int)num1;

...
Does num2 become 10 or 11? Let me know,
James

Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
User avatar
dom
Well known member
Posts: 2091
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

On Fri, 19 Mar 2004, James King wrote:

Hey, I've got an easy question for you for a change! When you typecast
doubles to ints, does the compiler truncate the value or round the
value? If I remember correctly this is compiler specific.

You think that's an easy question? <grin>

I believe genmath floor()s the number so truncation.

The other maths libraries (ZX,cpc,z88) call the appropriate maths routine
in the ROM, I'm guessing that they also truncate.

cheers,

d.




-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
Post Reply