npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rat-vec

v1.1.1

Published

Exact rational vector arithmetic

Downloads

123,671

Readme

rat-vec

Exact rational vector arithmetic.

rat-vec is slow but reliable. You can use it to get quickly and reliably implement geometric algorithms, then go back and smash your head into a wall trying to optimize them with filters and predicates and snap rounding and so on.

This library is built on top of bn.js

Example

var vec = require('rat-vec')

var toFloat = require('rat-vec/to-float')

var add = require('rat-vec/add')

var sub = require('rat-vec/sub')

var dot = require('rat-vec/sub')

Install

npm i rat-vec

API

A rat-vec is an array of big-rats.

var r = require('rat-vec')(v)

Converts a vector of n floating point numbers into an exact rational vector of n+1 big ints.

  • v is a vector of floats, big-rats or strings

Returns A rational vector of big integers

require('rat-vec/is-vec')(v)

Test if v is a rat-vec

var v = require('rat-vec/to-float')(r)

Rounds a vector of big-rats into a

  • r is a vector of n big integers

Returns A vector of n floats representing the closest representable vector

var s = require('rat-vec/add')(a, b)

Returns The vector sum of a and b

var d = require('rat-vec/sub')(a, b)

Returns The vector difference of a and b

var f = require('rat-vec/dot')(a, b)

Returns The dot product of a and b

var v = require('rat-vec/muls')(a, s)

Returns The scalar product of a and s, where s is a float, big-rat or string

var v = require('rat-vec/divs')(a, s)

Returns a divided by the scalar s

var lerp = require('rat-vec/lerp')(a, b, t)

Linearly interpolate between a and b with parameter t

var c = require('rat-vec/cmp')(a, b)

Compares the components of a and b, returns an array of 0,+1,-1 whose components are the result of comparing each value.

var eq = require('rat-vec/equals')(a, b)

Test if two rational vectors are equal.

var h = require('rat-vec/max')(a, b)

Computes the component-wise maximum of a and b

var l = require('rat-vec/min')(a, b)

Computes the component-wise minimum of a and b

var p = require('rat-vec/mul')(a, b)

Computes the component-wise product of a and b

var r = require('rat-vec/recip')(a)

Computes the component-wise reciprocal of a

var q = require('rat-vec/div')(a, b)

Computes the component-wise quotient of a and b

var n = require('rat-vec/neg')(x)

Computes the additive inverse of x

var n = require('rat-vec/abs')(x)

Computes the component-wise absolute value of x

Credits

(c) 2015, MIT License

Rat logo CC licensed, (c) La Tarte Au Citron