Logo

dev-resources.site

for different kinds of informations.

Announcing elm-integer

Published at
12/4/2023
Categories
elm
math
Author
dwayne
Categories
2 categories in total
elm
open
math
open
Author
6 person written this
dwayne
open
Announcing elm-integer

I am happy to announce the release of elm-integer.

elm-integer is a pure Elm library for computing with the integers, β„€ = { ..., -2, -1, 0, 1, 2, ... }. It uses arbitrary-precision arithmetic so the magnitude of the numbers you can compute with is only limited by the available memory. It is extensively tested for correctness and has reasonable performance characteristics.

Try it out

I built an integer calculator that allows you to test out all the integer input formats, arithmetic operations, and integer output formats that's supported by elm-integer. Feel free to use the calculator to explore the limits of the library.

Compared to cmditch/elm-bigint

Commonly used small integers are named

The integers from -10 to 10 are already named. In particular, zero, one, two, ten, and negativeOne are available for immediate use.

Large integers are easy to create

fromSafeString is useful for establishing large constants in a calculation.

Multiple integer input formats are supported

Any base from 2 to 36 is supported using fromBaseBString and shortcuts are provided for binary, octal, decimal, and hexadecimal input formats.

Multiple integer output formats are supported

Any base from 2 to 36 is supported using toBaseBString and shortcuts are provided for binary, octal, decimal, and hexadecimal output formats.

There are useful predicates

With these predicates it's easy to check if your integer is zero (== 0), negative (< 0), non-negative (>= 0), positive (> 0), or non-positive (<= 0).

== and /= work as expected so if you wanted to know if your integer, z, is equal to -1 then z == negativeOne is all you have to do.

Arithmetic is performant

This library is built on elm-natural which currently outperforms cmditch/elm-bigint in multiplication, division with remainder, and exponentiation.

divModBy defines Euclidean division

cmditch/elm-bigint's divmod operation defines truncated division (or T-division) according to Daan Leijen's paper, Division and Modulus for Computer Scientists. It is the equivalent of quot/rem in Haskell. No equivalent of Euclidean division is provided.

N.B. You can check out this Ellie of divmod to confirm the above statements.

However, Boute argues that Euclidean division is superior to the other definitions of the div and mod functions in terms of regularity and useful mathematical properties.

Hence, divModBy in elm-integer defines Euclidean division and truncated division is provided by quotRemBy.

Feedback is appreciated

If you happen to use the library in an application, I would greatly appreciate your feedback.

Thank you for reading!

elm Article's
30 articles in total
Favicon
10 Months of Elm to Angular
Favicon
25 Must-Check Elm Resources for Developers: Tutorials, Tools, and Tips
Favicon
πŸƒ 30 Elm Picks to Fuel Your Functional Code
Favicon
Stateless and stateful components. No! Reusable views in Elm.
Favicon
On why I prefer not to use elm-css
Favicon
GitHub Actions, Devbox, and Elm
Favicon
Run Elm and lunarvim in a devcontainer
Favicon
How to host Browser.application projects
Favicon
How I host Elm web applications with GitHub Pages
Favicon
Announcing my newsletter "Elm with Dwayne"
Favicon
Using ChatGPT o1 to write UI code with Elm
Favicon
Exploring Svelte and Elm: A Comparative Look at Unique Frontend Technologies
Favicon
Exploring Frontend Technologies: Elm vs. Svelte
Favicon
Using a continuation-passing interpreter to make an interactive read operation for the browser with Elm
Favicon
How I use Devbox in my Elm projects
Favicon
Yet Another Tour of an Open-Source Elm SPA
Favicon
Elm 2023, a year in review
Favicon
For lack of a better name, I’m calling it β€œThe Module Pattern”.
Favicon
Exploring the Elm Architecture for Web Applications
Favicon
How to use Elm extensible records
Favicon
Elm with flex and color
Favicon
How I use Nix in my Elm projects
Favicon
Record Type Alias Combinators: A Public Service Announcement
Favicon
Parsing AWS AppSync Responses, Elm GraphQL Libraries, and Only Doing Front-End
Favicon
On continuation-passing style and the factorial function
Favicon
Announcing elm-integer
Favicon
Stricter TypeScript >, <, and ===
Favicon
Final Fantasy Legend Level Editor Update
Favicon
Rebuilding Final Fantasy Legend in Elm
Favicon
Building mobile apps using Elm and Capacitor

Featured ones: