Fix issues revealed by ECMAScript test262

Cosmopolitan's QuickJS is now equally conformant and performant, with
the exception of Atomics, which have been disabled since Cosmopolitan
currently doesn't support pthreads.

QuickJS memory usage -- BigNum 2021-03-27 version, 64-bit, malloc limit: -1

NAME                    COUNT     SIZE
memory allocated          937   131764  (140.6 per block)
memory used               938   116103  (8 overhead, 16.7 average slack)
atoms                     513    21408  (41.7 per atom)
objects                   170    12279  (72.2 per object)
  properties              864    15531  (5.1 per object)
  shapes                   58    12995  (224.1 per shape)
bytecode functions         13     1512
  bytecode                 13      867  (66.7 per function)
C functions                99
arrays                      1
  fast arrays               1
  elements                  1       16  (1.0 per fast array)

Result: 35/74740 errors, 1279 excluded, 485 skipped, 19 new, 2 fixed

real    2m40.828s
user    2m29.764s
sys     0m10.939s
This commit is contained in:
Justine Tunney 2021-04-10 16:22:35 -07:00
parent 8f52c0d773
commit 8a91518633
38 changed files with 395 additions and 184 deletions

View file

@ -22,5 +22,5 @@
* Returns inverse hyperbolic tangent of 𝑥.
*/
double atanh(double x) {
return log((1 + x) / (1 - x)) / 2;
return x ? log((1 + x) / (1 - x)) / 2 : x;
}

View file

@ -22,5 +22,5 @@
* Returns inverse hyperbolic tangent of 𝑥.
*/
float atanhf(float x) {
return logf((1 + x) / (1 - x)) / 2;
return x ? logf((1 + x) / (1 - x)) / 2 : x;
}

View file

@ -22,5 +22,5 @@
* Returns inverse hyperbolic tangent of 𝑥.
*/
long double atanhl(long double x) {
return logl((1 + x) / (1 - x)) / 2;
return x ? logl((1 + x) / (1 - x)) / 2 : x;
}

View file

@ -19,7 +19,7 @@
#include "libc/runtime/pc.internal.h"
#include "libc/macros.internal.h"
// Returns 𝑒^x-1.
// Returns 𝑒^𝑥-𝟷.
//
// @param 𝑥 is an 80-bit long double passed on stack in 16-bytes
// @return result of exponentiation on FPU stack in %st
@ -27,11 +27,13 @@ expm1l: push %rbp
mov %rsp,%rbp
.profilable
fldt 16(%rbp)
fxam # isinf(x)
fxam
fstsw %ax
mov %ah,%al
and $0x45,%ah
cmp $5,%ah
and $(FPU_C3|FPU_C2|FPU_C0)>>8,%ah
cmp $(FPU_C3)>>8,%ah # !x
je 0f
cmp $(FPU_C2|FPU_C0)>>8,%ah # isinf(x)
je 1f
fldl2e
fmulp %st,%st(1)
@ -50,7 +52,7 @@ expm1l: push %rbp
faddp %st,%st(1)
0: pop %rbp
ret
1: test $2,%al # signbit(x)
1: test $FPU_C1>>8,%al # signbit(x)
jz 0b
fstp %st
fld1

View file

@ -46,7 +46,11 @@ long double powl(long double x, long double y) {
return 1;
}
} else if (y > 0) {
return y == 1 ? x : 0;
if (signbit(x) && y == truncl(y) && ((int64_t)y & 1)) {
return -0.;
} else {
return 0;
}
} else if (!y) {
return 1;
} else {

View file

@ -22,5 +22,6 @@
* Returns hyperbolic sine of 𝑥.
*/
double sinh(double x) {
if (!x) return x;
return (exp(x) - exp(-x)) / 2;
}

View file

@ -22,5 +22,6 @@
* Returns hyperbolic sine of 𝑥.
*/
float sinhf(float x) {
if (!x) return x;
return (expf(x) - expf(-x)) / 2;
}

View file

@ -22,5 +22,6 @@
* Returns hyperbolic sine of 𝑥.
*/
long double sinhl(long double x) {
if (!x) return x;
return (expl(x) - expl(-x)) / 2;
}

View file

@ -22,6 +22,7 @@
* Returns hyperbolic tangent of 𝑥.
*/
double tanh(double x) {
if (!x) return x;
if (isinf(x)) return copysign(1, x);
return sinh(x) / cosh(x);
}

View file

@ -22,6 +22,7 @@
* Returns hyperbolic tangent of 𝑥.
*/
float tanhf(float x) {
if (!x) return x;
if (isinf(x)) return copysignf(1, x);
return sinhf(x) / coshf(x);
}

View file

@ -22,6 +22,7 @@
* Returns hyperbolic tangent of 𝑥.
*/
long double tanhl(long double x) {
if (!x) return x;
if (isinf(x)) return copysignl(1, x);
return sinhl(x) / coshl(x);
}