Path: blob/main/contrib/arm-optimized-routines/math/test/trigpi_references.h
48254 views
/*1* Extended precision scalar reference functions for trigpi.2*3* Copyright (c) 2023-2024, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/67#include "math_config.h"89#ifndef M_PIl10# define M_PIl 3.141592653589793238462643383279502884l11#endif1213long double14arm_math_sinpil (long double x)15{16/* sin(inf) should return nan, as defined by C23. */17if (isinf (x))18return __math_invalid (x);1920long double ax = fabsl (x);2122/* Return 0 for all values above 2^64 to prevent23overflow when casting to uint64_t. */24if (ax >= 0x1p64)25return x < 0 ? -0.0l : 0.0l;2627/* All integer cases should return 0, with unchanged sign for zero. */28if (x == 0.0l)29return x;30if (ax == (uint64_t) ax)31return x < 0 ? -0.0l : 0.0l;3233return sinl (x * M_PIl);34}3536long double37arm_math_cospil (long double x)38{39/* cos(inf) should return nan, as defined by C23. */40if (isinf (x))41return __math_invalid (x);4243long double ax = fabsl (x);4445if (ax >= 0x1p64)46return 1;4748uint64_t m = (uint64_t) ax;4950/* Integer values of cospi(x) should return +/-1.51The sign depends on if x is odd or even. */52if (m == ax)53return (m & 1) ? -1 : 1;5455/* Values of Integer + 0.5 should always return 0. */56if (ax - 0.5 == m || ax + 0.5 == m)57return 0;5859return cosl (ax * M_PIl);60}6162long double63arm_math_tanpil (long double x)64{65/* inf and x = n + 0.5 for any integral n should return nan. */66if (fabsl (x) >= 0x1p54l)67{68if (isinf (x))69return __math_invalid (x);70return x < 0 ? -0.0l : 0.0l;71}7273long double i = roundl (x);74long double f = x - i;75int64_t m = (int64_t) i;7677if (x == 0)78{79return x;80}81else if (x == i)82{83if (x < 0)84{85return m & 1 ? 0.0l : -0.0l;86}87else88{89return m & 1 ? -0.0l : 0.0l;90}91}92else if (fabsl (f) == 0.5l)93{94if (x < 0)95{96return m & 1 ? -1.0l / 0.0l : 1.0l / 0.0l;97}98else99{100return m & 1 ? 1.0l / 0.0l : -1.0l / 0.0l;101}102}103104return tanl (f * M_PIl);105}106107108