Skip to content

terkel/mathsass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 

Repository files navigation

MathSass

A Sass implementation of mathematical functions.

Usage

Import _math.scss partial to the Sass document.

@import "path/to/math";

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

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)
@debug pow(4, 2);   // 16
@debug pow(4, -2);  // 0.0625
@debug pow(4, 0.2); // 1.31951

Factorial

  • fact($x)
@debug fact(4); // 24
@debug fact(8); // 40320

Square root

  • sqrt($x)
@debug sqrt(2); // 1.41421
@debug sqrt(3); // 1.73205

Exponential function

  • exp($x)
  • frexp($x)
  • ldexp($x, $exp)
@debug exp(-1); // 0.36788
@debug exp(0);  // 1
@debug exp(1);  // 2.71828

Logarithms

  • log($x)

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.

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

Inverse trigonometric functions

  • asin($x) - Arcsine (逆正弦)
  • acos($x) - Arccosine (逆余弦)
  • atan($x) - Arctangent (逆正接)
  • atan2($y, $x) - Arctangent of the quotient of its arguments (引数の比率での逆正接)
@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

Helper functions

  • strip-unit($number)
  • deg-to-rad($deg, $unit: true)
  • rad-to-deg($rad, $unit: true)
  • unitless-rad($angle)
@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:

Credits

Special thanks to @kaminaly and @pilssalgi!

License

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

About

A Sass implementation of mathematical functions.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors