Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Mathematical Functions : is_infinite

is_infinite

Finds whether a value is infinite (PHP 4 >= 4.2.0, PHP 5)
bool is_infinite ( float val )


Code Examples / Notes » is_infinite

david @t nirvanis d@t org

If you have PHP lower than 4.2 you can simulate the behaviour:
function is_infinite($value) {
  return (substr("$value",-3) == "INF");
}
(tested on php 4.1.2)


stangelanda

Actually any string ending in INF is more appropriate than any string beginning with INF.  Since negative infinity evaluates to "-INF" but it is still infinite.  However in either case the STRING "INF" is not infinite, only a float that converts to "INF" or "-INF" is infinite.
A more appropriate function might be:
<?php
if (!is_defined('is_infinite')) { function is_infinite($val) {
   return (is_float($val) and ("$val"=='INF' or "$val"=='-INF'));
} }
?>
* However the above function is untested.


21-aug-2006 04:54

@ david,
That will return true for any string ending with "INF".
I think substr("$value",0,3) would be more appropriate.


Change Language


Follow Navioo On Twitter
abs
acos
acosh
asin
asinh
atan2
atan
atanh
base_convert
bindec
ceil
cos
cosh
decbin
dechex
decoct
deg2rad
exp
expm1
floor
fmod
getrandmax
hexdec
hypot
is_finite
is_infinite
is_nan
lcg_value
log10
log1p
log
max
min
mt_getrandmax
mt_rand
mt_srand
octdec
pi
pow
rad2deg
rand
round
sin
sinh
sqrt
srand
tan
tanh
eXTReMe Tracker