Giter Club home page Giter Club logo

mod-floor-ceiling's Introduction

mod-floor-ceiling

Build Status Coverage Status semantic-release Commitizen friendly

computes floor and ceiling for any modulus, not just 1

node
> require('mod-floor-ceiling').modFloor(3.8, 1.7)
3.4
> require('mod-floor-ceiling').modFloor(3.4, 1.7)
3.4
> require('mod-floor-ceiling').modCeiling(-17.8, 2.5)
-17.5
> require('mod-floor-ceiling').modLower(15, 5)
10
> require('mod-floor-ceiling').modLower(16, 5)
15
> require('mod-floor-ceiling').modHigher(15, 5)
20
> require('mod-floor-ceiling').modHigher(14, 5)
15

Usage

npm install mod-floor-ceiling

modFloor(value: number, modulus: number, anchor?: number = 0): number

Returns the greatest (closest to positive infinity) multiple of modulus, plus anchor, that is <= value.

modCeiling(value: number, modulus: number, anchor?: number = 0): number

Returns the least (closest to negative infinity) multiple of modulus, plus anchor, that is >= value.

modLower(value: number, modulus: number, anchor?: number = 0): number

Returns the greatest (closest to positive infinity) multiple of modulus, plus anchor, that is < value.

modHigher(value: number, modulus: number, anchor?: number = 0): number

Returns the greatest (closest to positive infinity) multiple of modulus, plus anchor, that is > value.

What is anchor?

Anchor controls the offset of multiples of modulus.

For example, with a modulus of 3 and the default anchor of 0, possible return values include -6, -3, 0, 3, 6, etc.

But with anchor of 1, possible return values include -5, -2, 1, 4, 7, etc.

It's simple; modFloor(value, modulus, anchor) just computes anchor + modFloor(value - anchor, modulus).

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.