Detalhes do pacote

@hridel/modulo

hridel26Apache-2.01.2.0

A robust modular arithmetic utility for JavaScript, handling both positive and negative integers with ease. Ensure consistent, non-negative results for your modulo operations. Perfect for mathematical computations, circular buffer implementations, and mor

modular, arithmetic, modulo, remainder

readme (leia-me)

modulo

A robust modular arithmetic utility for JavaScript, handling both positive and negative integers with ease. Ensure consistent, non-negative results for your modulo operations. Perfect for mathematical computations, circular buffer implementations, and more.

Installation

npm install @hridel/modulo

mod function example

import { mod } from '@hridel/modulo';

const exampleResult: number = mod(-1, 5);
console.log(`The result of -1 mod 5 is: ${exampleResult}`);  // The result of -1 mod 5 is: 4

rem function example

import { rem } from '@hridel/modulo';

// Example usage
const exampleResult: number = rem(-1, 5);
console.log(`The result of -1 rem 5 is: ${exampleResult}`);  // The result of -1 rem 5 is: -1

div function example

import { div } from '@hridel/modulo';

// Example usage
const exampleResult: number = div(-1, 5);
console.log(`The result of -1 div 5 is: ${exampleResult}`);  // The result of -1 div 5 is: -1

Why to use this library?

Because (-1 % 5) in JavaScript returns -1, which is not a valid result for a modulo operation.

This library ensures that the result of the mod function is always a non-negative integer.

The rem function returns the remainder of the division operation, which can be negative.

And the div function returns the quotient rounded towards negative infinity, similar to Haskell's div.

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

v1.2.0

28 October 2024

  • feat: Add div function for Euclidean division function similar to Haskell's div. a9815af
  • chore: Update CHANGELOG.md 9badeae

v1.1.0

27 October 2024

  • feat: Add remainder function similar to Haskell's rem. 74d7e65
  • chore: Add CHANGELOG.md 7282c95
  • chore: Change homepage url 64c740a

v1.0.2

27 October 2024

v1.0.1

25 October 2024