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
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')
npm i rat-vec
A rat-vec
is an array of big-rat
s.
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-rat
s or strings
Returns A rational vector of big integers
Test if v
is a rat-vec
Rounds a vector of big-rats into a
r
is a vector ofn
big integers
Returns A vector of n
floats representing the closest representable vector
Returns The vector sum of a
and b
Returns The vector difference of a
and b
Returns The dot product of a
and b
Returns The scalar product of a
and s
, where s
is a float, big-rat or string
Returns a
divided by the scalar s
Linearly interpolate between a
and b
with parameter t
Compares the components of a
and b
, returns an array of 0,+1,-1
whose components are the result of comparing each value.
Test if two rational vectors are equal.
Computes the component-wise maximum of a
and b
Computes the component-wise minimum of a
and b
Computes the component-wise product of a
and b
Computes the component-wise reciprocal of a
Computes the component-wise quotient of a
and b
Computes the additive inverse of x
Computes the component-wise absolute value of x
(c) 2015, MIT License