Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    fract() of negative - unexpected

    Bug Reporting (FUZE 4 Nintendo Switch)
    3
    7
    285
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • spikey
      spikey F last edited by

      https://fuzearena.com/help/view/fract
      It seems that

      fract(-1.1) = 0.9
      

      I expected:

      fract(-1.1) = 0.1
      

      Is that a bug?

      pianofire 1 Reply Last reply Reply Quote 0
      • pianofire
        pianofire Fuze Team @spikey last edited by pianofire

        @spikey I would have thought so too but apparently the fractional part of a negative number is not straight forward.

        According to wikipedia the fractional part of -1.3 can be 0.7, 0.3 or -0.3 !

        See https://en.wikipedia.org/wiki/Fractional_part

        1 Reply Last reply Reply Quote 0
        • spikey
          spikey F last edited by

          Ah. I See, I just found out that my program was failing because of fract(-0.0) = 1

          test program output:

          z=0.400000 fract(z)= 0.4000000
          z=0.300000 fract(z)= 0.3000000
          z=0.200000 fract(z)= 0.2000000
          z=0.100000 fract(z)= 0.1000000
          z=-0.000000 fract(z)=1.000000
          z=-0.100000 fract(z)=0.900000
          z=-0.200000 fract(z)=0.800000
          z=-0.300000 fract(z)=0.700000
          z=-0.400000 fract(z)=0.600000
          z=-0.500000 fract(z)=0.500000
          fract(-0.000000)=0.000000
          

          example code:

          z = 0.5
          for i = 0 to 10 loop
             z = z - 0.1
             fz = fract(z)
             print("z=", z, " fract(z)= ", fz, "\n")
             update()
          repeat
          test = fract(-0.000000)
          print("fract(-0.000000)=",test)
          update()
          loop
          repeat
          

          But something is wrong here, because if I run print(fract(-0.000000)) I get 0.000000 and during the for loop I get 1.000000.
          Is it to early in the morning? I don't see the why.

          pianofire 1 Reply Last reply Reply Quote 0
          • pianofire
            pianofire Fuze Team @spikey last edited by

            @spikey that is strange I will have a look

            pianofire 1 Reply Last reply Reply Quote 0
            • pianofire
              pianofire Fuze Team @pianofire last edited by pianofire

              @spikey There are a couple of strange things here. Why does it think that 0 is negative (I am pretty sure that it shouldn't be) and why does it behave differently inside and outside of the loop?

              I will raise an issue. In the meantime fract(abs(x)) seems to behave as you want

              1 Reply Last reply Reply Quote 2
              • spikey
                spikey F last edited by

                Oh, thats perfect. Thanx.

                1 Reply Last reply Reply Quote 0
                • Mincus
                  Mincus F last edited by

                  I'm guessing the -0.0 and +0.0 are an artefact of the floating point format (it has both a + and - 0.0 due to how it works) and Fuze is taking your "-0.00" literal and converting it to the +0.0 instead whilst the 0.1 - 0.1 is giving -0.0 because of precision limitations in the floating point format.
                  fract() is then handling -0.0 and +0.0 differently, which may be a bug?

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post