ReactOS 0.4.15-dev-8614-gbc76250
sincos_special.c
Go to the documentation of this file.
1
2/*******************************************************************************
3MIT License
4-----------
5
6Copyright (c) 2002-2019 Advanced Micro Devices, Inc.
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this Software and associated documentaon files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24THE 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
35double _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;
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
66float _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;
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;
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
102float _sinf_special(float x)
103{
104 return _sincosf_special(x, "sinf", _FpCodeSin);
105}
106
107double _sin_special(double x)
108{
109 return _sincos_special(x, "sin", _FpCodeSin);
110}
111
112float _cosf_special(float x)
113{
114 return _sincosf_special(x, "cosf", _FpCodeCos);
115}
116
117double _cos_special(double x)
118{
119 return _sincos_special(x, "cos", _FpCodeCos);
120}
121
122double _tan_special(double x)
123{
124 return _sincos_special(x, "tan",_FpCodeTan);
125}
126
127float _tanf_special(float x)
128{
129 return _sincosf_special(x, "tanf",_FpCodeTan);
130}
double __cdecl _handle_error(char *fname, int opcode, unsigned long long value, int type, int flags, int error, double arg1, double arg2, int nargs)
Handles an error condition.
Definition: _handle_error.c:34
float __cdecl _handle_errorf(char *fname, int opcode, unsigned long long value, int type, int flags, int error, float arg1, float arg2, int nargs)
Definition: _handle_error.c:56
operation
Definition: copy.c:29
#define EDOM
Definition: errno.h:39
@ _FpCodeSin
Definition: fpieee.h:59
@ _FpCodeCos
Definition: fpieee.h:47
@ _FpCodeTan
Definition: fpieee.h:61
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define _DOMAIN
Definition: math.h:39
#define IND_64
Definition: libm_new.h:78
#define IND_32
Definition: libm_new.h:67
#define MANTISSA_MASK_64
Definition: libm_new.h:76
#define INF_POS_32
Definition: libm_new.h:63
#define QNAN_MASK_32
Definition: libm_new.h:61
#define QNAN_SET_32
Definition: libm_new.h:71
#define MANTISSA_MASK_32
Definition: libm_new.h:59
#define AMD_F_INVALID
Definition: libm_new.h:86
#define QNAN_MASK_64
Definition: libm_new.h:79
#define INF_POS_64
Definition: libm_new.h:73
float _cosf_special(float x)
float _sincosf_special(float x, char *name, unsigned int operation)
double _cos_special(double x)
float _sinf_special(float x)
double _sin_special(double x)
double _sincos_special(double x, char *name, unsigned int operation)
double _tan_special(double x)
float _tanf_special(float x)
Definition: name.c:39
Definition: libm_new.h:47
F64 f64
Definition: libm_new.h:48
U32 u32[2]
Definition: libm_new.h:52
U64 u64
Definition: libm_new.h:49
F32 f32[2]
Definition: libm_new.h:51