Jump to content

Negative Zero


Recommended Posts

I'm ran into an issue where:

  1. I have a default resampled Line.
  2. Calculated Normals using PolyFrame set to First Edge.
    @N:  { 0,-1, 0 }
  3. Reversed the Normals using Facet.
    @N: {-0, 1,-0 }
  4. Scattered points, inheriting Normals.
    @N: { 0, 1, 0 }
  5. Finally used a wrangle to check if Normals == {0,1,0}

The results were a bit random. Sometime it is true, sometimes it is false.

I did find a couple of solutions to work around this for what I was doing, but I believe something in this simple sequence of nodes is not doing its job properly. I just wanted to hear your thoughts about this before (or even if I needed to) send this as a bug.


negative_zero.hiplc - H16.0.600 Indie

Link to comment
Share on other sites

If you test like this it seems its the -1 it fails on:

int test1 = @N.x == 0;
int test2 = @N.y == -1;
int test3 = @N.z == 0;

    i@check = 1;

Might be a rounding issue somewhere, because if you then change it to int test2 = @N.y >= -1; it works fine. Also if you normalize N in your example it works.

Link to comment
Share on other sites

It's not a negative zero, it's a very small value (-0.0000000596046) shown as a negative zero by Spreadsheet. To understand problem, compute:

@N = {0, -1, 0} - @N;


Borrow any good one "almost equal" function example from the web. Here is one of simpler versions:

// Simplified port of CPython's math.isclose() function.
int isclose(float a, b, rtol, atol)
    if (a == b)
        return true;

    float d = abs(b - a);
    return ((d<=abs(rtol*b))||
            (d<=abs(rtol*a))) ||
           (d <= atol);


It will make your comparisons more robust: almost_equal_example.hipnc

Edited by f1480187
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...