Giter VIP home page Giter VIP logo

zarith_stubs_js's Introduction

Zarith Stubs JS

Zarith is an OCaml library that implements common operations over arbitrary-precision integers and rationals. It is implemented via a C api that primarily calls out to Gnu Multiple Precision Arithmetic Library. Because of that C API, Zarith could not be compiled via Js_of_ocaml until now.

Zarith Stubs JS is a reimplementation of the native C functions in JavaScript. It makes extensive use of peterolson/BigInteger.js as a shim for browser BigInt functionality and also for the implementations of many numerical algorithms.

How to use it ?

In order to use zarith with js_of_ocaml, just provide the javascript runtime files to the js_of_ocaml compiler and use zarith as you would normally do.

In practice,

  • if you use dune to build your project, just add zarith_stubs_js as a library dependency.
  • if you don't use dune, you need to find a way to pass both biginteger.js and runtime.js files to the js_of_ocaml compiler command line.

zarith_stubs_js's People

Contributors

aalekseyev avatar bclement-ocp avatar dkalinichenko-js avatar public-release avatar xclerc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zarith_stubs_js's Issues

zarith uses `caml_custom_ops` that is not in js_of_ocaml 3.4.0

The function caml_custom_ops is used here, and in the master branch of js_of_ocaml. It is not in an official release of jsoo.

Maybe, you can add a specific version of js_of_ocaml in the opam dependencies to avoid these problems in the future.

Thank you !

Missing primitive: `ml_z_extract_small`

ml_z_extract_small was added as a fast path for ml_z_extract in ZArith 1.13 (see ocaml/Zarith#90 )

It can be aliased to ml_z_extract:

// Provides: ml_z_extract_small
// Requires: ml_z_extract
function ml_z_extract_small(z1, pos, len) {
  return ml_z_extract(z1, pos, len);
}

Issue with Q.compare raising Stdlib error

Hi,
Thanks for this library, i'm trying to use it in the JS version of the SMT solver Alt-Ergo and i've found an error. I manage to make a minimal example of my problem:

let () =
  let y = Q.of_string "21749119135811171023142898368512/7209762788798054855747370097333" in
  print_int (Q.compare y y)

This lines issued the following error :

dune build; node _build/default/Main.bc.js
                     
<my_path>/_build/default/Main.bc.js:83
    function caml_raise_with_arg(tag,arg){throw [0,tag,arg]}
                                          ^
[
  0,
  [ 248, MlBytes { t: 9, c: 'Invalid_argument', l: 16 }, -3 ],
  MlBytes { t: 9, c: 'compare: abstract value', l: 23 }
]

The compare: abstract value error message seems to be issued by the compare function of the stdlib. But, in Zarith, Q use the comparison of Z which use an external ml_z_compare. Your runtime seems to provide this primitive using the bigInt comparison. I don't understand why i get an error message from the stdlib since your library provides every things that i need. Do i correctly use your library ?

test_zarith_stubs.zip

Release on OPAM?

Not to be rude, but is there a timeline for an updated OPAM release? The pre-v0.15 version has been sitting for several months.

The bugfix discussed here,
7c5a500
is important for our project. It's slightly clunky (but not impossible of course) to install it from source rather than OPAM.

Thanks!

Using Native JS BigInt

Just before the first release of zarith_stubs_js, I had written a stubs using the new BigInt built-in (only for my needs so not exhaustive). But of course some Safari users complained...
Since Safari has finally implemented BigInt (since october 2020), would you be inclined to review a PR switching to this native implementation ?

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.