forked from adambom/Sass-Math
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.scss
77 lines (57 loc) · 1.16 KB
/
math.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@function power ($x, $n) {
$ret: 1;
@if $n >= 0 {
@for $i from 1 through $n {
$ret: $ret * $x;
}
} @else {
@for $i from $n to 0 {
$ret: $ret / $x;
}
}
@return $ret;
}
@function factorial ($x) {
$ret: 1;
@if $x > 0 {
@while $x > 0 {
$ret: $ret * $x;
$x: $x - 1;
}
}
@return $ret;
}
@function sin ($x) {
$ret: 0;
@for $n from 0 to 25 {
$ret: $ret + power(-1, $n) * power($x, 2 * $n + 1) / factorial(2 * $n + 1);
}
@return $ret;
}
@function cos ($x) {
$ret: 0;
@for $n from 0 to 25 {
$ret: $ret + power(-1, $n) * power($x, 2 * $n) / factorial(2 * $n);
}
@return $ret;
}
@function exp ($x) {
$ret: 0;
@for $n from 0 to 25 {
$ret: $ret + power($x, $n) / factorial($n);
}
@return $ret;
}
@function ln($x) {
$ret: 0;
$n: 1;
$dx: .001;
@while $n <= $x {
$ret: $ret + $dx / $n;
$n: $n + $dx;
}
@return $ret;
}
@function sqrt($x) {
@return exp(0.5 * ln($x));
}