RE: [PHP-DEV] NAN and INF cast to int

From: Date: Mon, 06 Jan 2014 14:23:27 +0000
Subject: RE: [PHP-DEV] NAN and INF cast to int
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-71017@lists.php.net to get a copy of this message
> -----Original Message----- > From: Lester Caine [mailto:lester@lsces.co.uk] > Sent: Monday, January 06, 2014 3:16 PM > To: PHP internals > Subject: Re: [PHP-DEV] NAN and INF cast to int > > Julien Pauli 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?). > The bottom line is that 'int' simply does not have any means of returning NAN or > INF so why are you even discussing it? It is messages relating to an 'int' > object that need handling? Divide when divisor is '0' is a state that needs > handling by the code, what ever the type of number object. > > As Rasmus has indicated, how a platform handles these edge cases is the > inconsistent bit that needs documenting, and this is another aspect I need to > add to my notes ... > > -- > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.internals (#71017) next »