in reply to Re: How to determine whether a number has a decimal component?
in thread How to determine whether a number has a decimal component?

Well you could use

print "contains fractional component\n" if $number =~ /\.(?!0*$)/;

But that'll fail for large numbers.

sub r { $_[0] ? 'fractional' : 'integer' } for my $n ( '1.00', 2**50, ) { print( "$n:\n", "method 1: ", r( $n =~ /\./ ), "\n", "method 2: ", r( $n =~ /\.(?!0*$)/ ), "\n", "method 3: ", r( sprintf('%f',$n) =~ /\.(?!0*$)/ ), "\n", "method 4: ", r( int($_)!=$_ ), "\n", "\n", ); }
1.00: method 1: fractional method 2: integer method 3: integer method 4: integer 1.12589990684262e+015: method 1: fractional method 2: fractional method 3: integer method 4: integer

Replies are listed 'Best First'.
Re^3: How to determine whether a number has a decimal component?
by Xenofur (Monk) on Jan 04, 2009 at 22:10 UTC
    Shouldn't one use bignum either ways when going over 32 bit?

      Depends. It's a cost-benefit tradeoff. If the use of floats is appropriate, 53 bits of precision is probably way more than enough.

      By the way, Perl natively supports (without loss of precision) integer numbers (as in numbers without a fractional component) up to 2**53 (or higher depending on platform and build options), not 2**32-1.