msvcrt: Use __scalbn helper in ldexp implementation.
[wine.git] / dlls / msvcrt / unixlib.c
blob9afa0f4155789e7561cc0dd7aae888ca36c1f380
1 /*
2 * MSVCRT Unix interface
4 * Copyright 2020 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #if 0
22 #pragma makedep unix
23 #endif
25 #include "config.h"
26 #include "wine/port.h"
28 #include <stdio.h>
29 #include <stdarg.h>
30 #define __USE_ISOC9X 1
31 #define __USE_ISOC99 1
32 #include <math.h>
33 #ifdef HAVE_IEEEFP_H
34 #include <ieeefp.h>
35 #endif
37 #include "ntstatus.h"
38 #define WIN32_NO_STATUS
39 #include "winternl.h"
40 #include "unixlib.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
45 /*********************************************************************
46 * exp
48 static double CDECL unix_exp( double x )
50 return exp( x );
53 /*********************************************************************
54 * expf
56 static float CDECL unix_expf( float x )
58 return expf( x );
61 /*********************************************************************
62 * exp2
64 static double CDECL unix_exp2( double x )
66 #ifdef HAVE_EXP2
67 return exp2(x);
68 #else
69 return pow(2, x);
70 #endif
73 /*********************************************************************
74 * exp2f
76 static float CDECL unix_exp2f( float x )
78 #ifdef HAVE_EXP2F
79 return exp2f(x);
80 #else
81 return unix_exp2(x);
82 #endif
85 /*********************************************************************
86 * fma
88 static double CDECL unix_fma( double x, double y, double z )
90 #ifdef HAVE_FMA
91 return fma(x, y, z);
92 #else
93 return x * y + z;
94 #endif
97 /*********************************************************************
98 * fmaf
100 static float CDECL unix_fmaf( float x, float y, float z )
102 #ifdef HAVE_FMAF
103 return fmaf(x, y, z);
104 #else
105 return x * y + z;
106 #endif
109 /*********************************************************************
110 * frexp
112 static double CDECL unix_frexp( double x, int *exp )
114 return frexp( x, exp );
117 /*********************************************************************
118 * frexpf
120 static float CDECL unix_frexpf( float x, int *exp )
122 return frexpf( x, exp );
125 /*********************************************************************
126 * hypot
128 static double CDECL unix_hypot(double x, double y)
130 return hypot( x, y );
133 /*********************************************************************
134 * hypotf
136 static float CDECL unix_hypotf(float x, float y)
138 return hypotf( x, y );
141 /*********************************************************************
142 * lgamma
144 static double CDECL unix_lgamma(double x)
146 #ifdef HAVE_LGAMMA
147 return lgamma(x);
148 #else
149 FIXME( "not implemented\n" );
150 return 0;
151 #endif
154 /*********************************************************************
155 * lgammaf
157 static float CDECL unix_lgammaf(float x)
159 #ifdef HAVE_LGAMMAF
160 return lgammaf(x);
161 #else
162 FIXME( "not implemented\n" );
163 return 0;
164 #endif
167 /*********************************************************************
168 * log
170 static double CDECL unix_log( double x )
172 return log( x );
175 /*********************************************************************
176 * logf
178 static float CDECL unix_logf( float x )
180 return logf( x );
183 /*********************************************************************
184 * log10
186 static double CDECL unix_log10( double x )
188 return log10( x );
191 /*********************************************************************
192 * log10f
194 static float CDECL unix_log10f( float x )
196 return log10f( x );
199 /*********************************************************************
200 * log1p
202 static double CDECL unix_log1p(double x)
204 #ifdef HAVE_LOG1P
205 return log1p(x);
206 #else
207 return log(1 + x);
208 #endif
211 /*********************************************************************
212 * log1pf
214 static float CDECL unix_log1pf(float x)
216 #ifdef HAVE_LOG1PF
217 return log1pf(x);
218 #else
219 return log(1 + x);
220 #endif
223 /*********************************************************************
224 * log2
226 static double CDECL unix_log2(double x)
228 #ifdef HAVE_LOG2
229 return log2(x);
230 #else
231 return log(x) / log(2);
232 #endif
235 /*********************************************************************
236 * log2f
238 static float CDECL unix_log2f(float x)
240 #ifdef HAVE_LOG2F
241 return log2f(x);
242 #else
243 return unix_log2(x);
244 #endif
247 /*********************************************************************
248 * pow
250 static double CDECL unix_pow( double x, double y )
252 return pow( x, y );
255 /*********************************************************************
256 * powf
258 static float CDECL unix_powf( float x, float y )
260 return powf( x, y );
263 /*********************************************************************
264 * tgamma
266 static double CDECL unix_tgamma(double x)
268 #ifdef HAVE_TGAMMA
269 return tgamma(x);
270 #else
271 FIXME( "not implemented\n" );
272 return 0;
273 #endif
276 /*********************************************************************
277 * tgammaf
279 static float CDECL unix_tgammaf(float x)
281 #ifdef HAVE_TGAMMAF
282 return tgammaf(x);
283 #else
284 FIXME( "not implemented\n" );
285 return 0;
286 #endif
289 static const struct unix_funcs funcs =
291 unix_exp,
292 unix_expf,
293 unix_exp2,
294 unix_exp2f,
295 unix_fma,
296 unix_fmaf,
297 unix_frexp,
298 unix_frexpf,
299 unix_hypot,
300 unix_hypotf,
301 unix_lgamma,
302 unix_lgammaf,
303 unix_log,
304 unix_logf,
305 unix_log10,
306 unix_log10f,
307 unix_log1p,
308 unix_log1pf,
309 unix_log2,
310 unix_log2f,
311 unix_pow,
312 unix_powf,
313 unix_tgamma,
314 unix_tgammaf,
317 NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
319 if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS;
320 TRACE( "\n" );
321 *(const struct unix_funcs **)ptr_out = &funcs;
322 return STATUS_SUCCESS;