Common math functions, macros & utilities for Clojure/Clojurescript
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


About the project


A small library providing a Clojure/Clojurescript compatible collection of maths related protocols, general math functions, bit manipulation functions, as well as macros to produce inline expanded, nested expressions to create more legible source code for involved maths and to avoid extraneous reduce calls caused by the higher arity versions of Clojure’s built-in maths functions.

The macros are useful to simplify code for many geometry & matrix operations and are defined for both Clojure & ClojureScript.

The protocols defined here are used by a number of other projects, incl.,,

Note: This library relies on the new conditional reader syntax of recent Clojure & Clojurescript versions and therefore is not compatible with Clojure versions < 1.7.0

Leiningen coordinates


[ "0.2.2-SNAPSHOT"]



Project definition

Injected properties





[org.clojure/clojure "1.9.0"]


[org.clojure/clojurescript "1.10.238"]

[ "0.1.3"]



[criterium "0.4.3"]


[com.cemerick/clojurescript.test "0.3.3"]


[lein-cljsbuild "1.1.7"]

Building this project

This project is written in a literate programming format and requires Emacs & Org-mode to generate usable source code. Assuming both tools are installed, the easiest way to generate a working project is via command line (make sure emacs is on your path or else edit its path in

git clone
cd math
./ src/*.org test/*.org

Tangling is the process of extracting & combining source blocks from .org files into an actual working project/source tree. Once tangling is complete, you can cd into the generated project directory (babel) and then use lein as usual.


The project.clj file defines an alias to trigger a complete build & tests for both CLJ & CLJS versions.

cd babel
lein cleantest

To build the Clojurescript version simply run lein cljsbuild test from the same directory. A small HTML harness for the resulting JS file is also located in that folder (babel/index.html), allowing for further experimentation in the browser.

Working with the REPL

Editing code blocks or files in Org-mode, then re-loading & testing changes is quite trivial. Simply launch a REPL (via lein or Emacs) as usual. Everytime you’ve made changes to an .org file, re-tangle it from Emacs (C-c C-v t) or, then reload the namespace in the REPL via (require ' :reload) or similar.

Leiningen project file

(defproject "<<version>>"
  :description  "CLJ/CLJS math functions, macros & utilities"
  :url          "<<project-url>>"
  :license      {:name "Apache Software License 2.0"
                 :url ""
                 :distribution :repo}
  :scm          {:name "git"
                 :url ""}

  :min-lein-vesion "2.4.0"

  :dependencies [<<dep-clj>>

  :profiles     {:dev {:dependencies [<<dep-criterium>>]
                       :plugins      [<<dep-cljsbuild>>
                       :global-vars  {*warn-on-reflection* true}
                       :jvm-opts     ^:replace [""]
                       :aliases      {"cleantest" ["do" "clean," "test," "cljsbuild" "test"]}}}

  :cljsbuild    {:builds [{:id           "simple"
                           :source-paths ["src" "test"]
                           :compiler     {:output-to "<<cljs-artefact-path>>"
                                          :optimizations :whitespace
                                          :pretty-print true}}]
                 :test-commands {"unit-tests" ["phantomjs" :runner "<<cljs-artefact-path>>"]}}

  :pom-addition [:developers
                  [:name "Karsten Schmidt"]
                  [:url ""]
                  [:timezone "0"]]])

ClojureScript HTML harness

<!DOCTYPE html>
<html lang="en">
    <title><<lein-coords>> test</title>
    <script type="text/javascript" src="<<cljs-artefact-path>>"></script>

Accessing library version during runtime

The autogenerated namespace contains a single symbol version holding the version string defined above:

(use '[])

(prn version)
; "<<version>>"

Version namespace

Release history

VersionReleasedDescriptionLein coordinatesTagged Github URL
0.2.12016-03-19update typedarrays dependency[ "0.2.1"]0.2.1
0.2.02016-03-17add protocols, minor refactorings[ "0.2.0"]0.2.0
0.1.42015-06-17add interpolation fns, minor refactoring[ "0.1.4"]0.1.4
0.1.32015-06-08add interpolation fns[ "0.1.3"]0.1.3
0.1.22015-06-05update deps, add gamma fns[ "0.1.2"]0.1.2
0.1.12015-05-27add bit manipulations[ "0.1.1"]0.1.1
0.1.02015-05-25initial test release[ "0.1.0"]0.1.0


Karsten Schmidtinitiator & principal developer

I’ve got a fairly detailed roadmap and task list to implement over the coming months, but am always happy to receive feedback & suggestions and have issues filed. Once the core engine is more refined I’ll be gladly welcoming other contributions. Thanks for understanding!


This project is open source and licensed under the Apache Software License 2.0.