on ce614bb help sign in
elk/libraries/Native/Basics.js
103 lines 2.2 kB history raw
2Elm.Native.Basics = {};
3Elm.Native.Basics.make = function(elm) {
4 elm.Native = elm.Native || {};
5 elm.Native.Basics = elm.Native.Basics || {};
6 if (elm.Native.Basics.values) return elm.Native.Basics.values;
8 var JS = Elm.Native.JavaScript.make(elm);
9 var Utils = Elm.Native.Utils.make(elm);
11 function div(a, b) {
12 return (a/b)|0;
13 }
14 function rem(a, b) {
15 return a % b;
16 }
17 var mod = Utils.mod;
18 function logBase(base, n) {
19 return Math.log(n) / Math.log(base);
20 }
22 function min(a, b) {
23 return Utils.cmp(a,b) < 0 ? a : b;
24 }
25 function max(a, b) {
26 return Utils.cmp(a,b) > 0 ? a : b;
27 }
28 function clamp(lo, hi, n) {
29 return Utils.cmp(n,lo) < 0 ? lo : Utils.cmp(n,hi) > 0 ? hi : n;
30 }
32 function xor(a, b) {
33 return a !== b;
34 }
35 function not(b) {
36 return !b;
37 }
38 function isInfinite(n) {
39 return n === Infinity || n === -Infinity
40 }
42 function truncate(n) {
43 return n|0;
44 }
46 function degrees(d) {
47 return d * Math.PI / 180;
48 }
49 function turns(t) {
50 return 2 * Math.PI * t;
51 }
52 function fromPolar(point) {
53 var r = point._0;
54 var t = point._1;
55 return Utils.Tuple2(r * Math.cos(t), r * Math.sin(t));
56 }
57 function toPolar(point) {
58 var x = point._0;
59 var y = point._1;
60 return Utils.Tuple2(Math.sqrt(x * x + y * y), Math.atan2(y,x));
61 }
63 var basics = {
64 div: F2(div),
65 rem: F2(rem),
66 mod: mod,
68 pi: Math.PI,
69 e: Math.E,
70 cos: Math.cos,
71 sin: Math.sin,
72 tan: Math.tan,
73 acos: Math.acos,
74 asin: Math.asin,
75 atan: Math.atan,
76 atan2: F2(Math.atan2),
78 degrees: degrees,
79 turns: turns,
80 fromPolar: fromPolar,
81 toPolar: toPolar,
83 sqrt: Math.sqrt,
84 logBase: F2(logBase),
85 min: F2(min),
86 max: F2(max),
87 clamp: F3(clamp),
88 compare: Utils.compare,
90 xor: F2(xor),
91 not: not,
93 truncate: truncate,
94 ceiling: Math.ceil,
95 floor: Math.floor,
96 round: Math.round,
97 toFloat: function(x) { return x; },
98 isNaN: isNaN,
99 isInfinite: isInfinite
100 };
102 return elm.Native.Basics.values = basics;
103};