Code Monkey home page Code Monkey logo

bitintegers.jl's Introduction

BitIntegers

Build Status

This package implements fixed-width integer types similar to standard builtin-ones like Int or UInt128. The following types, with obvious meaning, are exported: Int256, UInt256, Int512, UInt512, Int1024, UInt1024; they come with string macros to construct them (like for Int128 and UInt128), e.g. int256"123". It's possible to instantiate a new pair of types with the non-exported @define_integers macro:

julia> BitIntegers.@define_integers 24

julia> UInt24(1), Int24(2)
(0x000001, 2)

julia> BitIntegers.@define_integers 8 MyInt8 MyUInt8

julia> MyUInt8(1)
0x01

julia> myint8"123" # the string macro is named like the type, in lower case
123

Enough functions have been implemented to make those numbers a bit useful, but many more are missing. Issues and PRs are welcome :)

I expected to implement this using tuples, but it turned out that using primitive type was a huge win: many basic functions were already available for free via the use of intrinsics! (which tap into already implemented features in LLVM). The caveat is that I have no idea whether how it is used here is legal: for example, it seems possible to call Primes.factor(rand(Int256)) without a problem, but Primes.factor(rand(UInt256)) will make LLVM abort the program, in a way that I'm unable to debug so far.

There are another couple of outstanding issues:

  1. the intrinsics for division operations make LLVM fail (at least for widths greater than 128 bits), so they are here implemented via conversion to BigInt first, which makes them quite slow (but a patch to Julia is on the way to accelerate that). What is quite surprising is that the intrinsics seem to work when not wrapped in another function! So if speed is paramount and you don't need checked operations, you can use Base.sdiv_int instead of div for example;

  2. for some reason, importing this code invalidates many precompiled functions from Base, so the REPL experience becomes very annoyingly slow until functions get recompiled. Hopefully this will be a solvable problem.

bitintegers.jl's People

Contributors

nhdaly avatar rfourquet avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.