01-05-2025, 01:33 PM
Sort of.
ZX Basic uses the ROM FP-Calc. Unfortunately, (-3)^2 (or any other negative integer) gives Invalid Argument.
Indeed, you should get this error when returning to BASIC.
This is a limitation of the ROM FP-Calc which uses Logarithms to compute the power of a number. Hence powers of negative numbers cannot be computed. However, you can do x * x in this case.
I'm looking for an alternative to this, but for floats it's not easy: x^y for x < 0 (negative numbers) is tricky if y is float. For example (-3)^0.5 is the same as SQR(-3) which is imaginary (and will return also Invalid Argument).
Maybe there is an algorithm using the ROM FP to compute this?
ZX Basic uses the ROM FP-Calc. Unfortunately, (-3)^2 (or any other negative integer) gives Invalid Argument.
Indeed, you should get this error when returning to BASIC.
This is a limitation of the ROM FP-Calc which uses Logarithms to compute the power of a number. Hence powers of negative numbers cannot be computed. However, you can do x * x in this case.
I'm looking for an alternative to this, but for floats it's not easy: x^y for x < 0 (negative numbers) is tricky if y is float. For example (-3)^0.5 is the same as SQR(-3) which is imaginary (and will return also Invalid Argument).
Maybe there is an algorithm using the ROM FP to compute this?
---
Boriel
Boriel