Grasshopper

algorithmic modeling for Rhino

I have a small function component with an If/Then/Else statement in it to defend from a divide by zero call.  Turns out that I'm getting a fault regardless.  If this were using lazy evaluation I don't believe I should get a fault.  Would it be possible to correct?

If(x≠0.0, (0.25/x), 1.0)

Attached is the (trivial) example file.

Thanks!

    - Brian -

Views: 1380

Replies to This Discussion

Hi Brian,

If() actually is a function, so the eval is not lazy.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

While not making this lazy, you could still avoid the error with this trick:

0.25/If(x≠0, x, 0.25)

- Giulio
________________
giulio@mcneel.com

Another option (less neat than Giulio's) would be:

If(x≠0.0, (0.25/Max(x, 1e-12)), 1.0)

where you can replace 1e-12 with whatever tolerance makes sense in the current case.

--

David Rutten

david@mcneel.com

Poprad, Slovakia


RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service