z88dk forums

z80 Development Kit

You are not logged in.

#1 2004-03-20 03:15:13

James King
Guest

[Z88dk-users] Conversion from double to int

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.

 

#2 2004-03-20 11:00:06

dom
Administrator
Registered: 2007-07-15
Posts: 738
Website

Re: [Z88dk-users] Conversion from double to int

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

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson