Re: Should %d round?

new topic     » goto parent     » topic index » view thread      » older message » newer message
kenneth said...

"floor()" rounds down, while "%.0f" rounds toward zero. Be careful what you ask for.

Yeah, I was sorta wondering about what floor did, exactly, with negative numbers:

printf(1, "%d %.0f\n", -3.1 ) -- -4 -3 
printf(1, "%d %.0f\n", -3.9 ) -- -4 -4 

Your description of "%.0f" is incorrect. It seems to simply round as one would expect.

kenneth said...

I still say a programming language that doesn't store numbers by explicit type shouldn't be used for arithmetic.

You're certainly welcome to that opinion, but it doesn't seem to make much sense to me. Euphoria does use explicit types, actually, and is pretty up front about them. Perhaps you were thinking about perl, or python, which can end up using its bignum if you overflow too much.

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu