Apama Documentation : Developing Apama Applications : EPL Reference : Types : Primitive and string types : float
float
A signed floating point number. Either a decimal point (.) or an exponent symbol (e) must be present within the number for it to be a valid float.
When perfect accuracy is a requirement, use the decimal type in place of the float type. When extremely small floating point variations are acceptable, you might choose to use the float type to obtain better performance.
Values
Values of the float type are a finite-precision approximation of the mathematical real numbers, encoded as 64-bit binary floating-point values consisting of sign, significand, and exponent, as defined by the IEEE Standard for Binary Floating-Point Arithmetic, ANSI/IEEE Standard 754 -1985 (IEEE, New York). Values of the float type have a precision of approximately 16 decimal digits. (The binary significand is 52 bits wide.)
The largest positive floating point value that can be stored in a variable of type float is 1.7976931348623157 * 10308 and the smallest nonzero positive value that can be stored is 2.2250738585072014 * 10-308.
In addition to the usual positive and negative numbers, the IEEE standard also defines positive and negative zeros, positive and negative infinities, and Not-a-Number values. For information about how the correlator handles these values, see Support for IEEE 754 special values.
Because float values are of finite precision and binary encoded, they cannot accurately represent all values. In particular, when a floating point literal expressed in decimal notation is converted to its binary floating-point representation, there can be a slight loss of accuracy. This occurs because most decimal fractions cannot be represented precisely in binary. So the fraction 0.1 or 1/10 in base 10 becomes the infinitely repeating fraction 0.0001100110011001100110011... when it is converted to base 2. Similarly, conversions from floating point values to integral or string types will sometimes be inexact. The following program illustrates the effects of finite precision and conversions between base 10 and base 2:
monitor foo
{
   action onload()
   {
      float f;
      f := 0.1;
      print f.formatFixed(18);
   }
}
This program produces the output 0.100000000000000006. Note the small error in the least significant digit.
There are a number of float constants provided in EPL. See Support for IEEE 754 special values.
Operators
The following table lists the EPL operators available for use with floating point values, that is decimal or float types.
Operator
Description
Result Type
<
Less-than comparison
boolean
<=
Less-than or equal comparison
boolean
=
Equal comparison
boolean
!=
Not equal comparison
boolean
>=
Greater-than or equal comparison
boolean
>
Greater-than comparison
boolean
+
Unary floating point identity
decimal or float
Unary floating point additive inverse
decimal or float
+
Floating point addition
decimal or float
Floating point subtraction
decimal or float
*
Floating point multiplication
decimal or float
/
Floating point division
decimal or float
Overflows and underflows are ignored by the EPL runtime.
The correlator compares floating point values as follows:
*Finite float and decimal types compare in the obvious way.
*-Inf is equal to -Inf and is less than any finite number or +Inf.
*+Inf is equal to +Inf and is greater than any finite number or -Inf.
*NaN is not equal to anything, including another NaN.
*If you try to use NaN for keying or sorting the correlator terminates the monitor instance.
Methods
The following inbuilt methods may be called on variables of decimal or float type. Unless noted otherwise, if you call a method on a decimal type the return value is a decimal, and if you call the method on a float type, the return value is a float. In all method descriptions, x represents the value that the method is called on.
*abs() — returns |x|, the absolute value of x.
*acos() — returns the inverse cosine of x in radians. Special case: x.acos() = NaN, if |x| > 1.
*acosh() — returns the inverse hyperbolic cosine of x. Special case: x.acosh() = NaN, if x < 1.
*asin() — returns the inverse sine of x in radians. Special cases:
*(NaN).asin() = NaN
*x.asin() = NaN, if |x| > 1
*asinh() — returns the inverse hyperbolic sine of x.
*atan() — returns the inverse tangent of x.
*atan2(y) — returns the two-parameter inverse tangent of x and y. Special cases:
*(anything).atan2(NaN) = NaN
*(NaN).atan2(anything) = NaN
*(±0).atan2(anything except NaN) = ±0
*(±0).atan2(-anything except NaN) = ±pi
*(anything except 0 and NaN).atan2(0) = ±pi/2
*(anything except ±Infinity and NaN).atan2(+Infinity) = ±0
*(anything except ±Infinity and NaN).atan2(-Infinity) = ±pi
*(±Infinity).atan2(+Infinity) = ±pi/4
*(±Infinity).atan2(-Infinity ) = ±3pi/4
*(±Infinity).atan2(anything except 0, NaN and ±Infinity) = ±pi/2
*atanh() — returns the inverse hyperbolic tangent of x. Special cases:
*x.atanh() = NaN, if |x| > 1
*(NaN).atanh() = NaN
*(±1).atanh() = ±Infinity
*bitEquals(decimal) or bitEquals(float) — returns true if the value it is called on and the value passed as an argument to the method are the same. The value the method is called on and the argument to the method must both be decimal types or must both be float types. The method performs a bitwise comparison. This is useful because bitEquals() returns true for NaN.bitEquals(NaN) for NaNs that are bitwise identical whereas NaN = NaN is always false even if the NaNs have identical representations.
*canParse(string) — returns true if the string argument can be successfully parsed.
*cbrt() — returns the cube root of x.
*ceil() — returns the smallest possible integer that is greater than or equal to the value the method is called on. Special cases:
*(+Infinity).ceil() = integer.MAX
*(-Infinity).ceil() = integer.MIN
*(NaN).ceil() causes a runtime error; the correlator terminates the monitor
*cos() — returns the cosine of x. See also the note at the end of this list.
*cosh() — returns the hyperbolic cosine of x. Special case: (±Infinity or NaN).cosh() = |x|
*erf() — returns the error function of x. The formula is as follows:
*exp() — returns e to the power x or ex, where x is the value of the decimal or float and where e is approximately 2.71828183. Special cases:
*exp(NaN) = NaN
*exp(+Infinity) = +Infinity
*exp(-Infinity) = 0
*exponent() — When called on a float value, this method returns the integer that is the exponent where x = mantissa*2exponent assuming 0.5 <= |mantissa| < 1.0. When called on a decimal value, this method returns the exponent where x = mantissa*10exponent assuming 0.1 <= |mantissa| < 1.0. Special cases:
*(0.0).exponent() = 0
*(±Infinity or NaN).exponent() terminates the monitor instance that contains the method call.
*floor() — returns the largest possible integer that is less than or equal to the value the method is called on. Special cases:
*(+Infinity).floor() = integer.MAX
*(-Infinity).floor() = integer.MIN
*(NaN).floor() causes a runtime error; the correlator terminates the monitor.
*fmod(y) — returns x mod y in exact arithmetic.
*formatFixed(integer) — returns a string representation of the value the method is called on where the value is rounded to the number of decimal places specified in the argument. This method can operate on the IEEE special values.
*formatScientific(integer) — returns a string representation of the value the method is called on where the value is truncated to the number of significant figures specified in the argument and formatted in Scientific Notation. This method can operate on the IEEE special values.
*fractionalPart() — returns the fractional component of x.
*gammal() — returns the logarithm of the gamma function.
*ilogb() — returns an integer that is the binary exponent of non-zero x. Special case: throws exception for ilogb(NaN).
*integralPart() — returns an integer that is the integral part of a floating point value. Similar to floor(), which rounds down, and ceil(), which rounds up. integralPart() rounds towards zero. Special case: throws exception for integralPart(NaN).
*isFinite() — returns true if and only if the value it is called on is not ±Infinity or NaN.
*isInfinite() — returns true if and only if the value it is called on is ±Infinity.
*isNaN() — returns true if and only if the value it is called on is NaN.
*ln() — returns the natural log of the value the method is called on. Special cases:
*(0).ln() = -Infinity
*(-anything).ln() = NaN
*log10() — returns the log to base 10 of the value the method is called on. Special cases:
*(0).log10() = -Infinity
*(-anything).log10() = NaN
*mantissa() — When called on a float value, this method returns a mantissa where x = mantissa*2exponent assuming that 0.5 <= |mantissa| < 1.0. When called on a decimal value, this method returns a mantissa where x = mantissa*10exponent assuming that 0.1 <= |mantissa| < 1.0. Special cases:
*(0.0).mantissa() = 0.0
*(Infinity or NaN).mantissa() terminates the monitor instance that contains the method call
*max(decimal, decimal) or max(float, float) — returns the value of the larger operand. You can call this method on the decimal or float type or on an instance of a decimal or float type.
*min(decimal, decimal) or min(float, float)— returns the value of the smaller operand. You can call this method on the decimal or float type or on an instance of a decimal or float type.
*nextafter(y) — returns the next distinct floating-point number after x that is representable in the underlying type in the direction toward y.
*parse(string) – method that returns the decimal or float instance represented by the string argument. You can call this method on the decimal or float type or on an instance of a decimal or float type. The more typical use is to call parse() directly on a decimal or float type.
The parse() method takes a single string as its argument. This string must be the string form of an event object. The string must adhere to the format described in Event file format. For example:
float a;
a := float.parse("123.456");
You can specify the parse() method after an expression or type name. If the correlator is unable to parse the string, it is a runtime error and the monitor instance that the EPL is running in terminates.
A call to decimal.parse() can include or exclude the appended d. In other words, decimal.parse("1.0") and decimal.parse("1.0d") both work.
The parse() method can operate on the string form of the IEEE special values.
*pow(decimal) or pow(float) — returns x to the power y (where y is the argument) or xy. See also Special cases of pow().
*rand() — returns a random value from 0.0 up to (but not including) the value the method was invoked on. If the value was negative, then the random value will be from the value (but not including it) up to 0.0. When you are calling the rand() method on a variable, the method behaves correctly if the variable value is zero, for example, (0.0).rand() returns 0.0.
Special case: (±Infinity or NaN).rand() causes a runtime error; the correlator terminates the monitor.
Caution:  
This random number generator is not verified to be cryptographically strong. Therefore, it should not be used for purposes where a strong random number is required.
*round() – rounds to the nearest integer. Uses banker's rounding, which means the round-to-even method, to break ties. For example, it rounds both 3.5 and 4.5 to 4. Special cases:
*(+Infinity).round() = integer.MAX
*(-Infinity).round() = integer.MIN
*(NaN).round() causes a runtime error; the correlator terminates the monitor.
*scalbn(n) — When called on a float value, this method returns x*2n, where n is of integer type. When called on a decimal value, this method returns x*10n, where n is of integer type.
*sin() — returns the sine of x. See also the note at the end of this list.
*sinh() — returns the hyperbolic sine of x. Special case: (±Infinity or NaN).sinh() = |x|
*sqrt() — returns the positive square root of the value it is called on. Special cases:
*(-anything).sqrt() = NaN
*(+Infinity).sqrt() = +Infinity
*tan() — returns the tangent of x. See also the note at the end of this list.
*tanh() — returns the hyperbolic tangent of x. Special case: NaN.tanh() = NaN
*toDecimal() — returns a decimal representation of the float. This method can operate on the IEEE special values.
*toFloat() — returns a float representation of the decimal. This method can operate on the IEEE special values.
*toString() — returns a string representation of the float or decimal it is called on. This method can operate on the IEEE special values. A call to decimal.toString() does not include a d suffix.
Note:  
Let trig be any of sin, cos, or tan. The argument to these functions is in units of Radian. Also (±Infinity or NaN).trig() = NaN.
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback