Error - Division by zero when using a field of double type
book
Article ID: KB0074911
calendar_today
Updated On:
Description
I have protected my expression in an if() statement that confirms the divisor is not null or zero. Why does the expression occasionally report:
---
2012-08-29 13:44:56.987-0400 [draft:Thread- ThreadPool - 3] WARN com.streambase.sb.runtime.RuntimeEnv - Error at operator: default.<operator>, port: 0, tuple: {<...>}, exception: com.streambase.sb.runtime.exceptions.EvalException: Division by zero
---
The expression is:
if ( notnull(input1.divisor) and input1.divisor != 0 )
then input1.numerator / input1.divisor
else double(null)
Is this a problem with
notnull() or
!=0 ?
Resolution
If
input1.divisor is
-0.0 (negative zero as a double value), then
is "true", which permits the division to take place.
You can test this from the command-line with
sbd (for StreamBase 7) as so:
sbd -e "0.0 != 0"
(bool) false
sbd -e "-0.0 != 0"
(bool) true
sbd -e "abs(-0.0) != 0"
(bool) false
The absolute-value function,
abs(), will avoid this. The expression needs to be:
notnull(input1.divisor) and abs(input1.divisor) != 0
More discussion of what is going on in
http://en.wikipedia.org/wiki/Signed_zero:
"However, some programming languages may provide alternative comparison operators that do distinguish the two zeros. This is the case, for example, of the equals method in Java's Double class."
Issue/Introduction
The StreamBase Expression Language supports -0.0 (negative zero, double)
Feedback
thumb_up
Yes
thumb_down
No