Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > isnan(), fpclassify()

Reply
Thread Tools

isnan(), fpclassify()

 
 
BZ
Guest
Posts: n/a
 
      08-24-2005
Hi!

I was wondering if the functionality of the C99 function isnan(),
isinf() and fp_classify() are available in perl.

Or even better, is it possible to get printf to recognise things like
'nan' and 'inf' as floats? They seems to be interpreted as text by
default:

[bas@matilda]~> perl -e 'printf "%e %e %e %e\n", "123", "nan", "inf", "-inf";'
1.230000e+02 0.000000e+00 0.000000e+00 -0.000000e+00


--
BZ
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      08-24-2005
BZ wrote:
> I was wondering if the functionality of the C99 function isnan(),
> isinf() and fp_classify() are available in perl.
>
> Or even better, is it possible to get printf to recognise things like
> 'nan' and 'inf' as floats?


Have a look at the Math::BigFloat module
(http://search.cpan.org/~tels/Math-Bi...th/BigFloat.pm)
and see if that suits your needs.

> They seems to be interpreted as text by
> default:
>
> [bas@matilda]~> perl -e 'printf "%e %e %e %e\n", "123", "nan", "inf", "-inf";'
> 1.230000e+02 0.000000e+00 0.000000e+00 -0.000000e+00


Correct. Any string that does not "look" like a number is treated as
the number 0 in numeric context.

Paul Lalli

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments