lauber00/elm-int64/1.2.2

NOTE: the latest version is 1.2.4

Renamed to volgariver6/elm-int64. That is where the repository lives now. It has not been published as a package under the new name.

Versions published as lauber00/elm-int64 still install under that name. 7 versions of 7 come from the new location (see their notes).

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/volgariver6/elm-int64.

What we checked: The repo moved to github.com/volgariver6/elm-int64. Rebuilt with git archive from commit 1dbe1f0355bc of https://github.com/volgariver6/elm-int64 (zip prefix lauber00-elm-int64-1d11ec4/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 d5d5a2321b9341580b0e5bed13e4924afd663dfe.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/lauber00/elm-int64/zipball/1.2.2/

elm-int64

An efficient 64-bit integer with correct overflow.

Bitwise operators in javascript can only use 32 bits. Sometimes, external protocols use 64-bit integers. This package implementes such integers with "correct" overflow behavior.

This is a low-level package focussed on speed. The 64-bit integers are represented as a 2-tuple of 32-bit numbers. There are helpers for conversion to string and elm/bytes Bytes.

import Int64 

Int64.add (Int64.fromInt 42) (Int64.fromInt 10)
    |> Int64.toUnsignedString
    --> "52"

Int64.subtract (Int64.fromInt 10) (Int64.fromInt 42)
    |> Int64.toSignedString
    --> "-32"

Int64.xor 
    (Int64.fromInt32s 0xDEADBEEF 0xBAAAAAAD) 
    (Int64.fromInt 42)
    |> Int64.toHex
    --> "deadbeefbaaaaa87"

Performance

Performance is roughly half for subtraction, addition and the bitwise operators. That is great considering int64 is really two 32-bit integers, so we're doing operations twice.

Reliabiltiy

This package is extensively tested with fuzz tests. Nonetheless, the logic is extremely tricky, so there might still be bugs.

Missing functionality

  1. Int64 -> Int

    This is unsafe, because Int cannot store all the information of a Int64. If you think the conversion is safe for you, use:

    Int64.fromInt 42
        |> Int64.toSignedString
        |> String.toInt
        --> Just 42
  2. String -> Int64

    And by extension converting 64-bit integers in e.g. JSON into Int64. This is tricky to implement, but PRs are welcome!

  3. Multiplication, integer division, modulo

    Would be nice to have, again PRs are welcome!