RealFloat -package:scientific

Efficient, machine-independent access to the components of a floating-point number.
Floating point formatting for Bytestring.Builder This module primarily exposes floatDec and doubleDec which do the equivalent of converting through string7 . show. It also exposes formatFloat and formatDouble with a similar API as formatRealFloat. NB: The float-to-string conversions exposed by this module match show's output (specifically with respect to default rounding and length). In particular, there are boundary cases where the closest and 'shortest' string representations are not used. Mentions of 'shortest' in the docs below are with this caveat. For example, for fidelity, we match show on the output below.
>>> show (1.0e23 :: Float)
"1.0e23"

>>> show (1.0e23 :: Double)
"9.999999999999999e22"

>>> floatDec 1.0e23
"1.0e23"

>>> doubleDec 1.0e23
"9.999999999999999e22"
Simplifying, we can build a shorter, lossless representation by just using "1.0e23" since the floating point values that are 1 ULP away are
>>> showHex (castDoubleToWord64 1.0e23) []
"44b52d02c7e14af6"

>>> castWord64ToDouble 0x44b52d02c7e14af5
9.999999999999997e22

>>> castWord64ToDouble 0x44b52d02c7e14af6
9.999999999999999e22

>>> castWord64ToDouble 0x44b52d02c7e14af7
1.0000000000000001e23
In particular, we could use the exact boundary if it is the shortest representation and the original floating number is even. To experiment with the shorter rounding, refer to acceptBounds. This will give us
>>> floatDec 1.0e23
"1.0e23"

>>> doubleDec 1.0e23
"1.0e23"
For more details, please refer to the Ryu paper.
Write a floating point value to a Builder.
Hugs (September 2006) has buggy definitions for isNaN and isInfinite on Float and Double. If this module is run through CPP with the macro HUGS set to a value no larger than 200609, then correct definitions are used. Otherwise the Prelude definitions are used (which should be correct for other compilers). For example, run Hugs with
hugs -F'cpp -P -DHUGS=200609' Hugs/RealFloat.hs
N.B. The corrected definitions have only been tested to work for Float and Double. These definitions should probably not be used for other RealFloat types. This installation was compiled with the normal Prelude version. This should be correct.
Faster String representations for floating point types. The code is largely taken from code in GHC.Float and the Show instance of Integer in GHC.Num to get the sequence of digits.
Show a signed RealFloat value to full precision, using standard decimal notation for arguments whose absolute value lies between 0.1 and 9,999,999, and scientific notation otherwise.
Generates a random floating-point number in the [inclusive,exclusive) range. This generator works the same as integral, but for floating point numbers.
Format a floating-point number.
>>> F.formatQuery ("SELECT * FROM series WHERE value > "%F.realFloat) 0.1
"SELECT * FROM series WHERE value > 0.1"
Deep embedded version of RealFloat. Efficient, machine-independent access to the components of a floating-point number. A complete definition has to define all functions.
A random variable sampling from the standard normal distribution over any RealFloat type (subject to the rest of the constraints - it builds and uses a Ziggurat internally, which requires the Erf class). Because it computes a Ziggurat, it is very expensive to use for just one evaluation, or even for multiple evaluations if not used and reused monomorphically (to enable the ziggurat table to be let-floated out). If you don't know whether your use case fits this description then you're probably better off using a different algorithm, such as boxMullerNormalPair or knuthPolarNormalPair. And of course if you don't need the full generality of this definition then you're much better off using doubleStdNormal or floatStdNormal. As far as I know, this should be safe to use in any monomorphic Distribution Normal instance declaration.
Compute a uniform random value in the range [0,1) for any RealFloat type
realFloatUniform a b computes a uniform random value in the range [a,b) for any RealFloat type
Helper function for converting RealFloat types to JavaScript strings
Formatter for RealFloat values.
Encode a signed RealFloat according to FPFormat and optionally requested precision. This corresponds to the show{E,F,G}Float operations provided by base's Numeric module. NOTE: The functions in base-4.12 changed the serialisation in case of a Just 0 precision; this version of text still provides the serialisation as implemented in base-4.11. The next major version of text will switch to the more correct base-4.12 serialisation.
Converts a RealFloat value to a Builder, specifying if a decimal point should always be shown. Since: 2
Like formatRealFloatAltB, except that the decimal is only shown for arguments whose absolute value is between 0.1 and 9,999,999. Since: 2