Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: modulus and floating point numbers

by BrowserUk (Patriarch)
on Nov 18, 2008 at 02:57 UTC ( [id://724180]=note: print w/replies, xml ) Need Help??


in reply to modulus and floating point numbers

Whether it's faster or not you'll have to determine yourself, but it's another way:

use POSIX qw[ fmod ];; print fmod( $_, 100 ) for 12300, 12301, 12399;; 0 1 99

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: modulus and floating point numbers
by dextius (Monk) on Nov 18, 2008 at 03:15 UTC
    how about .00001 ?

      I'm not sure if I understand the question, but:

      [0] Perl> print fmod( $_, 100 ) for 12300, 12301, 12399, .00001;; 0 1 99 1e-005

      Or do you mean this:

      [0] Perl> print fmod( $_, 1 ) for map{ ($_, -$_ ) } 12300, 12301, 1239 +9, .00001;; 0 0 0 0 0 0 1e-005 -1e-005

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://724180]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-23 20:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found