2020-06-15 14:18:57 +00:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
|
|
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
2020-06-15 14:18:57 +00:00
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
2020-06-15 14:18:57 +00:00
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2021-02-26 02:30:17 +00:00
|
|
|
#include "libc/calls/struct/sigaction.h"
|
|
|
|
#include "libc/calls/struct/siginfo.h"
|
|
|
|
#include "libc/calls/ucontext.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/math.h"
|
|
|
|
#include "libc/runtime/gc.h"
|
2021-02-26 02:30:17 +00:00
|
|
|
#include "libc/runtime/pc.internal.h"
|
2021-03-02 21:57:23 +00:00
|
|
|
#include "libc/stdio/stdio.h"
|
2021-02-26 02:30:17 +00:00
|
|
|
#include "libc/sysv/consts/sa.h"
|
|
|
|
#include "libc/sysv/consts/sig.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/testlib/ezbench.h"
|
|
|
|
#include "libc/testlib/testlib.h"
|
|
|
|
#include "libc/x/x.h"
|
|
|
|
|
|
|
|
TEST(powl, testLongDouble) {
|
2021-03-02 21:57:23 +00:00
|
|
|
EXPECT_STREQ("27", gc(xdtoal(powl(3, 3))));
|
|
|
|
EXPECT_STREQ("-27", gc(xdtoal(powl(-3, 3))));
|
|
|
|
EXPECT_STREQ("-1", gc(xdtoal(powl(-1, 1.1))));
|
2021-02-26 02:30:17 +00:00
|
|
|
EXPECT_STREQ("1e+4932", gc(xdtoal(powl(10, 4932))));
|
|
|
|
EXPECT_STREQ("INFINITY", gc(xdtoal(powl(10, 4933))));
|
|
|
|
EXPECT_STREQ("0", gc(xdtoal(powl(10, -5000))));
|
|
|
|
EXPECT_STREQ("1.063382396627933e+37", gc(xdtoal(powl(2, 123))));
|
|
|
|
EXPECT_STARTSWITH(".4248496805467504", gc(xdtoal(powl(0.7, 2.4))));
|
2020-06-15 14:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(powl, testDouble) {
|
2021-03-02 21:57:23 +00:00
|
|
|
EXPECT_STREQ("27", gc(xdtoa(pow(3, 3))));
|
|
|
|
EXPECT_STREQ("-27", gc(xdtoa(pow(-3, 3))));
|
2021-02-26 02:30:17 +00:00
|
|
|
EXPECT_STREQ("1e+308", gc(xdtoa(pow(10, 308))));
|
|
|
|
EXPECT_STREQ("INFINITY", gc(xdtoa(pow(10, 309))));
|
|
|
|
EXPECT_STARTSWITH(".42484968054675", gc(xdtoa(pow(0.7, 2.4))));
|
2020-06-15 14:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(powl, testFloat) {
|
2021-03-02 21:57:23 +00:00
|
|
|
EXPECT_STREQ("27", gc(xdtoaf(powf(3, 3))));
|
|
|
|
EXPECT_STREQ("-27", gc(xdtoaf(powf(-3, 3))));
|
2020-06-15 14:18:57 +00:00
|
|
|
EXPECT_STARTSWITH(".4248496", gc(xdtoa(powf(0.7f, 2.4f))));
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCH(powl, bench) {
|
2021-02-26 02:30:17 +00:00
|
|
|
double _pow(double, double) asm("pow");
|
|
|
|
float _powf(float, float) asm("powf");
|
|
|
|
long double _powl(long double, long double) asm("powl");
|
|
|
|
EZBENCH2("pow", donothing, _pow(.7, .2)); /* ~51ns */
|
|
|
|
EZBENCH2("powf", donothing, _powf(.7, .2)); /* ~52ns */
|
|
|
|
EZBENCH2("powl", donothing, _powl(.7, .2)); /* ~53ns */
|
2020-06-15 14:18:57 +00:00
|
|
|
}
|