kudzu-forest/elm-wide-float/2.0.2

WideFloat

This module provides the definitions and functionalities of WideFloat type.

Types

Opaque type that represents floating point number with 42 exponent bits and 52 significand bits.

type alias Content =
{ base2toThe1024exponent : Int
, significand : Float
}

Record type that represents inner content of WideFloat.

Constants

WideFloat representing 0.

zero == fromFloat 0 --> True

WideFloat representing 1.

one == fromFloat 1 --> True

Creation

create : Content -> WideFloat

Creates a WideFloat value from specified exponent and significand. The value create { base2toThe1024exponent = a, significand = b} corresponds to b * 2^(1024a).

create
    { base2toThe1024exponent = 0
    , significand = 2 ^ 513
    }
    == create
        { base2toThe1024exponent = 1
        , significand = 2 ^ -511
        } -->True
fromFloat : Float -> WideFloat

Creates a WideFloat value from specified float

fromFloat 1
    == one --> True

Checks

isZero : WideFloat -> Bool

Returns True if the parameter is recognized as zero in floating point precision.

fromFloat 1
    |> add
        ( create
            { base2toThe1024exponent = 100
            , significand = 1
            }
        )
    |> differenceFrom
        ( create
            { base2toThe1024exponent = 100
            , significand = 1
            }
        )
    |> isZero --> True




fromFloat 1
    |> add
        ( create
            { base2toThe1024exponent = 0
            , significand = 2^50
            }
        )
    |> differenceFrom
        ( create
            { base2toThe1024exponent = 0
            , significand = 2^50
            }
        )
    |> isZero --> False

Returns True if the second parameter is larger than first one. Reads naturally when used with pipe operator(|>).

w1 : WideFloat
w1 =
    create
        { base2toThe1024exponent = 1000
        , significand = 1
        }


w2 : WideFloat
w2 =
    create
        { base2toThe1024exponent = 999
        , significand = 1.999
        }


w1 |> isLargerThan w2 --> True


w2 |> isLargerThan w1 --> False

Returns True if the second parameter is smaller than first one. Reads naturally when used with pipe operator(|>).

w1 : WideFloat
w1 =
    create
        { base2toThe1024exponent = 1000
        , significand = 1
        }


w2 : WideFloat
w2 =
    create
        { base2toThe1024exponent = 999
        , significand = 1.999
        }


w1 |> isSmallerThan w2 --> False


w2 |> isSmallerThan w1 --> True

Returns True if the value of first parameter is the same as the second parameter.

w1 : WideFloat
w1 =
    create
        { base2toThe1024exponent = 1000
        , significand = 1
        }


w2 : WideFloat
w2 =
    create
        { base2toThe1024exponent = 50
        , significand = 1
        }
        |> add
            (create
                { base2toThe1024exponent = 0
                , significand = 1
                }
            )


w1 |> isEqualTo w1 --> True


w1 |> isEqualTo w2 --> False

Calcuration

adds two WideFloats.

w1 : WideFloat
w1 =
    create
        { base2toThe1024exponent = 100
        , significand = 2^(-511)
        }


w2 : WideFloat
w2 =
    create
        { base2toThe1024exponent = 99
        , significand = 2^511
        }


add w1 w2 --> create { base2toThe1024exponent = 100, significand = 1.25 * 2^(-511) }

Subtracts WideFloat value given as the first parameter from the second. Reads naturally when used with pipe(|>).

w1 : WideFloat
w1 =
    create
        { base2toThe1024exponent = 1
        , significand = 2^(-511)
        }


w2 : WideFloat
w2 =
    create
        { base2toThe1024exponent = 0
        , significand = 2^511
        }


w1 |> differenceFrom w2 --> create { base2toThe1024exponent = 1, significand = 1.5 * 2^(-512) }

Multiplies two WideFloats.

w1 : WideFloat
w1 =
    create
        { base2toThe1024exponent = 100
        , significand = 1.5
        }


w2 : WideFloat
w2 =
    create
        { base2toThe1024exponent = 200
        , significand = 1.75
        }


multiply w1 w2 --> create { base2toThe1024exponent = 300, significand = 2.625 }

multiplies a Float value on a WideFloat value.

w : WideFloat
w =
    create
        { base2toThe1024exponent = 0
        , significand = 2^(500)
        }


multiplyFloat (2^20) w --> create { base2toThe1024exponent = 1, significand = 256 * 2 ^(-512) }

Returns ratio between to WideFloats. Reads naturally when used with pipe(|>).

w1 : WideFloat
w1 =
    create
        { base2toThe1024exponent = 100
        , significand = 1
        }


w2 : WideFloat
w2 =
    create
        { base2toThe1024exponent = 99
        , significand = 1.6
        }


w1 |> dividedBy w2
    |> differenceFrom ( create { base2toThe1024exponent = 0, significand = 1.25})
    |> isSmallerThan ( create { base2toThe1024exponent = -30, significand = 1})--> True

Output

Returns proportion of the first parameter in the sum of first and second parameters.

w1 : WideFloat
w1 =
    create
        { base2toThe1024exponent = 100
        , significand = 2 ^ (-511)
        }


w2 : WideFloat
w2 =
    create
        { base2toThe1024exponent = 99
        , significand = 2^511
        }


p : Float
p =
    proportionOf w1 w2




p <= 0.8001 --> True


p >= 0.7999 --> True
getInternal : WideFloat -> Content

Returns a record representing the inner content of WideFloat. Inverse function of create (when significand is specified properly).

content : Content
content =
    { base2toThe1024exponent = 1000
    , significand = 1.234
    }




getInternal (create content)
   == content --> True
toString : Int -> WideFloat -> String

Returns a String value representing the base 10 expression of a WideFloat. You can specify how many digits is shown after decimal point as the first parameter. The result may be a little less precise than other calcurations implemented in this module.

create
    { base2toThe1024exponent = 1
    , significand = 1
    }
    |> toString 3 --> "1.798e308"

If you want some other formats, you can make your original toString function using getInternal.