ReactOS 0.4.15-dev-7834-g00c4b3d
log_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
35// y = log10f(x)
36// y = log10(x)
37// y = logf(x)
38// y = log(x)
39
40// these codes and the ones in the related .asm files have to match
41#define LOG_X_ZERO 1
42#define LOG_X_NEG 2
43#define LOG_X_NAN 3
44
45static float _logf_special_common(float x, float y, U32 code, unsigned int op, char *name)
46{
47 switch(code)
48 {
49 case LOG_X_ZERO:
50 {
51 UT64 ym; ym.u64 = 0; ym.f32[0] = y;
53 }
54 break;
55
56 case LOG_X_NEG:
57 {
58 UT64 ym; ym.u64 = 0; ym.f32[0] = y;
60 }
61 break;
62
63 case LOG_X_NAN:
64 {
65 unsigned int is_snan;
66 UT32 xm; UT64 ym;
67 xm.f32 = x;
68 is_snan = (((xm.u32 & QNAN_MASK_32) == QNAN_SET_32) ? 0 : 1);
69 ym.u64 = 0; ym.f32[0] = y;
70
71 if(is_snan)
72 {
74 }
75 else
76 {
77 _handle_errorf(name, op, ym.u64, _DOMAIN, 0, EDOM, x, 0.0, 1);
78 }
79 }
80 break;
81 }
82
83 return y;
84}
85
86float _logf_special(float x, float y, U32 code)
87{
88 return _logf_special_common(x, y, code, _FpCodeLog, "logf");
89}
90
91float _log10f_special(float x, float y, U32 code)
92{
93 return _logf_special_common(x, y, code, _FpCodeLog10, "log10f");
94}
95
96static double _log_special_common(double x, double y, U32 code, unsigned int op, char *name)
97{
98 switch(code)
99 {
100 case LOG_X_ZERO:
101 {
102 UT64 ym; ym.f64 = y;
104 }
105 break;
106
107 case LOG_X_NEG:
108 {
109 UT64 ym; ym.f64 = y;
111 }
112 break;
113
114 case LOG_X_NAN:
115 {
116 UT64 ym; ym.f64 = y;
117 _handle_error(name, op, ym.u64, _DOMAIN, 0, EDOM, x, 0.0, 1);
118 }
119 break;
120 }
121
122 return y;
123}
124
125double _log_special(double x, double y, U32 code)
126{
127 return _log_special_common(x, y, code, _FpCodeLog, "log");
128}
129
130double _log10_special(double x, double y, U32 code)
131{
132 return _log_special_common(x, y, code, _FpCodeLog10, "log10");
133}
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
#define ERANGE
Definition: acclib.h:92
UINT op
Definition: effect.c:236
#define EDOM
Definition: errno.h:39
@ _FpCodeLog10
Definition: fpieee.h:56
@ _FpCodeLog
Definition: fpieee.h:55
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define _DOMAIN
Definition: math.h:39
#define _SING
Definition: math.h:40
#define AMD_F_DIVBYZERO
Definition: libm_new.h:85
#define QNAN_MASK_32
Definition: libm_new.h:61
#define QNAN_SET_32
Definition: libm_new.h:71
#define AMD_F_INVALID
Definition: libm_new.h:86
#define LOG_X_NEG
Definition: log_special.c:42
double _log10_special(double x, double y, U32 code)
Definition: log_special.c:130
#define LOG_X_NAN
Definition: log_special.c:43
double _log_special(double x, double y, U32 code)
Definition: log_special.c:125
static double _log_special_common(double x, double y, U32 code, unsigned int op, char *name)
Definition: log_special.c:96
float _logf_special(float x, float y, U32 code)
Definition: log_special.c:86
float _log10f_special(float x, float y, U32 code)
Definition: log_special.c:91
#define LOG_X_ZERO
Definition: log_special.c:41
static float _logf_special_common(float x, float y, U32 code, unsigned int op, char *name)
Definition: log_special.c:45
Definition: inflate.c:139
Definition: name.c:39
Definition: libm_new.h:41
F32 f32
Definition: libm_new.h:42
U32 u32
Definition: libm_new.h:43
Definition: libm_new.h:47
F64 f64
Definition: libm_new.h:48
U64 u64
Definition: libm_new.h:49
F32 f32[2]
Definition: libm_new.h:51
unsigned int U32
Definition: xxhash.c:195