Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

(tye)Re: Defining Arrays

by tye (Sage)
on May 17, 2001 at 19:19 UTC ( [id://81270]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Defining Arrays
in thread Defining Arrays

FYI, I see no advantage to this method whatsoever.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: Defining Arrays
by Masem (Monsignor) on May 17, 2001 at 19:38 UTC
    I don't see it happening in this specific case, but in the general case, I would expect that I'll start seeing floating point errors when you do the division, particulary if you got away from multiples of 10, eg, increments of 0.2, 0.5 or so on. Mind you, I don't think this map solution works as cleanly as in this case (thus resorting to a basic for loop)....
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

      If you were proposing this as an alternative to doing, for example: for( $i= 1.5; $i < 9.5; $i += 0.1 ) { then, yes, you are correct that errors could start to appear.

      But the node that you replied to doesn't suffer from such problems.

      As another data point, if you wanted to go from 1.2 to 3.6 in steps of 0.12, you could do this:

      for( $i= 120; $i <= 360; $i += 12 ) { push @n, $i/100; }
      without risk of errors sneaking in.

      The problem results from repeatedly adding something like 0.1 to a number since, in binary floating point, isn't exactly 0.1:

      printf "%.30f", 0.1 # prints 0.100000000000000010000000000000

              - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2024-04-23 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found