Added C# implementation of System.Math.ScaleB and System.MathF.ScaleB… (#42476)
[platform/upstream/dotnet/runtime.git] / src / coreclr / classlibnative / float / floatsingle.cpp
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 //
4 // File: FloatSingle.cpp
5 //
6
7 #include <common.h>
8
9 #include "floatsingle.h"
10
11 // Windows x86 and Windows ARM/ARM64 may not define _isnanf() or _copysignf() but they do
12 // define _isnan() and _copysign(). We will redirect the macros to these other functions if
13 // the macro is not defined for the platform. This has the side effect of a possible implicit
14 // upcasting for arguments passed in and an explicit downcasting for the _copysign() call.
15 #if (defined(TARGET_X86) || defined(TARGET_ARM) || defined(TARGET_ARM64)) && !defined(TARGET_UNIX)
16
17 #if !defined(_copysignf)
18 #define _copysignf   (float)_copysign
19 #endif
20
21 #endif
22
23 // The default compilation mode is /fp:precise, which disables floating-point intrinsics. This
24 // default compilation mode has previously caused performance regressions in floating-point code.
25 // We enable /fp:fast semantics for the majority of the math functions, as it will speed up performance
26 // and is really unlikely to cause any other code regressions.
27
28 ////////////////////////////////////////////////////////////////////////////////////
29 ////////////////////////////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////////////////////////////
31 ///
32 ///                         beginning of /fp:fast scope
33 ///
34 ////////////////////////////////////////////////////////////////////////////////////
35 ////////////////////////////////////////////////////////////////////////////////////
36 ////////////////////////////////////////////////////////////////////////////////////
37
38 #ifdef _MSC_VER
39 #pragma float_control(push)
40 #pragma float_control(precise, off)
41 #endif
42
43 /*=====================================Abs=====================================
44 **
45 ==============================================================================*/
46 FCIMPL1_V(float, COMSingle::Abs, float x)
47     FCALL_CONTRACT;
48
49     return (float)fabsf(x);
50 FCIMPLEND
51
52 /*=====================================Acos=====================================
53 **
54 ==============================================================================*/
55 FCIMPL1_V(float, COMSingle::Acos, float x)
56     FCALL_CONTRACT;
57
58     return (float)acosf(x);
59 FCIMPLEND
60
61 /*=====================================Acosh====================================
62 **
63 ==============================================================================*/
64 FCIMPL1_V(float, COMSingle::Acosh, float x)
65     FCALL_CONTRACT;
66
67     return (float)acoshf(x);
68 FCIMPLEND
69
70 /*=====================================Asin=====================================
71 **
72 ==============================================================================*/
73 FCIMPL1_V(float, COMSingle::Asin, float x)
74     FCALL_CONTRACT;
75
76     return (float)asinf(x);
77 FCIMPLEND
78
79 /*=====================================Asinh====================================
80 **
81 ==============================================================================*/
82 FCIMPL1_V(float, COMSingle::Asinh, float x)
83     FCALL_CONTRACT;
84
85     return (float)asinhf(x);
86 FCIMPLEND
87
88 /*=====================================Atan=====================================
89 **
90 ==============================================================================*/
91 FCIMPL1_V(float, COMSingle::Atan, float x)
92     FCALL_CONTRACT;
93
94     return (float)atanf(x);
95 FCIMPLEND
96
97 /*=====================================Atanh====================================
98 **
99 ==============================================================================*/
100 FCIMPL1_V(float, COMSingle::Atanh, float x)
101     FCALL_CONTRACT;
102
103     return (float)atanhf(x);
104 FCIMPLEND
105
106 /*=====================================Atan2====================================
107 **
108 ==============================================================================*/
109 FCIMPL2_VV(float, COMSingle::Atan2, float y, float x)
110     FCALL_CONTRACT;
111
112     return (float)atan2f(y, x);
113 FCIMPLEND
114
115 /*====================================Cbrt======================================
116 **
117 ==============================================================================*/
118 FCIMPL1_V(float, COMSingle::Cbrt, float x)
119     FCALL_CONTRACT;
120
121     return (float)cbrtf(x);
122 FCIMPLEND
123
124 #if defined(_MSC_VER) && defined(TARGET_AMD64)
125 // The /fp:fast form of `ceilf` for AMD64 does not correctly handle: `-1.0 < value <= -0.0`
126 // https://github.com/dotnet/runtime/issues/11003
127 #pragma float_control(push)
128 #pragma float_control(precise, on)
129 #endif
130
131 /*====================================Ceil======================================
132 **
133 ==============================================================================*/
134 FCIMPL1_V(float, COMSingle::Ceil, float x)
135     FCALL_CONTRACT;
136
137     return (float)ceilf(x);
138 FCIMPLEND
139
140 #if defined(_MSC_VER) && defined(TARGET_AMD64)
141 #pragma float_control(pop)
142 #endif
143
144 /*=====================================Cos======================================
145 **
146 ==============================================================================*/
147 FCIMPL1_V(float, COMSingle::Cos, float x)
148     FCALL_CONTRACT;
149
150     return (float)cosf(x);
151 FCIMPLEND
152
153 /*=====================================Cosh=====================================
154 **
155 ==============================================================================*/
156 FCIMPL1_V(float, COMSingle::Cosh, float x)
157     FCALL_CONTRACT;
158
159     return (float)coshf(x);
160 FCIMPLEND
161
162 /*=====================================Exp======================================
163 **
164 ==============================================================================*/
165 FCIMPL1_V(float, COMSingle::Exp, float x)
166     FCALL_CONTRACT;
167
168     return (float)expf(x);
169 FCIMPLEND
170
171 /*====================================Floor=====================================
172 **
173 ==============================================================================*/
174 FCIMPL1_V(float, COMSingle::Floor, float x)
175     FCALL_CONTRACT;
176
177     return (float)floorf(x);
178 FCIMPLEND
179
180 /*=====================================FMod=====================================
181 **
182 ==============================================================================*/
183 FCIMPL2_VV(float, COMSingle::FMod, float x, float y)
184     FCALL_CONTRACT;
185
186     return (float)fmodf(x, y);
187 FCIMPLEND
188
189 /*=====================================FusedMultiplyAdd==========================
190 **
191 ==============================================================================*/
192 FCIMPL3_VVV(float, COMSingle::FusedMultiplyAdd, float x, float y, float z)
193     FCALL_CONTRACT;
194
195     return (float)fmaf(x, y, z);
196 FCIMPLEND
197
198 /*=====================================Ilog2====================================
199 **
200 ==============================================================================*/
201 FCIMPL1_V(int, COMSingle::ILogB, float x)
202     FCALL_CONTRACT;
203
204     return (int)ilogbf(x);
205 FCIMPLEND
206
207 /*=====================================Log======================================
208 **
209 ==============================================================================*/
210 FCIMPL1_V(float, COMSingle::Log, float x)
211     FCALL_CONTRACT;
212
213     return (float)logf(x);
214 FCIMPLEND
215
216 /*=====================================Log2=====================================
217 **
218 ==============================================================================*/
219 FCIMPL1_V(float, COMSingle::Log2, float x)
220     FCALL_CONTRACT;
221
222     return (float)log2f(x);
223 FCIMPLEND
224
225 /*====================================Log10=====================================
226 **
227 ==============================================================================*/
228 FCIMPL1_V(float, COMSingle::Log10, float x)
229     FCALL_CONTRACT;
230
231     return (float)log10f(x);
232 FCIMPLEND
233
234 /*=====================================ModF=====================================
235 **
236 ==============================================================================*/
237 FCIMPL2_VI(float, COMSingle::ModF, float x, float* intptr)
238     FCALL_CONTRACT;
239
240     return (float)modff(x, intptr);
241 FCIMPLEND
242
243 /*=====================================Pow======================================
244 **
245 ==============================================================================*/
246 FCIMPL2_VV(float, COMSingle::Pow, float x, float y)
247     FCALL_CONTRACT;
248
249     return (float)powf(x, y);
250 FCIMPLEND
251
252 /*=====================================Sin======================================
253 **
254 ==============================================================================*/
255 FCIMPL1_V(float, COMSingle::Sin, float x)
256     FCALL_CONTRACT;
257
258     return (float)sinf(x);
259 FCIMPLEND
260
261 /*====================================SinCos====================================
262 **
263 ==============================================================================*/
264 FCIMPL3_VII(void, COMSingle::SinCos, float x, float* pSin, float* pCos)
265     FCALL_CONTRACT;
266
267 #ifdef _MSC_VER
268     *pSin = sinf(x);
269     *pCos = cosf(x);
270 #else
271     sincosf(x, pSin, pCos);
272 #endif
273
274 FCIMPLEND
275
276 /*=====================================Sinh=====================================
277 **
278 ==============================================================================*/
279 FCIMPL1_V(float, COMSingle::Sinh, float x)
280     FCALL_CONTRACT;
281
282     return (float)sinhf(x);
283 FCIMPLEND
284
285 /*=====================================Sqrt=====================================
286 **
287 ==============================================================================*/
288 FCIMPL1_V(float, COMSingle::Sqrt, float x)
289     FCALL_CONTRACT;
290
291     return (float)sqrtf(x);
292 FCIMPLEND
293
294 /*=====================================Tan======================================
295 **
296 ==============================================================================*/
297 FCIMPL1_V(float, COMSingle::Tan, float x)
298     FCALL_CONTRACT;
299
300     return (float)tanf(x);
301 FCIMPLEND
302
303 /*=====================================Tanh=====================================
304 **
305 ==============================================================================*/
306 FCIMPL1_V(float, COMSingle::Tanh, float x)
307     FCALL_CONTRACT;
308
309     return (float)tanhf(x);
310 FCIMPLEND
311
312 #ifdef _MSC_VER
313 #pragma float_control(pop)
314 #endif
315
316 ////////////////////////////////////////////////////////////////////////////////////
317 ////////////////////////////////////////////////////////////////////////////////////
318 ////////////////////////////////////////////////////////////////////////////////////
319 ///
320 ///                         End of /fp:fast scope
321 ///
322 ////////////////////////////////////////////////////////////////////////////////////
323 ////////////////////////////////////////////////////////////////////////////////////
324 ////////////////////////////////////////////////////////////////////////////////////