Re: NAN and INF cast to int
| From: | Andrea Faulds | Date: | Mon, 06 Jan 2014 18:39:17 +0000 |
| Subject: | Re: NAN and INF cast to int | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-71025@lists.php.net to get a copy of this message | ||
On 06/01/14 15:22, Lester Caine wrote:
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?It'd be float in both cases, and I see nothing wrong with implicit float conversion when using int to represent isn't possible any more. But if we must, I suppose we might be able to make an "integer" INF value, though I expect that'd require too much effort to be worth it. Also, having special-value integers wouldn't be nice. When something's of a float type, you know it might be special. With ints, you know it can never be. So I see nothing wrong with float(inf) here. -- Andrea Faulds http://ajf.me/