Giter Site home page Giter Site logo

cantor's Introduction

Cantor is a high-performance floating point math library.

The idiomatic way to add together two 2-vectors in Clojure is

> (map + [1 2] [3 4])
(4 6)

Sadly, this is quite slow. Cantor defines operators which work efficiently across a variety of types. The above operation, in Cantor, is accomplished thus:

> (add (vec2 1 2) (vec2 3 4))
[ x=4.0 y=6.0 ]

This is roughly 10-20x faster than the idiomatic approach. These operators also work on normal numbers:

> (add 1 2)
3

The available operators include:

  • add
  • sub
  • mul
    • (mul (vec2 1 2) 2) => [ x=2.0 y=4.0 ]
    • (mul (vec3 1 2 3) (vec3 4 5 6)) => [ x=4.0 y=7.0 z=9.0 ]
  • div
    • (div (vec3 2 4 6) 2) => [ x=1.0 y=2.0 z=3.0 ]
    • (div (vec2 4 8) (vec2 1 2)) => [ x=4.0 y=4.0 ]
  • dot
    • (dot (vec2 1 0) (vec2 0 1)) => 0.0
  • polar
    • (polar (vec2 1 1)) => [ theta=45 r=1.414 ]
  • map*
    • (map* #(+ % 1) (vec3 1 2 3)) => [ x=2.0 y=3.0 z=4.0 ]
  • cartesian
    • (cartesian (polar2 45 1)) => [ x=0.707 y=0.707 ]
    • (cartesian 45) => [ x=0.707 y=0.707 ]

Complete documentation can be found here.

cantor's People

Contributors

kephale avatar ztellman avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.