in reply to How to determine MIN and MAX values for floating point number
#!/usr/bin/perl # get the largest and smallest float usable without # Math::BigFloat my $i = 1.0; my $lasti; my $bignum; for ( ; ; ) { $bignum = $lasti; $lasti = $i; $i *= 2; #print $i,"\n"; last if ( $i == $lasti ); } print "$bignum\n"; #The last number before "inf" is your largest representable #float (8.98846567431158e+307 on my system). #A similar trick with division by 2 will give you the smallest #representable float (4.94065645841247e-324 on my system). $i = 1.0; $lasti; my $smallnum; for ( ; ; ) { $smallnum = $lasti; $lasti = $i; $i /= 2; #print $i,"\n"; last if ( $i == $lasti ); } print "$smallnum\n";
|
|---|