math_tests: pow test (#1842)

* math::nolibc: replaced code with word macros

* math_tests: pow test

Added test for pow and added more test points for the exp and log tests.
This commit is contained in:
Taylor W
2025-01-15 06:35:18 -06:00
committed by GitHub
parent 2f7d18bfb8
commit 660654f9e0
5 changed files with 104 additions and 45 deletions

View File

@@ -217,30 +217,21 @@ fn float _atanf(float x) @weak @extern("atanf") @nostrip
const PI_LO @private = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
macro void extract_words(double d, uint* hi, uint* lo) @private
{
ulong rep = bitcast(d, ulong);
*hi = (uint)(rep >> 32);
*lo = (uint)rep;
}
fn double _atan2(double y, double x) @weak @extern("atan2") @nostrip
{
if (math::is_nan(x) || math::is_nan(y)) return x + y;
uint lx @noinit;
uint ix @noinit;
extract_words(x, &ix, &lx);
uint ly @noinit;
uint iy @noinit;
extract_words(y, &iy, &ly);
uint lx = x.low_word();
uint ix = x.high_word();
uint ly = y.low_word();
uint iy = y.high_word();
// x = 1.0
if ((ix - 0x3ff00000) | lx == 0) return _atan(y);
// 2*sign(x) + sign(y)
uint m = ((iy >> 31) & 1) | ((ix >> 30) & 2);
ix = ix & 0x7fffffff;
iy = iy & 0x7fffffff;
ix &= 0x7fffffff;
iy &= 0x7fffffff;
// when y = 0
if (iy | ly == 0)
@@ -313,8 +304,8 @@ const float PI_LO_F @private = -8.7422776573e-08; /* 0xb3bbbd2e */
fn float _atan2f(float y, float x) @weak @extern("atan2f") @nostrip
{
if (math::is_nan(x) || math::is_nan(y)) return x + y;
uint ix = bitcast(x, uint);
uint iy = bitcast(y, uint);
uint ix = x.word();
uint iy = y.word();
/* x=1.0 */
if (ix == 0x3f800000) return _atanf(y);
/* 2*sign(x)+sign(y) */

View File

@@ -2,7 +2,7 @@ module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH));
fn float _cosf(float x) @extern("cosf") @weak @nostrip
{
uint ix = bitcast(x, uint);
uint ix = x.word();
uint sign = ix >> 31;
ix &= 0x7fffffff;
@@ -54,8 +54,7 @@ fn float _cosf(float x) @extern("cosf") @weak @nostrip
fn double _cos(double x) @extern("cos") @weak @nostrip
{
// High word of x.
uint ix = (uint)(bitcast(x, ulong) >> 32);
ix &= 0x7fffffff;
uint ix = x.high_word() & 0x7fffffff;
switch
{

View File

@@ -18,7 +18,7 @@ module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH));
fn float _sinf(float x) @weak @extern("sinf") @nostrip
{
uint ix = bitcast(x, uint);
uint ix = x.word();
int sign = ix >> 31;
ix &= 0x7fffffff;
switch
@@ -87,8 +87,7 @@ fn float _sinf(float x) @weak @extern("sinf") @nostrip
fn double sin(double x) @extern("sin") @weak @nostrip
{
// High word of x.
uint ix = (uint)(bitcast(x, ulong) >> 32);
ix &= 0x7fffffff;
uint ix = x.high_word() & 0x7fffffff;
switch
{
// |x| ~< pi/4

View File

@@ -18,8 +18,7 @@ module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH));
fn void sincosf(float x, float *sin, float *cos) @extern("__sincosf") @weak @nostrip
{
uint ix = bitcast(x, uint);
uint ix = x.word();
uint sign = ix >> 31;
ix &= 0x7fffffff;
@@ -108,8 +107,7 @@ fn void sincosf(float x, float *sin, float *cos) @extern("__sincosf") @weak @nos
fn void sincos(double x, double *sin, double *cos) @extern("__sincos") @weak @nostrip
{
// High word of x.
uint ix = (uint)(bitcast(x, ulong) >> 32);
ix &= 0x7fffffff;
uint ix = x.high_word() & 0x7fffffff;
// |x| ~< pi/4
switch