How do I create or test for NaN or infinity in Perl?

ysth picture ysth · Jul 27, 2009 · Viewed 13.1k times · Source

How do I create or test for NaN or infinite values in Perl?

Answer

Hynek -Pichi- Vychodil picture Hynek -Pichi- Vychodil · Jul 27, 2009
print "Is NaN\n" if $a eq 'nan';
print "Is Inf\n" if $a eq 'inf' or $a eq '-inf';

EDIT: Fixed for negative infinity.