@agoric/xsnap 0.14.3-dev-b047af2.0 → 0.14.3-dev-3eb4230.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/api.js +1 -1
  2. package/package.json +16 -23
  3. package/src/build.js +4 -61
  4. package/moddable/modules/data/base64/base64.js +0 -28
  5. package/moddable/modules/data/base64/manifest.json +0 -11
  6. package/moddable/modules/data/base64/modBase64.c +0 -188
  7. package/moddable/modules/data/binaryMessage/BinaryMessage.js +0 -106
  8. package/moddable/modules/data/crc/crc.c +0 -205
  9. package/moddable/modules/data/crc/crc.js +0 -36
  10. package/moddable/modules/data/crc/manifest.json +0 -8
  11. package/moddable/modules/data/hex/hex.js +0 -28
  12. package/moddable/modules/data/hex/manifest.json +0 -11
  13. package/moddable/modules/data/hex/modHex.c +0 -139
  14. package/moddable/modules/data/logical/logical.js +0 -32
  15. package/moddable/modules/data/logical/modLogical.c +0 -98
  16. package/moddable/modules/data/qrcode/manifest.json +0 -9
  17. package/moddable/modules/data/qrcode/qrcode.c +0 -93
  18. package/moddable/modules/data/qrcode/qrcode.js +0 -23
  19. package/moddable/modules/data/qrcode/qrcodegen.c +0 -1025
  20. package/moddable/modules/data/qrcode/qrcodegen.h +0 -267
  21. package/moddable/modules/data/text/decoder/manifest.json +0 -8
  22. package/moddable/modules/data/text/decoder/textdecoder.c +0 -480
  23. package/moddable/modules/data/text/decoder/textdecoder.js +0 -27
  24. package/moddable/modules/data/text/encoder/manifest.json +0 -8
  25. package/moddable/modules/data/text/encoder/textencoder.c +0 -232
  26. package/moddable/modules/data/text/encoder/textencoder.js +0 -24
  27. package/moddable/modules/data/tinyint/tinyint.c +0 -150
  28. package/moddable/modules/data/tinyint/tinyint.js +0 -53
  29. package/moddable/modules/data/url/manifest.json +0 -17
  30. package/moddable/modules/data/url/url.c +0 -1959
  31. package/moddable/modules/data/url/url.js +0 -210
  32. package/moddable/modules/data/wavreader/manifest.json +0 -8
  33. package/moddable/modules/data/wavreader/wavreader.js +0 -128
  34. package/moddable/modules/data/zlib/deflate.c +0 -161
  35. package/moddable/modules/data/zlib/deflate.js +0 -63
  36. package/moddable/modules/data/zlib/inflate.c +0 -145
  37. package/moddable/modules/data/zlib/inflate.js +0 -66
  38. package/moddable/modules/data/zlib/manifest_deflate.json +0 -9
  39. package/moddable/modules/data/zlib/manifest_inflate.json +0 -9
  40. package/moddable/modules/data/zlib/miniz.c +0 -4924
  41. package/moddable/xs/includes/xs.d.ts +0 -73
  42. package/moddable/xs/includes/xs.h +0 -1533
  43. package/moddable/xs/includes/xsmc.h +0 -206
  44. package/moddable/xs/makefiles/lin/makefile +0 -33
  45. package/moddable/xs/makefiles/lin/xsc.mk +0 -118
  46. package/moddable/xs/makefiles/lin/xsid.mk +0 -90
  47. package/moddable/xs/makefiles/lin/xsl.mk +0 -168
  48. package/moddable/xs/makefiles/lin/xst.mk +0 -201
  49. package/moddable/xs/makefiles/mac/makefile +0 -33
  50. package/moddable/xs/makefiles/mac/xsc.mk +0 -130
  51. package/moddable/xs/makefiles/mac/xsid.mk +0 -102
  52. package/moddable/xs/makefiles/mac/xsl.mk +0 -177
  53. package/moddable/xs/makefiles/mac/xst.mk +0 -203
  54. package/moddable/xs/makefiles/mac/xst_no_asan.txt +0 -52
  55. package/moddable/xs/makefiles/win/build.bat +0 -26
  56. package/moddable/xs/makefiles/win/xsc.mak +0 -142
  57. package/moddable/xs/makefiles/win/xsid.mak +0 -113
  58. package/moddable/xs/makefiles/win/xsl.mak +0 -186
  59. package/moddable/xs/makefiles/win/xst.mak +0 -195
  60. package/moddable/xs/platforms/lin_xs.h +0 -99
  61. package/moddable/xs/platforms/mac_xs.h +0 -97
  62. package/moddable/xs/platforms/wasm_xs.h +0 -79
  63. package/moddable/xs/platforms/win_xs.h +0 -104
  64. package/moddable/xs/platforms/xsHost.h +0 -63
  65. package/moddable/xs/platforms/xsPlatform.h +0 -618
  66. package/moddable/xs/sources/xsAPI.c +0 -2555
  67. package/moddable/xs/sources/xsAll.c +0 -294
  68. package/moddable/xs/sources/xsAll.h +0 -2741
  69. package/moddable/xs/sources/xsArguments.c +0 -222
  70. package/moddable/xs/sources/xsArray.c +0 -2657
  71. package/moddable/xs/sources/xsAtomics.c +0 -844
  72. package/moddable/xs/sources/xsBigInt.c +0 -1859
  73. package/moddable/xs/sources/xsBoolean.c +0 -109
  74. package/moddable/xs/sources/xsCode.c +0 -4493
  75. package/moddable/xs/sources/xsCommon.c +0 -1710
  76. package/moddable/xs/sources/xsCommon.h +0 -1142
  77. package/moddable/xs/sources/xsDataView.c +0 -2890
  78. package/moddable/xs/sources/xsDate.c +0 -1541
  79. package/moddable/xs/sources/xsDebug.c +0 -2710
  80. package/moddable/xs/sources/xsDefaults.c +0 -134
  81. package/moddable/xs/sources/xsError.c +0 -353
  82. package/moddable/xs/sources/xsFunction.c +0 -776
  83. package/moddable/xs/sources/xsGenerator.c +0 -865
  84. package/moddable/xs/sources/xsGlobal.c +0 -839
  85. package/moddable/xs/sources/xsJSON.c +0 -1091
  86. package/moddable/xs/sources/xsLexical.c +0 -1969
  87. package/moddable/xs/sources/xsLockdown.c +0 -933
  88. package/moddable/xs/sources/xsMapSet.c +0 -1649
  89. package/moddable/xs/sources/xsMarshall.c +0 -1020
  90. package/moddable/xs/sources/xsMath.c +0 -624
  91. package/moddable/xs/sources/xsMemory.c +0 -1941
  92. package/moddable/xs/sources/xsModule.c +0 -3101
  93. package/moddable/xs/sources/xsNumber.c +0 -560
  94. package/moddable/xs/sources/xsObject.c +0 -1102
  95. package/moddable/xs/sources/xsPlatforms.c +0 -480
  96. package/moddable/xs/sources/xsProfile.c +0 -577
  97. package/moddable/xs/sources/xsPromise.c +0 -1199
  98. package/moddable/xs/sources/xsProperty.c +0 -636
  99. package/moddable/xs/sources/xsProxy.c +0 -1014
  100. package/moddable/xs/sources/xsRegExp.c +0 -1168
  101. package/moddable/xs/sources/xsRun.c +0 -4889
  102. package/moddable/xs/sources/xsScope.c +0 -1293
  103. package/moddable/xs/sources/xsScript.c +0 -288
  104. package/moddable/xs/sources/xsScript.h +0 -1186
  105. package/moddable/xs/sources/xsSnapshot.c +0 -2161
  106. package/moddable/xs/sources/xsSnapshot.h +0 -51
  107. package/moddable/xs/sources/xsSourceMap.c +0 -218
  108. package/moddable/xs/sources/xsString.c +0 -3332
  109. package/moddable/xs/sources/xsSymbol.c +0 -503
  110. package/moddable/xs/sources/xsSyntaxical.c +0 -4193
  111. package/moddable/xs/sources/xsTree.c +0 -1893
  112. package/moddable/xs/sources/xsType.c +0 -1488
  113. package/moddable/xs/sources/xsdtoa.c +0 -6672
  114. package/moddable/xs/sources/xsmc.c +0 -340
  115. package/moddable/xs/sources/xsre.c +0 -7578
  116. package/xsnap-native/xsnap/makefiles/lin/makefile +0 -10
  117. package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +0 -153
  118. package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +0 -144
  119. package/xsnap-native/xsnap/makefiles/mac/makefile +0 -10
  120. package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +0 -162
  121. package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +0 -153
  122. package/xsnap-native/xsnap/sources/xsnap-worker.c +0 -996
  123. package/xsnap-native/xsnap/sources/xsnap.c +0 -716
  124. package/xsnap-native/xsnap/sources/xsnap.h +0 -142
  125. package/xsnap-native/xsnap/sources/xsnapPlatform.c +0 -1496
  126. package/xsnap-native/xsnap/sources/xsnapPlatform.h +0 -105
@@ -1,624 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-2017 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Runtime.
5
- *
6
- * The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Lesser General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public License
17
- * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- * This file incorporates work covered by the following copyright and
20
- * permission notice:
21
- *
22
- * Copyright (C) 2010-2016 Marvell International Ltd.
23
- * Copyright (C) 2002-2010 Kinoma, Inc.
24
- *
25
- * Licensed under the Apache License, Version 2.0 (the "License");
26
- * you may not use this file except in compliance with the License.
27
- * You may obtain a copy of the License at
28
- *
29
- * http://www.apache.org/licenses/LICENSE-2.0
30
- *
31
- * Unless required by applicable law or agreed to in writing, software
32
- * distributed under the License is distributed on an "AS IS" BASIS,
33
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34
- * See the License for the specific language governing permissions and
35
- * limitations under the License.
36
- */
37
-
38
- #include "xsAll.h"
39
-
40
- void fxBuildMath(txMachine* the)
41
- {
42
- txSlot* slot;
43
- mxPush(mxObjectPrototype);
44
- slot = fxLastProperty(the, fxNewObjectInstance(the));
45
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_abs), 1, mxID(_abs), XS_DONT_ENUM_FLAG);
46
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_acos), 1, mxID(_acos), XS_DONT_ENUM_FLAG);
47
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_acosh), 1, mxID(_acosh), XS_DONT_ENUM_FLAG);
48
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_asin), 1, mxID(_asin), XS_DONT_ENUM_FLAG);
49
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_asinh), 1, mxID(_asinh), XS_DONT_ENUM_FLAG);
50
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_atan), 1, mxID(_atan), XS_DONT_ENUM_FLAG);
51
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_atanh), 1, mxID(_atanh), XS_DONT_ENUM_FLAG);
52
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_atan2), 2, mxID(_atan2), XS_DONT_ENUM_FLAG);
53
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_cbrt), 1, mxID(_cbrt), XS_DONT_ENUM_FLAG);
54
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_ceil), 1, mxID(_ceil), XS_DONT_ENUM_FLAG);
55
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_clz32), 1, mxID(_clz32), XS_DONT_ENUM_FLAG);
56
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_cos), 1, mxID(_cos), XS_DONT_ENUM_FLAG);
57
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_cosh), 1, mxID(_cosh), XS_DONT_ENUM_FLAG);
58
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_exp), 1, mxID(_exp), XS_DONT_ENUM_FLAG);
59
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_expm1), 1, mxID(_expm1), XS_DONT_ENUM_FLAG);
60
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_floor), 1, mxID(_floor), XS_DONT_ENUM_FLAG);
61
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_fround), 1, mxID(_fround), XS_DONT_ENUM_FLAG);
62
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_hypot), 2, mxID(_hypot_), XS_DONT_ENUM_FLAG);
63
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_idiv), 2, mxID(_idiv), XS_DONT_ENUM_FLAG);
64
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_idivmod), 2, mxID(_idivmod), XS_DONT_ENUM_FLAG);
65
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_imod), 2, mxID(_imod), XS_DONT_ENUM_FLAG);
66
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_imul), 2, mxID(_imul), XS_DONT_ENUM_FLAG);
67
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_imuldiv), 2, mxID(_imuldiv), XS_DONT_ENUM_FLAG);
68
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_irem), 2, mxID(_irem), XS_DONT_ENUM_FLAG);
69
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_log), 1, mxID(_log), XS_DONT_ENUM_FLAG);
70
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_log1p), 1, mxID(_log1p), XS_DONT_ENUM_FLAG);
71
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_log10), 1, mxID(_log10), XS_DONT_ENUM_FLAG);
72
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_log2), 1, mxID(_log2), XS_DONT_ENUM_FLAG);
73
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_max), 2, mxID(_max), XS_DONT_ENUM_FLAG);
74
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_min), 2, mxID(_min), XS_DONT_ENUM_FLAG);
75
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_mod), 2, mxID(_mod), XS_DONT_ENUM_FLAG);
76
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_pow), 2, mxID(_pow), XS_DONT_ENUM_FLAG);
77
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_random), 0, mxID(_random), XS_DONT_ENUM_FLAG);
78
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_round), 1, mxID(_round), XS_DONT_ENUM_FLAG);
79
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_sign), 1, mxID(_sign), XS_DONT_ENUM_FLAG);
80
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_sin), 1, mxID(_sin), XS_DONT_ENUM_FLAG);
81
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_sinh), 1, mxID(_sinh), XS_DONT_ENUM_FLAG);
82
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_sqrt), 1, mxID(_sqrt), XS_DONT_ENUM_FLAG);
83
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_tan), 1, mxID(_tan), XS_DONT_ENUM_FLAG);
84
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_tanh), 1, mxID(_tanh), XS_DONT_ENUM_FLAG);
85
- slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Math_trunc), 1, mxID(_trunc), XS_DONT_ENUM_FLAG);
86
- slot = fxNextNumberProperty(the, slot, C_M_E, mxID(_E), XS_GET_ONLY);
87
- slot = fxNextNumberProperty(the, slot, C_M_LN10, mxID(_LN10), XS_GET_ONLY);
88
- slot = fxNextNumberProperty(the, slot, C_M_LN2, mxID(_LN2), XS_GET_ONLY);
89
- slot = fxNextNumberProperty(the, slot, C_M_LOG10E, mxID(_LOG10E), XS_GET_ONLY);
90
- slot = fxNextNumberProperty(the, slot, C_M_LOG2E, mxID(_LOG2E), XS_GET_ONLY);
91
- slot = fxNextNumberProperty(the, slot, C_M_PI, mxID(_PI), XS_GET_ONLY);
92
- slot = fxNextNumberProperty(the, slot, C_M_SQRT1_2, mxID(_SQRT1_2), XS_GET_ONLY);
93
- slot = fxNextNumberProperty(the, slot, C_M_SQRT2, mxID(_SQRT2), XS_GET_ONLY);
94
- slot = fxNextStringXProperty(the, slot, "Math", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
95
- mxPull(mxMathObject);
96
- //@@ c_srand((unsigned)c_time(0));
97
- }
98
-
99
- #define mxNanResultIfNoArg \
100
- if (mxArgc < 1) { \
101
- mxResult->kind = XS_NUMBER_KIND; \
102
- mxResult->value.number = C_NAN; \
103
- return; \
104
- }
105
-
106
- #define mxNanResultIfNoArg2 \
107
- if (mxArgc < 2) { \
108
- mxResult->kind = XS_NUMBER_KIND; \
109
- mxResult->value.number = C_NAN; \
110
- return; \
111
- }
112
-
113
- void fx_Math_abs(txMachine* the)
114
- {
115
- mxNanResultIfNoArg;
116
- fxToNumber(the, mxArgv(0));
117
- mxResult->kind = XS_NUMBER_KIND;
118
- mxResult->value.number = c_fabs(mxArgv(0)->value.number);
119
- }
120
-
121
- void fx_Math_acos(txMachine* the)
122
- {
123
- mxNanResultIfNoArg;
124
- fxToNumber(the, mxArgv(0));
125
- mxResult->kind = XS_NUMBER_KIND;
126
- mxResult->value.number = c_acos(mxArgv(0)->value.number);
127
- }
128
-
129
- void fx_Math_acosh(txMachine* the)
130
- {
131
- mxNanResultIfNoArg;
132
- fxToNumber(the, mxArgv(0));
133
- mxResult->kind = XS_NUMBER_KIND;
134
- mxResult->value.number = c_acosh(mxArgv(0)->value.number);
135
- }
136
-
137
- void fx_Math_asin(txMachine* the)
138
- {
139
- mxNanResultIfNoArg;
140
- fxToNumber(the, mxArgv(0));
141
- mxResult->kind = XS_NUMBER_KIND;
142
- mxResult->value.number = c_asin(mxArgv(0)->value.number);
143
- }
144
-
145
- void fx_Math_asinh(txMachine* the)
146
- {
147
- mxNanResultIfNoArg;
148
- fxToNumber(the, mxArgv(0));
149
- mxResult->kind = XS_NUMBER_KIND;
150
- mxResult->value.number = c_asinh(mxArgv(0)->value.number);
151
- }
152
-
153
- void fx_Math_atan(txMachine* the)
154
- {
155
- mxNanResultIfNoArg;
156
- fxToNumber(the, mxArgv(0));
157
- mxResult->kind = XS_NUMBER_KIND;
158
- mxResult->value.number = c_atan(mxArgv(0)->value.number);
159
- }
160
-
161
- void fx_Math_atanh(txMachine* the)
162
- {
163
- mxNanResultIfNoArg;
164
- fxToNumber(the, mxArgv(0));
165
- mxResult->kind = XS_NUMBER_KIND;
166
- mxResult->value.number = c_atanh(mxArgv(0)->value.number);
167
- }
168
-
169
- void fx_Math_atan2(txMachine* the)
170
- {
171
- mxNanResultIfNoArg2;
172
- fxToNumber(the, mxArgv(0));
173
- fxToNumber(the, mxArgv(1));
174
- mxResult->kind = XS_NUMBER_KIND;
175
- mxResult->value.number = c_atan2(mxArgv(0)->value.number, mxArgv(1)->value.number);
176
- }
177
-
178
- void fx_Math_cbrt(txMachine* the)
179
- {
180
- mxNanResultIfNoArg;
181
- fxToNumber(the, mxArgv(0));
182
- mxResult->kind = XS_NUMBER_KIND;
183
- mxResult->value.number = c_cbrt(mxArgv(0)->value.number);
184
- }
185
-
186
- void fx_Math_ceil(txMachine* the)
187
- {
188
- mxNanResultIfNoArg;
189
- if (XS_INTEGER_KIND == mxArgv(0)->kind) {
190
- mxResult->kind = XS_INTEGER_KIND;
191
- mxResult->value.integer = mxArgv(0)->value.integer;
192
- return;
193
- }
194
- fxToNumber(the, mxArgv(0));
195
- mxResult->kind = XS_NUMBER_KIND;
196
- mxResult->value.number = c_ceil(mxArgv(0)->value.number);
197
- fx_Math_toInteger(the);
198
- }
199
-
200
- void fx_Math_clz32(txMachine* the)
201
- {
202
- txUnsigned x = (mxArgc > 0) ? fxToUnsigned(the, mxArgv(0)) : 0;
203
- txInteger r;
204
- if (x)
205
- #if mxWindows
206
- _BitScanForward(&r, x);
207
- #else
208
- r = __builtin_clz(x);
209
- #endif
210
- else
211
- r = 32;
212
- mxResult->kind = XS_INTEGER_KIND;
213
- mxResult->value.integer = r;
214
- }
215
-
216
- void fx_Math_cos(txMachine* the)
217
- {
218
- mxNanResultIfNoArg;
219
- fxToNumber(the, mxArgv(0));
220
- mxResult->kind = XS_NUMBER_KIND;
221
- mxResult->value.number = c_cos(mxArgv(0)->value.number);
222
- }
223
-
224
- void fx_Math_cosh(txMachine* the)
225
- {
226
- mxNanResultIfNoArg;
227
- fxToNumber(the, mxArgv(0));
228
- mxResult->kind = XS_NUMBER_KIND;
229
- mxResult->value.number = c_cosh(mxArgv(0)->value.number);
230
- }
231
-
232
- void fx_Math_exp(txMachine* the)
233
- {
234
- mxNanResultIfNoArg;
235
- fxToNumber(the, mxArgv(0));
236
- mxResult->kind = XS_NUMBER_KIND;
237
- mxResult->value.number = c_exp(mxArgv(0)->value.number);
238
- }
239
-
240
- void fx_Math_expm1(txMachine* the)
241
- {
242
- mxNanResultIfNoArg;
243
- fxToNumber(the, mxArgv(0));
244
- mxResult->kind = XS_NUMBER_KIND;
245
- mxResult->value.number = c_expm1(mxArgv(0)->value.number);
246
- }
247
-
248
- void fx_Math_floor(txMachine* the)
249
- {
250
- mxNanResultIfNoArg;
251
- if (XS_INTEGER_KIND == mxArgv(0)->kind) {
252
- mxResult->kind = XS_INTEGER_KIND;
253
- mxResult->value.integer = mxArgv(0)->value.integer;
254
- return;
255
- }
256
- fxToNumber(the, mxArgv(0));
257
- mxResult->kind = XS_NUMBER_KIND;
258
- mxResult->value.number = c_floor(mxArgv(0)->value.number);
259
- fx_Math_toInteger(the);
260
- }
261
-
262
- void fx_Math_fround(txMachine* the)
263
- {
264
- float arg;
265
- mxNanResultIfNoArg;
266
- if (XS_INTEGER_KIND == mxArgv(0)->kind) {
267
- mxResult->kind = XS_INTEGER_KIND;
268
- mxResult->value.integer = mxArgv(0)->value.integer;
269
- return;
270
- }
271
- arg = (float)fxToNumber(the, mxArgv(0));
272
- mxResult->kind = XS_NUMBER_KIND;
273
- mxResult->value.number = arg;
274
- }
275
-
276
- void fx_Math_hypot(txMachine* the)
277
- {
278
- if (mxArgc == 2) {
279
- fxToNumber(the, mxArgv(0));
280
- fxToNumber(the, mxArgv(1));
281
- mxResult->kind = XS_NUMBER_KIND;
282
- mxResult->value.number = c_hypot(mxArgv(0)->value.number, mxArgv(1)->value.number);
283
- }
284
- else {
285
- txInteger c = mxArgc, i;
286
- txNumber result = 0;
287
- for (i = 0; i < c; i++) {
288
- txNumber argument = fxToNumber(the, mxArgv(i));
289
- result += argument * argument;
290
- }
291
- mxResult->kind = XS_NUMBER_KIND;
292
- mxResult->value.number = c_sqrt(result);
293
- }
294
- }
295
-
296
- void fx_Math_idiv(txMachine* the)
297
- {
298
- txInteger x = (mxArgc > 0) ? fxToInteger(the, mxArgv(0)) : 0;
299
- txInteger y = (mxArgc > 1) ? fxToInteger(the, mxArgv(1)) : 0;
300
- if (y == 0) {
301
- mxResult->kind = XS_NUMBER_KIND;
302
- mxResult->value.number = C_NAN;
303
- }
304
- else {
305
- mxResult->kind = XS_INTEGER_KIND;
306
- #if mxIntegerDivideOverflowException
307
- if ((x == (txInteger)0x80000000) && (y == -1))
308
- mxResult->value.integer = x;
309
- else
310
- #endif
311
- mxResult->value.integer = x / y;
312
- }
313
- }
314
-
315
- void fx_Math_idivmod(txMachine* the)
316
- {
317
- txInteger x = (mxArgc > 0) ? fxToInteger(the, mxArgv(0)) : 0;
318
- txInteger y = (mxArgc > 1) ? fxToInteger(the, mxArgv(1)) : 0;
319
- if (y == 0) {
320
- mxPushNumber(C_NAN);
321
- mxPushNumber(C_NAN);
322
- }
323
- else {
324
- #if mxIntegerDivideOverflowException
325
- if ((x == (txInteger)0x80000000) && (y == -1)) {
326
- mxPushInteger(x);
327
- mxPushInteger(0);
328
- }
329
- else
330
- #endif
331
- {
332
- mxPushInteger(x / y);
333
- mxPushInteger((x % y + y) % y);
334
- }
335
- }
336
- fxConstructArrayEntry(the, mxResult);
337
- }
338
-
339
- void fx_Math_imod(txMachine* the)
340
- {
341
- txInteger x = (mxArgc > 0) ? fxToInteger(the, mxArgv(0)) : 0;
342
- txInteger y = (mxArgc > 1) ? fxToInteger(the, mxArgv(1)) : 0;
343
- if (y == 0) {
344
- mxResult->kind = XS_NUMBER_KIND;
345
- mxResult->value.number = C_NAN;
346
- }
347
- else {
348
- mxResult->kind = XS_INTEGER_KIND;
349
- #if mxIntegerDivideOverflowException
350
- if ((x == (txInteger)0x80000000) && (y == -1))
351
- mxResult->value.integer = 0;
352
- else
353
- #endif
354
- mxResult->value.integer = (x % y + y) % y;
355
- }
356
- }
357
-
358
- void fx_Math_imul(txMachine* the)
359
- {
360
- txInteger x = (mxArgc > 0) ? fxToInteger(the, mxArgv(0)) : 0;
361
- txInteger y = (mxArgc > 1) ? fxToInteger(the, mxArgv(1)) : 0;
362
- mxResult->kind = XS_INTEGER_KIND;
363
- mxResult->value.integer = x * y;
364
- }
365
-
366
- void fx_Math_imuldiv(txMachine* the)
367
- {
368
- txS8 x = (mxArgc > 0) ? fxToInteger(the, mxArgv(0)) : 0;
369
- txS8 y = (mxArgc > 1) ? fxToInteger(the, mxArgv(1)) : 0;
370
- txS8 z = (mxArgc > 2) ? fxToInteger(the, mxArgv(2)) : 0;
371
- if (z == 0) {
372
- mxResult->kind = XS_NUMBER_KIND;
373
- mxResult->value.number = C_NAN;
374
- }
375
- else {
376
- txS8 r = (x * y) / z;
377
- if ((-2147483648LL <= r) && (r <= 2147483647LL)) {
378
- mxResult->kind = XS_INTEGER_KIND;
379
- mxResult->value.integer = (txInteger)r;
380
- }
381
- else {
382
- mxResult->kind = XS_NUMBER_KIND;
383
- mxResult->value.number = (txNumber)r;
384
- }
385
- }
386
- }
387
-
388
- void fx_Math_irem(txMachine* the)
389
- {
390
- txInteger x = (mxArgc > 0) ? fxToInteger(the, mxArgv(0)) : 0;
391
- txInteger y = (mxArgc > 1) ? fxToInteger(the, mxArgv(1)) : 0;
392
- if (y == 0) {
393
- mxResult->kind = XS_NUMBER_KIND;
394
- mxResult->value.number = C_NAN;
395
- }
396
- else {
397
- mxResult->kind = XS_INTEGER_KIND;
398
- #if mxIntegerDivideOverflowException
399
- if ((x == (txInteger)0x80000000) && (y == -1))
400
- mxResult->value.integer = 0;
401
- else
402
- #endif
403
- mxResult->value.integer = x % y;
404
- }
405
- }
406
-
407
- void fx_Math_log(txMachine* the)
408
- {
409
- mxNanResultIfNoArg;
410
- fxToNumber(the, mxArgv(0));
411
- mxResult->kind = XS_NUMBER_KIND;
412
- mxResult->value.number = c_log(mxArgv(0)->value.number);
413
- }
414
-
415
- void fx_Math_log1p(txMachine* the)
416
- {
417
- mxNanResultIfNoArg;
418
- fxToNumber(the, mxArgv(0));
419
- mxResult->kind = XS_NUMBER_KIND;
420
- mxResult->value.number = c_log1p(mxArgv(0)->value.number);
421
- }
422
-
423
- void fx_Math_log10(txMachine* the)
424
- {
425
- mxNanResultIfNoArg;
426
- fxToNumber(the, mxArgv(0));
427
- mxResult->kind = XS_NUMBER_KIND;
428
- mxResult->value.number = c_log10(mxArgv(0)->value.number);
429
- }
430
-
431
- void fx_Math_log2(txMachine* the)
432
- {
433
- mxNanResultIfNoArg;
434
- fxToNumber(the, mxArgv(0));
435
- mxResult->kind = XS_NUMBER_KIND;
436
- #if mxAndroid
437
- mxResult->value.number = c_log(mxArgv(0)->value.number) / c_log(2);
438
- #else
439
- mxResult->value.number = c_log2(mxArgv(0)->value.number);
440
- #endif
441
- }
442
-
443
- void fx_Math_max(txMachine* the)
444
- {
445
- txInteger c = mxArgc, i;
446
- mxResult->kind = XS_NUMBER_KIND;
447
- mxResult->value.number = -((txNumber)C_INFINITY);
448
- for (i = 0; i < c; i++) {
449
- txNumber n = fxToNumber(the, mxArgv(i));
450
- if (c_isnan(n)) {
451
- for (; i < c; i++)
452
- fxToNumber(the, mxArgv(i));
453
- mxResult->value.number = C_NAN;
454
- return;
455
- }
456
- if (mxResult->value.number < n)
457
- mxResult->value.number = n;
458
- else if ((mxResult->value.number == 0) && (n == 0)) {
459
- if (c_signbit(mxResult->value.number) != c_signbit(n))
460
- mxResult->value.number = 0;
461
- }
462
- }
463
- }
464
-
465
- void fx_Math_min(txMachine* the)
466
- {
467
- txInteger c = mxArgc, i;
468
- mxResult->kind = XS_NUMBER_KIND;
469
- mxResult->value.number = (txNumber)C_INFINITY;
470
- for (i = 0; i < c; i++) {
471
- txNumber n = fxToNumber(the, mxArgv(i));
472
- if (c_isnan(n)) {
473
- for (; i < c; i++)
474
- fxToNumber(the, mxArgv(i));
475
- mxResult->value.number = C_NAN;
476
- return;
477
- }
478
- if (mxResult->value.number > n)
479
- mxResult->value.number = n;
480
- else if ((mxResult->value.number == 0) && (n == 0)) {
481
- if (c_signbit(mxResult->value.number) != c_signbit(n))
482
- mxResult->value.number = -0.0;
483
- }
484
- }
485
- }
486
-
487
- void fx_Math_mod(txMachine* the)
488
- {
489
- txNumber x = (mxArgc > 0) ? fxToNumber(the, mxArgv(0)) : 0;
490
- txNumber y = (mxArgc > 1) ? fxToNumber(the, mxArgv(1)) : 0;
491
- mxResult->kind = XS_NUMBER_KIND;
492
- mxResult->value.number = c_fmod((c_fmod(x, y) + y), y);
493
- }
494
-
495
- txNumber fx_pow(txNumber x, txNumber y)
496
- {
497
- if (!c_isfinite(y) && (c_fabs(x) == 1.0))
498
- return C_NAN;
499
- return c_pow(x, y);
500
- }
501
-
502
- void fx_Math_pow(txMachine* the)
503
- {
504
- txNumber x, y;
505
- mxNanResultIfNoArg2;
506
- x = fxToNumber(the, mxArgv(0));
507
- y = fxToNumber(the, mxArgv(1));
508
- mxResult->kind = XS_NUMBER_KIND;
509
- mxResult->value.number = fx_pow(x, y);
510
- }
511
-
512
- void fx_Math_random(txMachine* the)
513
- {
514
- uint32_t result = c_rand();
515
- while (result == C_RAND_MAX)
516
- result = c_rand();
517
- mxResult->kind = XS_NUMBER_KIND;
518
- mxResult->value.number = (double)result / (double)C_RAND_MAX;
519
- }
520
-
521
- void fx_Math_random_secure(txMachine* the)
522
- {
523
- mxTypeError("secure mode");
524
- }
525
-
526
- void fx_Math_round(txMachine* the)
527
- {
528
- txNumber arg;
529
- mxNanResultIfNoArg;
530
- if (XS_INTEGER_KIND == mxArgv(0)->kind) {
531
- mxResult->kind = XS_INTEGER_KIND;
532
- mxResult->value.integer = mxArgv(0)->value.integer;
533
- return;
534
- }
535
- arg = fxToNumber(the, mxArgv(0));
536
- if (c_isnormal(arg) && (-4503599627370495 < arg) && (arg < 4503599627370495)) { // 2 ** 52 - 1
537
- if ((arg < -0.5) || (0.5 <= arg))
538
- arg = c_floor(arg + 0.5);
539
- else if (arg < 0)
540
- arg = -0.0;
541
- else if (arg > 0)
542
- arg = 0.0;
543
- }
544
- mxResult->kind = XS_NUMBER_KIND;
545
- mxResult->value.number = arg;
546
- fx_Math_toInteger(the);
547
- }
548
-
549
- void fx_Math_sqrt(txMachine* the)
550
- {
551
- mxNanResultIfNoArg;
552
- fxToNumber(the, mxArgv(0));
553
- mxResult->kind = XS_NUMBER_KIND;
554
- mxResult->value.number = c_sqrt(mxArgv(0)->value.number);
555
- }
556
-
557
- void fx_Math_sign(txMachine* the)
558
- {
559
- txNumber arg;
560
- mxNanResultIfNoArg;
561
- arg = fxToNumber(the, mxArgv(0));
562
- mxResult->kind = XS_NUMBER_KIND;
563
- if (c_isnan(arg))
564
- mxResult->value.number = C_NAN;
565
- else if (arg < 0)
566
- mxResult->value.number = -1;
567
- else if (arg > 0)
568
- mxResult->value.number = 1;
569
- else
570
- mxResult->value.number = arg;
571
- fx_Math_toInteger(the);
572
- }
573
-
574
- void fx_Math_sin(txMachine* the)
575
- {
576
- mxNanResultIfNoArg;
577
- fxToNumber(the, mxArgv(0));
578
- mxResult->kind = XS_NUMBER_KIND;
579
- mxResult->value.number = c_sin(mxArgv(0)->value.number);
580
- }
581
-
582
- void fx_Math_sinh(txMachine* the)
583
- {
584
- mxNanResultIfNoArg;
585
- fxToNumber(the, mxArgv(0));
586
- mxResult->kind = XS_NUMBER_KIND;
587
- mxResult->value.number = c_sinh(mxArgv(0)->value.number);
588
- }
589
-
590
- void fx_Math_tan(txMachine* the)
591
- {
592
- mxNanResultIfNoArg;
593
- fxToNumber(the, mxArgv(0));
594
- mxResult->kind = XS_NUMBER_KIND;
595
- mxResult->value.number = c_tan(mxArgv(0)->value.number);
596
- }
597
-
598
- void fx_Math_tanh(txMachine* the)
599
- {
600
- mxNanResultIfNoArg;
601
- fxToNumber(the, mxArgv(0));
602
- mxResult->kind = XS_NUMBER_KIND;
603
- mxResult->value.number = c_tanh(mxArgv(0)->value.number);
604
- }
605
-
606
- void fx_Math_trunc(txMachine* the)
607
- {
608
- mxNanResultIfNoArg;
609
- fxToNumber(the, mxArgv(0));
610
- mxResult->kind = XS_NUMBER_KIND;
611
- mxResult->value.number = c_trunc(mxArgv(0)->value.number);
612
- fx_Math_toInteger(the);
613
- }
614
-
615
- void fx_Math_toInteger(txMachine* the)
616
- {
617
- txNumber number = mxResult->value.number;
618
- txInteger integer = (txInteger)number;
619
- txNumber check = integer;
620
- if ((number == check) && (number || !c_signbit(number))) {
621
- mxResult->value.integer = integer;
622
- mxResult->kind = XS_INTEGER_KIND;
623
- }
624
- }