Home

Awesome

MathSass NPM version Build Status Dependency Status devDependency Status

A Sass implementation of mathematical functions.

Install

Git

git clone git@github.com:terkel/mathsass.git && cd mathsass

Bower

bower install mathsass --save-dev

npm

npm install mathsass --save-dev

Usage

Import dist/_math.scss partial to the Sass document.

@import "path/to/dist/math";

.content {
    height: 200px;
    width: 200px / tan(60deg); // 115.47005px
}

If you installed via Npm the path will be: node_modules/mathsass/dist/math

If you installed via Bower the path will be: bower_components/mathsass/dist/math

Features

Constants

Functions

Exponentiation

@debug pow(4, 2);   // 16
@debug pow(4, -2);  // 0.0625
@debug pow(4, 0.2); // 1.31951

Factorial

@debug fact(4); // 24
@debug fact(8); // 40320

Square root

@debug sqrt(2); // 1.41421
@debug sqrt(3); // 1.73205

Exponential function

@debug exp(-1); // 0.36788
@debug exp(0);  // 1
@debug exp(1);  // 2.71828

Logarithms

@debug log(2);     // 0.69315
@debug log(10);    // 2.30259
@debug log(2, 10); // 0.30103

Trigonometric functions

If argument has deg unit, converted to rad.

@debug tan(0.5236); // 0.57735
@debug tan(30deg);  // 0.57735

Inverse trigonometric functions

@debug atan2(0, 0);       // 0
@debug atan2(0, -0.0);    // 3.14159
@debug atan2(-0.0, 0);    // 0
@debug atan2(-0.0, -0.0); // -3.14159

Greatest common divisor and least common multiple

@debug gcd(54, 24); // 6
@debug lcm(30, 42); // 210

Helper functions

@debug rad-to-deg(1.0472);       // 60.00014deg
@debug deg-to-rad(60deg);        // 1.0472rad
@debug deg-to-rad(60deg, false); // 1.0472
@debug unitless-rad(60deg);      // 1.0472
@debug unitless-rad(1.0472rad);  // 1.0472

References

…and Wikipedia articles:

Contributing

Make sure you have node.js and grunt installed.

Clone Repository

git clone git@github.com:terkel/mathsass.git

Install Dependencies

npm install

Run Sass/Tests

grunt

Credits

Originally created with help from @kaminaly and @pilssalgi.

License

Copyright (c) 2013 Takeru Suzuki Licensed under the MIT license.