Float used instead of double when decoding DataType into DataField
DataType
are encoded binary values that are decoded into DataField
instances that may hold double values.
At several places (see for example RtcmDataField.DF082
, but there are other examples), one
uses FastMath.scalb
to create a double by scaling the binary value.
The pattern used is:
public double doubleValue(final EncodedMessage message) {
return FastMath.scalb(DataType.INT_8.decode(message).intValue(), -55);
}
However, this means the first argument to scalb
is an integer and not a double. In fact, we end up calling the float
version of scalb
rather than the double
version, and a second cast is performed after that to promote the returned float
into double
.
This should rather be replaced by
public double doubleValue(final EncodedMessage message) {
return FastMath.scalb((double) DataType.INT_8.decode(message), -55);
}
Edited by Luc Maisonobe