Re: NAN and INF cast to int

From: Date: Mon, 06 Jan 2014 15:22:14 +0000
Subject: Re: NAN and INF cast to int
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-71018@lists.php.net to get a copy of this message
Robert Stoll wrote:
I'm +1 to make div by zero return INF.
This begs the question 'how' ... If we are processing to integer values they produce an integer result and there is no provision for a 'number' INF. This is the exact sort of request that prompted my recent article on 'what is a number' ...
PHP behaves already different. 1/2 = 0.5 So it would be perfectly valid to define 2/0 = INF Personally, I would prefer to keep false for a division with two integers (e.g. 1/0) but would change the result as follows if a float is involved 1.0/0 = INF 1/0.0 = INF 0.0/0 = NAN 0/0.0 = NAN pretty much as other language behave (right?).
But that is not 'cast to int' ... http://phpsurgery.org/wiki/integer is my take on some of this, and if you follow the results on stackoverflow asking why there is not a NAN or INF value for numbers in other languages you will see that your list only works for 'float' ... but mapping everything to float is wrong? The real problem here is what 'container' is created when calculating int(x) / int(y) = ??? 27/3 can give a clean int(9), but 27/2 has a remainder and 27/0 can't produce an int() result? Some other container needs to be created? -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

Thread (13 messages)

« previous php.internals (#71018) next »