Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MOD doesn't work with type FIXED (*solved*)
#1
I did wonder if this was a bug or not, since it might be odd to modulus a floating point number.

But mod works perfectly with type FLOAT, so logically it should also work well with type FIXED. Fixed division works, and the compiler seems to know where the code for mod should be - at label _MODF16.

Error: Undefined label '__MODF16'
Reply
#2
britlion Wrote:I did wonder if this was a bug or not, since it might be odd to modulus a floating point number.

But mod works perfectly with type FLOAT, so logically it should also work well with type FIXED. Fixed division works, and the compiler seems to know where the code for mod should be - at label _MODF16.

Error: Undefined label '__MODF16'
Yes, this is a bug. As you might already guessed, Fixed type MOD is not implemented (I didn't exhaustively tested it, because I use fixed type only on +, - , *, / operations). Ok, will try to fix this week.
Reply
#3
Ok, the bug has been fixed. Keep in mind that "MOD" is supposed to be used only with positive integer (Ubyte, UInteger, ULong) types. Anyway, the MODF16 is implemented, and it should work as expected, but due to the lack of precision, the following issues might happen:
  1. Lost of precision: 5 mod 3 = 2, but for fixed values it renders to 1.99999 aprox
  2. For negative numbers, the sign is propagated to the modulo.

The A mod B function is implemented as: fract(A / B) * B
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)