Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
When y2 = y1, obviously slope = INF. A backend build error arises as a result.
The following is a generic function which demonstrates the problem. Both of the last two lines of the function are required for the error to arise. Additionally, the numerator of 'm' is necessary; if m is instead
1.0 / ( y2 - y1 ), the error does not arise.
The device is a 1280n.
function A ( byval D as single ) as single
const C as single = 20.0
const x2 as single = 20.0, x1 as single = 10.0
const y2 as single = 1.0, y1 as single = 1.0
const m as single = ( x2 - x1 ) / ( y2 - y1 )
const b as single = y2 - (m*y1)
A = m * abs(D) + b
A = A * C
end function
This problem actually occurs in the front-end ZBasic compiler which is attempting to calculate the constant expression which evaluates to +INF. This is a problem that should be fixed. The compiler should probably issue warnings for constant expressions that evaluate to -/+INF and NAN.
My question is why do you have a constant expression that is +INF? Any special case calculations involving INF and NAN are probably not supported by ZBasic as they require a lot of special case logic for different expressions.
mikep wrote:The compiler should probably issue warnings for constant expressions that evaluate to -/+INF and NAN.
Quite so. I just finished adding that and modified the native mode code generator to emit a valid value (0.0) when a NaN, infinity or denormalized value is encountered. Of course, this doesn't make the code work but it does avoid the backend compiler errors.
The INF was an inadvertant result when accidentally setting both values to be identical. The error was not well defined, hence the post...
The error occurred not when just evaluating the constant expression, given that a few cases (such as 1.0 / (n-n) = 1.0 / 0.0 ) compiled.
Hence my assumption that this was a compiler bug, versus a front-end evaluation error.