xref: /reactos/sdk/lib/crt/math/libm_sse2/exp_special.c (revision 09dde2cf)
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 // y = expf(x)
36 // y = exp(x)
37 
38 // these codes and the ones in the related .asm files have to match
39 #define EXP_X_NAN       1
40 #define EXP_Y_ZERO      2
41 #define EXP_Y_INF       3
42 
43 float _expf_special(float x, float y, U32 code)
44 {
45     switch(code)
46     {
47     case EXP_X_NAN:
48         {
49             UT64 ym; ym.u64 = 0; ym.f32[0] = y;
50             _handle_errorf("expf", _FpCodeExp, ym.u64, _DOMAIN, 0, EDOM, x, 0.0, 1);
51         }
52         break;
53 
54     case EXP_Y_ZERO:
55         {
56             UT64 ym; ym.u64 = 0; ym.f32[0] = y;
57             _handle_errorf("expf", _FpCodeExp, ym.u64, _UNDERFLOW, AMD_F_INEXACT|AMD_F_UNDERFLOW, ERANGE, x, 0.0, 1);
58         }
59         break;
60 
61     case EXP_Y_INF:
62         {
63             UT64 ym; ym.u64 = 0; ym.f32[0] = y;
64             _handle_errorf("expf", _FpCodeExp, ym.u64, _OVERFLOW, AMD_F_INEXACT|AMD_F_OVERFLOW, ERANGE, x, 0.0, 1);
65 
66         }
67         break;
68     }
69 
70     return y;
71 }
72 
73 double _exp_special(double x, double y, U32 code)
74 {
75     switch(code)
76     {
77     case EXP_X_NAN:
78         {
79             UT64 ym; ym.f64 = y;
80             _handle_error("exp", _FpCodeExp, ym.u64, _DOMAIN, 0, EDOM, x, 0.0, 1);
81         }
82         break;
83 
84     case EXP_Y_ZERO:
85         {
86             UT64 ym; ym.f64 = y;
87             _handle_error("exp", _FpCodeExp, ym.u64, _UNDERFLOW, AMD_F_INEXACT|AMD_F_UNDERFLOW, ERANGE, x, 0.0, 1);
88         }
89         break;
90 
91     case EXP_Y_INF:
92         {
93             UT64 ym; ym.f64 = y;
94             _handle_error("exp", _FpCodeExp, ym.u64, _OVERFLOW, AMD_F_INEXACT|AMD_F_OVERFLOW, ERANGE, x, 0.0, 1);
95         }
96         break;
97     }
98 
99 
100     return y;
101 }
102