mIRC Home    About    Download    Register    News    Help

Print Thread
#6832 16/01/03 02:00 PM
Joined: Dec 2002
Posts: 145
G
Vogon poet
OP Offline
Vogon poet
G
Joined: Dec 2002
Posts: 145
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
Joined: Dec 2002
Posts: 66
Babel fish
Offline
Babel fish
Joined: Dec 2002
Posts: 66
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.


- Linux System Administrator, Darktides Communications, LLC.
#6834 17/01/03 09:44 AM
Joined: Jan 2003
Posts: 94
S
Babel fish
Offline
Babel fish
S
Joined: Jan 2003
Posts: 94
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)


-
E-Mail: mirc_sabby@hotmail.com
Network: irc.enterthegame.com
Channel: #Helpdesk
#6835 18/01/03 04:51 AM
Joined: Dec 2002
Posts: 66
Babel fish
Offline
Babel fish
Joined: Dec 2002
Posts: 66
The point is $int(1.9999999) is returning 2, which it shouldn't.


- Linux System Administrator, Darktides Communications, LLC.
#6836 18/01/03 10:49 AM
Joined: Dec 2002
Posts: 89
N
Babel fish
Offline
Babel fish
N
Joined: Dec 2002
Posts: 89
I bet it has something to do with string output - try printf("%g",1.999999); to see what I mean.


Sincerely,
Necroman, #mIRC @ Undernet
#6837 18/01/03 11:47 AM
Joined: Dec 2002
Posts: 66
Babel fish
Offline
Babel fish
Joined: Dec 2002
Posts: 66
Well.. why wouldn't he just do [ws|s]printf("%d",(int)1.999999);


- Linux System Administrator, Darktides Communications, LLC.
#6838 19/01/03 02:21 AM
Joined: Dec 2002
Posts: 46
Z
zac Offline
Ameglian cow
Offline
Ameglian cow
Z
Joined: Dec 2002
Posts: 46
Reproducing it.

//echo -a $int(1.9999999)
2

//echo -a $int(1.9)
1


Link Copied to Clipboard