Feature suggestion: Add static equals methods to Float and Double
martin.desruisseaux at geomatys.com
Wed Jan 9 09:00:36 UTC 2019
Le 08/01/2019 à 19:55, Hans Boehm a écrit :
> The IEEE standard does say that for quiet NaNs, the value (or one of them)
> "should" be preserved by most operations on the quiet NaN. I have not heard
> of implementations violating this for anything other than the "quiet" bit.
> Thus I don't immediately see why it would be problematic to encode an
> explicitly programmer-introduced error cause in the remaining bits (as
> opposed to relying on hardware-generated patterns). I have not seen
> non-testing code that does so, but I would be mildly surprised if it
> doesn't exist somewhere.
I confirm that such code exist and are used in production for 15 years
at least in the GeoTools and Apache Spatial Information System (SIS)
projects. Earth Observation data are often images mixing measurement
values with different kind of missing values. So above-cited projects
perform computation on float primitive types where, for example:
* Real values are Sea Surface Temperatures values in °C.
* One NaN bit pattern stands for values missing because the sea was
hidden by a cloud.
* Another NaN bit pattern stands for values missing because the pixel
is over a land.
* Another NaN bit pattern stands for values missing because the remote
sensor did not fly over that area.
Actually those data are typically encoded as integers in some file
format where each missing value is associated to a different color
(clouds in white, lands in brown, etc.). But they are converted to float
values for performing calculations (e.g. applying the "gradient
magnitude" operator provided by Java Advanced Imaging library), then
converted back to integers for displaying purpose with
java.awt.image.RenderedImage. It allows the use of mathematical formulas
without special checks for missing values, and still preserve the lands,
clouds, etc. masks in the resulting image. I have never seen yet a lost
of information encoded in quiet NaN values (e.g. I have not seen a "NaN
for land" mutated to a "NaN for cloud"), except if an arithmetic
operation is applied on two different NaN bit patterns.
More information about the core-libs-dev