Giter Site home page Giter Site logo

usane's Introduction

Usane - unsigned integers for OCaml

%%VERSION%% The behaviour of numbers (int, int32, int64) in OCaml is to be signed, and wrap around on over/underflow. This library gives explicit access to the carry bit by using compiler builtins. Other fine integer libraries, such as integers library and stdint) mirror the OCaml standard library behaviour.

This library defines 8, 16, 32, and 64 bit unsigned integers which interoperates well with the builtin types (int32, int64) by reusing their representation. Arithmetic operations return the carry bit explicitly.

Some motivating examples are:

# succ max_int
- : int = -4611686018427387904

# pred min_int
- : int = 4611686018427387903

# abs min_int
- : int = -4611686018427387904

Usane comes with a extensive test suite to show the behaviour.

Currently this library is not released, I first want to a) use ocb-stubblr (to get it to run on MirageOS) and b) test on 32bit.

Documentation

Build Status

API Documentation is available online.

usane's People

Contributors

haesbaert avatar hannesm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

haesbaert yallop

usane's Issues

exception-free result wrappers

It would be very nice to have an interface along the lines of:

module Usane : sig
  module Usane32 : sig
    val of_int_e : 'error -> int -> (t, 'error) result
  end
end

Interoperability with the integers package

For easy interoperability it would be helpful to have the following type equalities in the interface:

module Usane :
sig
  module Uint8 : 
  sig
    type t = Unsigned.UInt8.t
    (* ... *)
  end

  module Uint16 : 
  sig
    type t = Unsigned.UInt16.t
    (* ... *)
  end

  module Uint32 : 
  sig
    type t = Unsigned.UInt32.t
    (* ... *)
  end

  module Uint64 : 
  sig
    type t = Unsigned.UInt64.t
    (* ... *)
  end
end

rather than the current situation:

module Usane :
sig
  module Uint8 : 
  sig
    type t = int
    (* ... *)
  end

  module Uint16 : 
  sig
    type t = int
    (* ... *)
  end

  module Uint32 : 
  sig
    type t = int32
    (* ... *)
  end

  module Uint64 : 
  sig
    type t = int64
    (* ... *)
  end
end

Besides interoperability, there'd be an added bonus: polymorphic comparison (Pervasives.compare, Pervasives.(<)) would work as expected on Uint32.t and Uint64.t. At present, large positive numbers of those types are represented as negative numbers, and so comparison behaves unexpectedly.

Previous discussion: yallop/ocaml-integers#2

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.