This repository has been archived by the owner. It is now read-only.

# ztellman/cantor

not under active development - primitive math for clojure
Clojure
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
 Failed to load latest commit information. autodoc src test/cantor/test .gitignore README.textile project.clj

This library is not under active development. It was written to support Penumbra, which has also not been touched in a few years. Given the changes to Clojure’s primitive math in the intervening years, it’s probably not that useful anymore.

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:

• 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.