Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

momenta

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

momenta

Basic vector operations

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

momenta

Basic vector operations over the rational numbers.

Support

browser support

Examples

where m.r is the rationals used by momenta

var m = require('momenta');
m([1])[0] === m.r(1); // true

while in the case of rationals it made sense to keep direct equality between the created objects, I think this is not the case with momentai. However this might change some time in the future.

Another issue is that no matter how much I wish, there isn't a good, widely supported way to subclass array (not until es6 is widely supported). The workarounds available kinda create more problems than they solve, so after a day of thinking I went in the minimalist direction. This also means, that while momenta methods expect arrays and scalars with add, sub, scale, disperse, dot methods on them, the module's user should provide these methods.

Probably worth to mention that the API gives you easy solution to this:

var m = require('momenta');
var equal = require('deep-equal');
var r = m.r;
equal(m.disperse(m([1,4,7,9,16]), r(12)), m([r(1,12),r(1,3),r(7,12),r(3,4),r(4,3)])); // true

API

all methods on momenta objects will return an array of rationals with the exception of .dot, which will return a single rational

Casting an array of integers to rationals
momenta()
m([3])[0].toString()  // 3/1
Casting an integer to a rational
momenta.r()
m.r(5).toString()  // 5/1
Scaling up
scale
m.scale(m([1,3,5]), m.r(7))  // [7/1,21/1,35/1]
Scaling down
disperse
m.disperse(m([1,3,5]), m.r(9)) // [1/9,1/3,5/9]
Addition
add
m.add(m([1,3,5]), m([2,4,6])) // [3/1,7/1,11/1]
Subtraction
sub
m.sub(m([3,7,11]), m([2,4,6])) // [1/1,3/1,5/1]
Dot product
dot
m.dot(m([1,3,5]), m([7,11,13])) // 105/1
Cross product
cross
m.cross(m([1,3,5]), m([7,11,13])) // [-16/1, 22/1, -10/1]

Install

npm install momenta

You can use it in the browser with browserify

Keywords

FAQs

Package last updated on 11 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc