perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

Add is_inf and is_nan functions to builtin::

Open leonerd opened this issue 1 year ago • 2 comments

As it is not expected that these two functions are likely to be called very often, I didn't bother making inlined-opcode variants of them as per e.g. is_bool(). Instead these are just regular XSUBs like trim() is.

Testing-wise, I'm a little unsure about the use of 1 * (inf - inf) to get a calculated NaN value, but I really couldn't think of anything else that actually works. Is it portable enough?

leonerd avatar Mar 01 '24 23:03 leonerd

Another issue with this (and ceil(), floor() for that matter), is it doesn't support overloads in the same way other numeric functions do, e.g.:

use overload sin => sub { ... };

It's less of an issue if the 0+ overload returns a Inf/Nan as needed (which this code also doesn't support), but I can see it as an issue for ceil/floor with bignum-ish overloads.

tonycoz avatar Mar 03 '24 23:03 tonycoz

Another issue with this (and ceil(), floor() for that matter), is it doesn't support overloads in the same way other numeric functions do, e.g.:

use overload sin => sub { ... };

It's less of an issue if the 0+ overload returns a Inf/Nan as needed (which this code also doesn't support), but I can see it as an issue for ceil/floor with bignum-ish overloads.

@leonerd, @tonycoz has noted some significant problems with this pull request. Do you wish to pursue it further? Thanks.

jkeenan avatar Jun 13 '24 13:06 jkeenan