1 2 /******************************************************************************* 3 MIT License 4 ----------- 5 6 Copyright (c) 2002-2019 Advanced Micro Devices, Inc. 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy 9 of this Software and associated documentaon files (the "Software"), to deal 10 in the Software without restriction, including without limitation the rights 11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 copies of the Software, and to permit persons to whom the Software is 13 furnished to do so, subject to the following conditions: 14 15 The above copyright notice and this permission notice shall be included in 16 all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 THE SOFTWARE. 25 *******************************************************************************/ 26 27 #include <fpieee.h> 28 #include <excpt.h> 29 #include <float.h> 30 #include <math.h> 31 #include <errno.h> 32 33 #include "libm_new.h" 34 35 double _sincos_special(double x, char *name, unsigned int operation) 36 { 37 UT64 xu; 38 unsigned int is_snan; 39 40 xu.f64 = x; 41 42 if((xu.u64 & INF_POS_64) == INF_POS_64) 43 { 44 // x is Inf or NaN 45 if((xu.u64 & MANTISSA_MASK_64) == 0x0) 46 { 47 // x is Inf 48 xu.u64 = IND_64; 49 _handle_error(name, operation, xu.u64, _DOMAIN, AMD_F_INVALID, EDOM, x, 0, 1); 50 } 51 else 52 { 53 // x is NaN 54 is_snan = (((xu.u64 & QNAN_MASK_64) == QNAN_MASK_64) ? 0 : 1); 55 if(is_snan) 56 { 57 xu.u64 |= QNAN_MASK_64; 58 } 59 _handle_error(name, operation, xu.u64, _DOMAIN, 0, EDOM, x, 0, 1); 60 } 61 } 62 63 return xu.f64; 64 } 65 66 float _sincosf_special(float x, char *name, unsigned int operation) 67 { 68 UT64 xu; 69 unsigned int is_snan; 70 71 xu.u64 = 0; 72 xu.f32[0] = x; 73 74 if((xu.u32[0] & INF_POS_32) == INF_POS_32) 75 { 76 // x is Inf or NaN 77 if((xu.u32[0] & MANTISSA_MASK_32) == 0x0) 78 { 79 // x is Inf 80 xu.u32[0] = IND_32; 81 _handle_errorf(name, operation, xu.u64, _DOMAIN, AMD_F_INVALID, EDOM, x, 0, 1); 82 } 83 else 84 { 85 // x is NaN 86 is_snan = (((xu.u32[0] & QNAN_MASK_32) == QNAN_MASK_32) ? 0 : 1); 87 if(is_snan) 88 { 89 xu.u32[0] |= QNAN_SET_32; 90 _handle_errorf(name, operation, xu.u64, _DOMAIN, AMD_F_INVALID, EDOM, x, 0, 1); 91 } 92 else 93 { 94 _handle_errorf(name, operation, xu.u64, _DOMAIN, 0, EDOM, x, 0, 1); 95 } 96 } 97 } 98 99 return xu.f32[0]; 100 } 101 102 float _sinf_special(float x) 103 { 104 return _sincosf_special(x, "sinf", _FpCodeSin); 105 } 106 107 double _sin_special(double x) 108 { 109 return _sincos_special(x, "sin", _FpCodeSin); 110 } 111 112 float _cosf_special(float x) 113 { 114 return _sincosf_special(x, "cosf", _FpCodeCos); 115 } 116 117 double _cos_special(double x) 118 { 119 return _sincos_special(x, "cos", _FpCodeCos); 120 } 121 122 double _tan_special(double x) 123 { 124 return _sincos_special(x, "tan",_FpCodeTan); 125 } 126 127 float _tanf_special(float x) 128 { 129 return _sincosf_special(x, "tanf",_FpCodeTan); 130 } 131