2019-03-01 16:49:03 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS CRT
|
|
|
|
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
|
|
|
|
* PURPOSE: Implements the ldexp CRT function for IA-32 with Windows-compatible error codes.
|
|
|
|
* COPYRIGHT: Copyright 2010 Timo Kreuzer (timo.kreuzer@reactos.org)
|
|
|
|
* Copyright 2011 Pierre Schweitzer (pierre@reactos.org)
|
|
|
|
* Copyright 2019 Colin Finck (colin@reactos.org)
|
|
|
|
*/
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2011-11-19 19:01:58 +00:00
|
|
|
#include <precomp.h>
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2010-05-31 01:50:09 +00:00
|
|
|
double ldexp (double value, int exp)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2019-03-01 16:49:03 +00:00
|
|
|
#ifdef __GNUC__
|
2010-05-31 01:50:09 +00:00
|
|
|
register double result;
|
2011-11-19 22:08:39 +00:00
|
|
|
#endif
|
2011-11-19 19:01:58 +00:00
|
|
|
|
|
|
|
/* Check for value correctness
|
|
|
|
* and set errno if required
|
|
|
|
*/
|
|
|
|
if (_isnan(value))
|
|
|
|
{
|
|
|
|
errno = EDOM;
|
|
|
|
}
|
|
|
|
|
2007-03-14 20:24:57 +00:00
|
|
|
#ifdef __GNUC__
|
2010-05-31 01:50:09 +00:00
|
|
|
asm ("fscale"
|
2011-11-19 19:01:58 +00:00
|
|
|
: "=t" (result)
|
2010-05-31 01:50:09 +00:00
|
|
|
: "0" (value), "u" ((double)exp)
|
|
|
|
: "1");
|
2019-03-01 16:49:03 +00:00
|
|
|
return result;
|
2010-05-31 01:50:09 +00:00
|
|
|
#else /* !__GNUC__ */
|
2011-11-19 19:01:58 +00:00
|
|
|
__asm
|
|
|
|
{
|
2019-03-01 16:49:03 +00:00
|
|
|
fild exp
|
2011-11-19 19:01:58 +00:00
|
|
|
fld value
|
|
|
|
fscale
|
2019-03-01 16:49:03 +00:00
|
|
|
fstp st(1)
|
2011-11-19 19:01:58 +00:00
|
|
|
}
|
2019-03-01 16:49:03 +00:00
|
|
|
|
|
|
|
/* "fstp st(1)" has copied st(0) to st(1), then popped the FPU stack,
|
|
|
|
* so that the value is again in st(0) now. Effectively, we have reduced
|
|
|
|
* the FPU stack by one element while preserving st(0).
|
|
|
|
* st(0) is also the register used for returning a double value. */
|
2010-05-31 01:50:09 +00:00
|
|
|
#endif /* !__GNUC__ */
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|