Loading ...
Sorry, an error occurred while loading the content.

Misc. NetLogo questions

Expand Messages
  • Seth Tisue
    A user wrote with some questions/problems I thought people might be ... It is a limitation of IEEE floating point arithmetic in general (Java implements the
    Message 1 of 1 , Jun 4, 2002
    • 0 Attachment
      A user wrote with some questions/problems I thought people might be
      interested in the answers to:

      > Some numbers when generated seem to be slightly off. eg, some
      > values are reported as "0.10000000004" or "0.799999999999"
      > rather than 0.1 or 0.8, while others are okay (the math being
      > done should not result in anything other than single decimal
      > place numbers). I had this problem with the early versions of
      > Netlogo beta 3a and prior) but the problem went away, as I
      > recall, when I upgraded from IE5 to IE5.5--so is this a Java
      > problem?

      It is a limitation of IEEE floating point arithmetic in general (Java
      implements the IEEE standard), but there are some places when NetLogo
      should compensate for it and doesn't. We fixed a number of them in
      the betas leading up to 1.0, and fixes for one more will appear in 1.1
      (namely, sliders will no longer occasionally produce such slightly-off
      numbers). But in general, you shouldn't expect floating point
      arithmetic to produce absolutely exact answers. The "precision"
      primitive is handy for rounding off numbers for display purposes.

      If you encounter a specific instance of this problem and are not sure
      whether it falls into the "blame NetLogo" category or the "blame
      floating point arithmetic in general" category, run it by us and we'll
      take a look.

      One more note: agent monitors have been redesigned for version 1.1 so
      they're always wide enough to display all decimal places -- in 1.0
      sometimes it's confusing because the entire number doesn't appear.

      > More on lists...some of the commands seem cumbersome, eg, list
      > primitive takes TWO reporters, rather than just one.

      We plan to change it so that you can use parentheses to make it take
      any number of arguments from 0 on up.

      > Remove removes everything (if it works) of the same value
      > rather than just one.

      Here's how to remove only the first occurrence:

      to-report remove-first [x l]
      locals [pos]
      set pos position x l
      ifelse pos = false
      [ report l ]
      [ report remove-nth pos l ]
      end

      to-report remove-nth [pos l]
      ifelse pos = 0
      [ report butfirst l ]
      [ report fput (first l)
      (remove-nth (pos - 1)
      (butfirst l)) ]
      end

      Or you could use this sneaky (but easier to understand) hack:

      to-report remove-first [x l]
      locals [pos]
      set pos position x l
      ifelse pos = false
      [ report l ]
      [ report remove "" (replace-item pos l "") ]
      end

      but note this won't work if "" already appears in the list..!

      > An other-turtles primitive would be useful, so that a turtle
      > can ask all other turtles rather than only those -at or -here.

      You can accomplish this as follows:

      ask turtles with [who != who-of myself] [ ... ]

      but we do plan to add other-turtles anyway, since it will result in
      clearer code and we can make it run faster too.

      > The identity of a turtle, when determined by a patch, seems to
      > incorporate "turtle" into the variable (if so set). This makes
      > using turtle identifiers more tricky (although I think the
      > workaround of using value-from does the trick).

      This is intentional, and we believe that it results in simpler code
      (although perhaps not in absolutely every instance).

      If you have used StarLogo, StarLogoT, or pre-beta 9 versions of
      NetLogo, you may be accustomed to storing turtle id numbers in
      variables. In NetLogo, this is not the standard idiom anymore -- the
      standard idiom is to store the turtle itself. It is now quite rare in
      NetLogo to ever have to think about turtle id numbers, or use turtle
      id numbers in code.

      If you have a particular piece of code that you feel is unnecessarily
      awkward because of this, you might want to run it by us and we may be
      able to suggest a way to make it clearer (probably by eliminating the
      use of id numbers).

      Seth Tisue / seth@... / (847) 467-2814
      lead developer, NetLogo http://ccl.northwestern.edu/netlogo/
      Center for Connected Learning and Computer-Based Modeling
      School of Education and Social Policy / Department of Computer Science
      Northwestern University
    Your message has been successfully submitted and would be delivered to recipients shortly.