Class NonFiniteDoubles

java.lang.Object
dev.frostlake.values.NonFiniteDoubles

public final class NonFiniteDoubles extends Object
NaN and the infinities as SQL sees them — how their words are spelled, and how they compare.

Live-verified. The words are matched CASE-INSENSITIVELY and a sign may lead them, with one measured asymmetry: in a DOCUMENT, +NaN is read and -NaN is not.

★ A CAST DOES NOT SHARE THAT ASYMMETRY. Live answers NaN for '-nan'::FLOAT, so the two readers are deliberately different — parse(java.lang.String) is the document's and parseForCast(java.lang.String) is the cast's — where a single reader would have to refuse a value one of the two accepts.

Their ORDER is not IEEE. Snowflake gives NaN a place in the total order rather than leaving it incomparable: it EQUALS ITSELF and sorts ABOVE every other value, so ORDER BY ends -Infinity, 1, Infinity, NaN. That is exactly what Double.compare(double, double) does, which is why comparison routes through it rather than through the == a primitive double would use.

  • Method Details

    • parse

      public static Double parse(String raw)
      The double a non-finite word stands for, or null where the text is not one.
    • parseForCast

      public static Double parseForCast(String raw)
      The same words as parse(java.lang.String), read the way a CAST reads them — where a NEGATIVE NaN is ACCEPTED.

      ★ THE SIGN RULE IS NOT ONE RULE. In a JSON DOCUMENT it is asymmetric and measured: +NaN parses and -NaN is refused. A CAST does not follow that — live answers NaN for '-nan'::FLOAT as readily as for '+nan' — so the two readers have to differ, and applying the document's rule to the cast refused a value live accepts.

      Parameters:
      raw - the text being cast
      Returns:
      the double it stands for, or null where the text is not a non-finite word
    • isNonFinite

      public static boolean isNonFinite(Number value)
      Whether this is a non-finite DOUBLE. A BigDecimal too large to fit a double does NOT count — it is an exact number that merely overflows on conversion, and it keeps its exact comparison.