Giter VIP home page Giter VIP logo

elm-int64's Introduction

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!

elm-int64's People

Watchers

James Cloos avatar LiuBo avatar

elm-int64's Issues

Package broken after username change

I get this error when trying to install your package

-- CORRUPT PACKAGE DATA --------------------------------------------------------

I downloaded the source code for lauber00/elm-int64 1.2.4 from:

    https://github.com/lauber00/elm-int64/zipball/1.2.4/

But it looks like the hash of the archive has changed since publication:

  Expected: 2a7cf50b67c50ec25966eb79578e0572c5e64d3d
    Actual: acc104ef750821e0f181d7d644f8d6f4a4d0bf16

This usually means that the package author moved the version tag, so report it
to them and see if that is the issue. Folks on Elm slack can probably help as
well.

I believe the reason for this is that you changed your github username. Can you republish this package so it's accessible again?

Edit: Actually are there differences between this package and folkertdev/elm-int64? If not then I guess it doesn't make sense to republish this package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.