mIRC Home    About    Download    Register    News    Help

Print Thread
#6832 16/01/03 02:00 PM
Joined: Dec 2002
Posts: 143
G
Vogon poet
OP Offline
Vogon poet
G
Joined: Dec 2002
Posts: 143
Obviously, I am not a programmer ... frown

$int(N)
Returns the integer part of a floating point number with no rounding.

$int(1.999999) = 1

$int(1.9999999) = 2

Why would a function which is dropping decimals without rounding do round after the sixth decimal and return a wrong answer?

Why can it simply drop all decimals regardless of the number of decimals?

gemeau50

#6833 16/01/03 03:11 PM
G
GrimZ
GrimZ
G
I'd say you found a bug. ;-)

My guess (and I'm probably right) is $int() does nothing more than return an (int) type cast to the number.

I doubt it's a bug in C/C++ (I've never noticed it when working with > 7 digit decimal floating points/doubles.

Perhaps you post this in the Bug Reports forum.

#6834 17/01/03 09:44 AM
S
Sabby
Sabby
S
all $int does is return the number value without the decimal.
its the same as $gettok(1.99999,1,46)

if you want to round the number you must use $round(1.9999,0)

#6835 18/01/03 04:51 AM
G
GrimZ
GrimZ
G
The point is $int(1.9999999) is returning 2, which it shouldn't.

#6836 18/01/03 10:49 AM
N
Necroman
Necroman
N
I bet it has something to do with string output - try printf("%g",1.999999); to see what I mean.

#6837 18/01/03 11:47 AM
G
GrimZ
GrimZ
G
Well.. why wouldn't he just do [ws|s]printf("%d",(int)1.999999);

#6838 19/01/03 02:21 AM
Z
zac
zac
Z
Reproducing it.

//echo -a $int(1.9999999)
2

//echo -a $int(1.9)
1


Link Copied to Clipboard