MathSass
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.
; .content
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
$E
- Euler's constant (ネイピア数 [オイラー数])$PI
- π (円周率)$LN2
- The natural logarithm of 2 (2 の自然対数)$SQRT2
- The square root of 2 (2 の平方根)
Functions
Exponentiation
pow($base, $exp)
; // 16 ; // 0.0625 ; // 1.31951
Factorial
fact($x)
; // 24 ; // 40320
Square root
sqrt($x)
; // 1.41421 ; // 1.73205
Exponential function
exp($x)
frexp($x)
ldexp($x, $exp)
; // 0.36788 ; // 1 ; // 2.71828
Logarithms
log($x, $b: null)
; // 0.69315 ; // 2.30259 ; // 0.30103
Trigonometric functions
sin($x)
- Sine (正弦)cos($x)
- Cosine (余弦)tan($x)
- Tangent (正接)csc($x)
- Cosecant (余割)sec($x)
- Secant (正割)cot($x)
- Cotangent (余接)
If argument has deg
unit, converted to rad
.
; // 0.57735 ; // 0.57735
Inverse trigonometric functions
asin($x)
- Arcsine (逆正弦)acos($x)
- Arccosine (逆余弦)atan($x)
- Arctangent (逆正接)atan2($y, $x)
- Arctangent of the quotient of its arguments (引数の比率での逆正接)
; // 0 ; // 3.14159 ; // 0 ; // -3.14159
Greatest common divisor and least common multiple
gcd($a, $b)
- Greatest common divisor (最大公約数)lcm($a, $b)
- Least common multiple (最小公倍数)
; // 6 ; // 210
Helper functions
strip-unit($number)
deg-to-rad($deg, $unit: true)
rad-to-deg($rad, $unit: true)
unitless-rad($angle)
; // 60.00014deg ; // 1.0472rad ; // 1.0472 ; // 1.0472 ; // 1.0472
References
- adambom/Sass-Math · GitHub
- Team-Sass/Sassy-math · GitHub
- Math - JavaScript | MDN
- 404 Blog Not Found:javascript - Mathを再発明してみた
- C言語による最新アルゴリズム事典
…and Wikipedia articles:
- Exponentiation, 冪乗 (累乗)
- Factorial, 階乗
- Square root, 平方根
- Exponential function, 指数関数
- Logarithm, 対数
- Trigonometric functions, 三角関数
- Inverse trigonometric functions, 逆三角関数
- Greatest common divisor, 最大公約数
- Least common multiple, 最小公倍数
- Degree (angle), 度 (角度)
- Radian, ラジアン
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.