Skip to content

Commit 164f134

Browse files
authored
Even more math (AssemblyScript#56)
Remaining implementations of JavaScript's Math functions (except sin/cos/tan), both double (Math) and single (Mathf) precision, ported from musl incl. tests from libc-test, plus some changes to match JS semantics. Also binds fmod to `%` and pow to `**`.
1 parent e47a130 commit 164f134

29 files changed

+147527
-19380
lines changed

NOTICE

Lines changed: 228 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,248 @@
11
Copyright (c) 2017-2018 AssemblyScript authors.
22

33
The following authors have all licensed their contributions to AssemblyScript
4-
under the licensing terms detailed in LICENSE.
4+
under the licensing terms detailed in LICENSE:
55

66
* Daniel Wirtz <dcode@dcode.io>
77
* Max Graey <maxgraey@gmail.com>
88
* Igor Sbitnev <PinkaminaDianePie@gmail.com>
99
* Norton Wang <me@nortonwang.com>
1010

11-
================================================================================
11+
Portions of this software are derived from third-party works licensed under
12+
the following terms:
1213

13-
This program includes parts of TypeScript:
14-
15-
https://github.com/Microsoft/TypeScript
14+
* TypeScript: https://github.com/Microsoft/TypeScript
1615

1716
Copyright (c) Microsoft Corporation. All rights reserved.
18-
Apache License, Version 2.0
19-
https://www.apache.org/licenses/LICENSE-2.0
17+
Apache License, Version 2.0 (see LICENSE file)
2018

21-
================================================================================
19+
* Binaryen: https://github.com/WebAssembly/binaryen
2220

23-
This program includes parts of Binaryen:
21+
Copyright 2015 WebAssembly Community Group participants
22+
Apache License, Version 2.0 (see LICENSE file)
2423

25-
https://github.com/WebAssembly/binaryen
24+
* musl: http://www.musl-libc.org
2625

27-
Copyright 2015 WebAssembly Community Group participants
28-
Apache License, Version 2.0
29-
https://www.apache.org/licenses/LICENSE-2.0
26+
musl as a whole is licensed under the following standard MIT license:
3027

31-
================================================================================
28+
----------------------------------------------------------------------
29+
Copyright © 2005-2014 Rich Felker, et al.
3230

33-
This program includes parts of musl:
31+
Permission is hereby granted, free of charge, to any person obtaining
32+
a copy of this software and associated documentation files (the
33+
"Software"), to deal in the Software without restriction, including
34+
without limitation the rights to use, copy, modify, merge, publish,
35+
distribute, sublicense, and/or sell copies of the Software, and to
36+
permit persons to whom the Software is furnished to do so, subject to
37+
the following conditions:
3438

35-
http://www.musl-libc.org
39+
The above copyright notice and this permission notice shall be
40+
included in all copies or substantial portions of the Software.
3641

37-
Copyright © 2005-2014 Rich Felker, et al.
38-
MIT License
39-
https://opensource.org/licenses/MIT
42+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49+
----------------------------------------------------------------------
50+
51+
Authors/contributors include:
52+
53+
Alex Dowad
54+
Alexander Monakov
55+
Anthony G. Basile
56+
Arvid Picciani
57+
Bobby Bingham
58+
Boris Brezillon
59+
Brent Cook
60+
Chris Spiegel
61+
Clément Vasseur
62+
Daniel Micay
63+
Denys Vlasenko
64+
Emil Renner Berthing
65+
Felix Fietkau
66+
Felix Janda
67+
Gianluca Anzolin
68+
Hauke Mehrtens
69+
Hiltjo Posthuma
70+
Isaac Dunham
71+
Jaydeep Patil
72+
Jens Gustedt
73+
Jeremy Huntwork
74+
Jo-Philipp Wich
75+
Joakim Sindholt
76+
John Spencer
77+
Josiah Worcester
78+
Justin Cormack
79+
Khem Raj
80+
Kylie McClain
81+
Luca Barbato
82+
Luka Perkov
83+
M Farkas-Dyck (Strake)
84+
Mahesh Bodapati
85+
Michael Forney
86+
Natanael Copa
87+
Nicholas J. Kain
88+
orc
89+
Pascal Cuoq
90+
Petr Hosek
91+
Pierre Carrier
92+
Rich Felker
93+
Richard Pennington
94+
Shiz
95+
sin
96+
Solar Designer
97+
Stefan Kristiansson
98+
Szabolcs Nagy
99+
Timo Teräs
100+
Trutz Behn
101+
Valentin Ochs
102+
William Haddon
103+
104+
Portions of this software are derived from third-party works licensed
105+
under terms compatible with the above MIT license:
106+
107+
The TRE regular expression implementation (src/regex/reg* and
108+
src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed
109+
under a 2-clause BSD license (license text in the source files). The
110+
included version has been heavily modified by Rich Felker in 2012, in
111+
the interests of size, simplicity, and namespace cleanliness.
112+
113+
Much of the math library code (src/math/* and src/complex/*) is
114+
Copyright © 1993,2004 Sun Microsystems or
115+
Copyright © 2003-2011 David Schultz or
116+
Copyright © 2003-2009 Steven G. Kargl or
117+
Copyright © 2003-2009 Bruce D. Evans or
118+
Copyright © 2008 Stephen L. Moshier
119+
and labelled as such in comments in the individual source files. All
120+
have been licensed under extremely permissive terms.
121+
122+
The ARM memcpy code (src/string/arm/memcpy_el.S) is Copyright © 2008
123+
The Android Open Source Project and is licensed under a two-clause BSD
124+
license. It was taken from Bionic libc, used on Android.
125+
126+
The implementation of DES for crypt (src/crypt/crypt_des.c) is
127+
Copyright © 1994 David Burren. It is licensed under a BSD license.
128+
129+
The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was
130+
originally written by Solar Designer and placed into the public
131+
domain. The code also comes with a fallback permissive license for use
132+
in jurisdictions that may not recognize the public domain.
133+
134+
The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011
135+
Valentin Ochs and is licensed under an MIT-style license.
136+
137+
The BSD PRNG implementation (src/prng/random.c) and XSI search API
138+
(src/search/*.c) functions are Copyright © 2011 Szabolcs Nagy and
139+
licensed under following terms: "Permission to use, copy, modify,
140+
and/or distribute this code for any purpose with or without fee is
141+
hereby granted. There is no warranty."
142+
143+
The x86_64 port was written by Nicholas J. Kain and is licensed under
144+
the standard MIT terms.
145+
146+
The mips and microblaze ports were originally written by Richard
147+
Pennington for use in the ellcc project. The original code was adapted
148+
by Rich Felker for build system and code conventions during upstream
149+
integration. It is licensed under the standard MIT terms.
150+
151+
The mips64 port was contributed by Imagination Technologies and is
152+
licensed under the standard MIT terms.
153+
154+
The powerpc port was also originally written by Richard Pennington,
155+
and later supplemented and integrated by John Spencer. It is licensed
156+
under the standard MIT terms.
157+
158+
All other files which have no copyright comments are original works
159+
produced specifically for use as part of this library, written either
160+
by Rich Felker, the main author of the library, or by one or more
161+
contibutors listed above. Details on authorship of individual files
162+
can be found in the git version control history of the project. The
163+
omission of copyright and license comments in each file is in the
164+
interest of source tree size.
165+
166+
In addition, permission is hereby granted for all public header files
167+
(include/* and arch/*/bits/*) and crt files intended to be linked into
168+
applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit
169+
the copyright notice and permission notice otherwise required by the
170+
license, and to use these files without any requirement of
171+
attribution. These files include substantial contributions from:
172+
173+
Bobby Bingham
174+
John Spencer
175+
Nicholas J. Kain
176+
Rich Felker
177+
Richard Pennington
178+
Stefan Kristiansson
179+
Szabolcs Nagy
180+
181+
all of whom have explicitly granted such permission.
182+
183+
This file previously contained text expressing a belief that most of
184+
the files covered by the above exception were sufficiently trivial not
185+
to be subject to copyright, resulting in confusion over whether it
186+
negated the permissions granted in the license. In the spirit of
187+
permissive licensing, and of not having licensing issues being an
188+
obstacle to adoption, that text has been removed.
189+
190+
* V8: https://developers.google.com/v8/
191+
192+
This license applies to all parts of V8 that are not externally
193+
maintained libraries. The externally maintained libraries used by V8
194+
are:
195+
196+
- PCRE test suite, located in
197+
test/mjsunit/third_party/regexp-pcre/regexp-pcre.js. This is based on the
198+
test suite from PCRE-7.3, which is copyrighted by the University
199+
of Cambridge and Google, Inc. The copyright notice and license
200+
are embedded in regexp-pcre.js.
201+
202+
- Layout tests, located in test/mjsunit/third_party/object-keys. These are
203+
based on layout tests from webkit.org which are copyrighted by
204+
Apple Computer, Inc. and released under a 3-clause BSD license.
205+
206+
- Strongtalk assembler, the basis of the files assembler-arm-inl.h,
207+
assembler-arm.cc, assembler-arm.h, assembler-ia32-inl.h,
208+
assembler-ia32.cc, assembler-ia32.h, assembler-x64-inl.h,
209+
assembler-x64.cc, assembler-x64.h, assembler-mips-inl.h,
210+
assembler-mips.cc, assembler-mips.h, assembler.cc and assembler.h.
211+
This code is copyrighted by Sun Microsystems Inc. and released
212+
under a 3-clause BSD license.
213+
214+
- Valgrind client API header, located at third_party/valgrind/valgrind.h
215+
This is release under the BSD license.
216+
217+
These libraries have their own licenses; we recommend you read them,
218+
as their terms may differ from the terms below.
219+
220+
Further license information can be found in LICENSE files located in
221+
sub-directories.
222+
223+
Copyright 2014, the V8 project authors. All rights reserved.
224+
Redistribution and use in source and binary forms, with or without
225+
modification, are permitted provided that the following conditions are
226+
met:
227+
228+
* Redistributions of source code must retain the above copyright
229+
notice, this list of conditions and the following disclaimer.
230+
* Redistributions in binary form must reproduce the above
231+
copyright notice, this list of conditions and the following
232+
disclaimer in the documentation and/or other materials provided
233+
with the distribution.
234+
* Neither the name of Google Inc. nor the names of its
235+
contributors may be used to endorse or promote products derived
236+
from this software without specific prior written permission.
237+
238+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
239+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
240+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
241+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
242+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
243+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
244+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
245+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
247+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
248+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bin/asc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,12 @@ exports.main = function main(argv, options, callback) {
363363
assemblyscript.setImportTable(compilerOptions, !!args.importTable);
364364
assemblyscript.setMemoryBase(compilerOptions, args.memoryBase >>> 0);
365365
assemblyscript.setSourceMap(compilerOptions, args.sourceMap != null);
366+
367+
// Initialize default aliases
366368
assemblyscript.setGlobalAlias(compilerOptions, "Math", "NativeMath");
369+
assemblyscript.setGlobalAlias(compilerOptions, "Mathf", "NativeMathf");
367370

368-
// Add or override global aliases if specified
371+
// Add or override aliases if specified
369372
var aliases = args.use;
370373
if (aliases != null) {
371374
if (typeof aliases === "string") aliases = aliases.split(",");

scripts/hexfloat.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ <h1>Hexadecimal float to decimal float converter</h1>
1010
<p>
1111
<label for="f64"><input id="f64" name="precision" value="f64" type="radio" checked /> f64</label>
1212
<label for="f32"><input id="f32" name="precision" value="f32" type="radio" /> f32</label>
13-
<input id="name" type="text" value="test" />
13+
<input id="pre" type="text" value="test(" />
14+
<input id="post" type="text" value=");" />
1415
<button>Convert</button>
1516
</p>
1617
<p><textarea cols="120" rows="20" id="input"></textarea></p>
@@ -21,17 +22,19 @@ <h1>Hexadecimal float to decimal float converter</h1>
2122
<script>
2223
function convert(form) {
2324
var isF64 = document.getElementById("f64").checked;
24-
var name = document.getElementById("name").value;
25+
var pre = document.getElementById("pre").value;
26+
var post = document.getElementById("post").value;
2527
var input = document.getElementById("input").value;
2628
document.getElementById("output").value = input
2729
.replace(/\b(\-?0x[0-9a-fA-F]*(?:\.[0-9a-fA-F]+)?[pP][+-]?[0-9]+\b)/g, ($0, $1) => {
2830
var val = parse($1);
2931
return val.toPrecision(isF64 ? 18 : 10);
3032
})
33+
.replace(/(\d\.[0-9])0+\b/g, "$1")
3134
.replace(/\bnan\b/g, "NaN")
3235
.replace(/\binf\b/g, "Infinity")
33-
.replace(/^T\(R\w, */mg, name + "(")
34-
.replace(/\)$/mg, ");")
36+
.replace(/^T\(R\w, */mg, pre)
37+
.replace(/\);?$/mg, post)
3538
.replace(/ +/g, " ");
3639
}
3740
</script>

0 commit comments

Comments
 (0)