GithubHelp home page GithubHelp logo

zhangaz1 / sanctuary-int Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sanctuary-js/sanctuary-int

0.0 1.0 0.0 102 KB

:1234: A collection of functions which operate on 32-bit signed integers

License: MIT License

JavaScript 100.00%

sanctuary-int's Introduction

sanctuary-int

A collection of functions which operate on 32-bit signed integers.

API

The Int type represents integers in the range [-2^31 .. 2^31).

The NonZeroInt type represents non-zero integers in the range [-2^31 .. 2^31).

Returns the sum of its two arguments.

> add (1) (2)
3

Returns the result of subtracting its first argument from its second argument.

> sub (1) (100)
99

Returns the product of its two arguments.

> mul (6) (7)
42

Returns the result of dividing its second argument by its first argument, truncating towards zero.

Throws if the divisor is zero.

See also div.

> quot (5) (42)
8

> quot (-5) (42)
-8

> quot (5) (-42)
-8

> quot (-5) (-42)
8

Integer remainder, satisfying:

quot (y) (x) * y + rem (y) (x) === x

Throws if the divisor is zero.

See also mod.

> rem (5) (42)
2

> rem (-5) (42)
2

> rem (5) (-42)
-2

> rem (-5) (-42)
-2

Returns the result of dividing its second argument by its first argument, truncating towards negative infinity.

Throws if the divisor is zero.

See also quot.

> div (5) (42)
8

> div (-5) (42)
-9

> div (5) (-42)
-9

> div (-5) (-42)
8

Integer modulus, satisfying:

div (y) (x) * y + mod (y) (x) === x

Throws if the divisor is zero.

See also rem.

> mod (5) (42)
2

> mod (-5) (42)
-3

> mod (5) (-42)
3

> mod (-5) (-42)
-2

Bitwise AND. Returns an Int with a one at each bit position at which both arguments have a one.

> and (0b1100) (0b1010)
0b1000

Bitwise OR. Returns an Int with a one at each bit position at which at least one argument has a one.

> or (0b1100) (0b1010)
0b1110

Bitwise XOR. Returns an Int with a one at each bit position at which exactly one argument has a one.

> xor (0b1100) (0b1010)
0b0110

Bitwise NOT, satisfying:

not (x) === -(x + 1)
> not (42)
-43

Returns true if its argument is even; false if it is odd.

> even (42)
true

Returns true if its argument is odd; false if it is even.

> odd (42)
false

sanctuary-int's People

Contributors

davidchambers avatar svozza avatar

Watchers

 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.