on bb9ffcf help sign in
elk/libraries/Native/Basics.js
84 lines 2.1 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) { return (a/b)|0; }
12 function rem(a,b) { return a % b; }
13 var mod = Utils.mod;
14 function abs(x) { return x < 0 ? -x : x; }
15 function logBase(base,n) { return Math.log(n) / Math.log(base); }
16 function min(a,b) { return Utils.cmp(a,b) < 0 ? a : b; }
17 function max(a,b) { return Utils.cmp(a,b) > 0 ? a : b; }
18 function clamp(lo,hi,n) {
19 return Utils.cmp(n,lo) < 0 ? lo : Utils.cmp(n,hi) > 0 ? hi : n; }
20 function xor(a,b) { return a !== b; }
21 function not(b) { return !b; }
22 function isInfinite(n) { return n === Infinity || n === -Infinity }
24 function truncate(n) { return n|0; }
26 function degrees(d) {
27 return d * Math.PI / 180;
28 }
29 function turns(t) {
30 return 2 * Math.PI * t;
31 }
32 function fromPolar(point) {
33 var r = point._0;
34 var t = point._1;
35 return Utils.Tuple2(r * Math.cos(t), r * Math.sin(t));
36 }
37 function toPolar(point) {
38 var x = point._0;
39 var y = point._1;
40 return Utils.Tuple2(Math.sqrt(x * x + y * y), Math.atan2(y,x));
41 }
43 var basics = {
44 div:F2(div),
45 rem:F2(rem),
46 mod:mod,
48 pi:Math.PI,
49 e:Math.E,
50 cos:Math.cos,
51 sin:Math.sin,
52 tan:Math.tan,
53 acos:Math.acos,
54 asin:Math.asin,
55 atan:Math.atan,
56 atan2:F2(Math.atan2),
58 degrees: degrees,
59 turns: turns,
60 fromPolar: fromPolar,
61 toPolar: toPolar,
63 sqrt:Math.sqrt,
64 abs:abs,
65 logBase:F2(logBase),
66 min:F2(min),
67 max:F2(max),
68 clamp:F3(clamp),
69 compare:Utils.compare,
71 xor:F2(xor),
72 not:not,
74 truncate:truncate,
75 ceiling:Math.ceil,
76 floor:Math.floor,
77 round:Math.round,
78 toFloat:function(x) { return x; },
79 isNaN:isNaN,
80 isInfinite:isInfinite
81 };
83 return elm.Native.Basics.values = basics;
84};