mirror of
https://github.com/reactos/reactos.git
synced 2024-11-23 19:43:31 +08:00
[CRT] Make _controlfp_s portable
This commit is contained in:
parent
a17dd3a7a9
commit
994d5e0ad1
31
sdk/lib/crt/float/_controlfp_s.c
Normal file
31
sdk/lib/crt/float/_controlfp_s.c
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* PROJECT: ReactOS CRT library
|
||||
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
||||
* PURPOSE: Implementation of _controlfp_s (adapted from wine msvcrt/math.c)
|
||||
* COPYRIGHT: Copyright 2000 Jon Griffiths
|
||||
* Copyright 2010 Piotr Caban
|
||||
* Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
#include <float.h>
|
||||
|
||||
#ifdef _M_ARM
|
||||
#define INVALID_MASK ~(_MCW_EM | _MCW_RC | _MCW_DN)
|
||||
#else
|
||||
#define INVALID_MASK ~(_MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC | _MCW_DN)
|
||||
#endif
|
||||
|
||||
int CDECL _controlfp_s(unsigned int* cur, unsigned int newval, unsigned int mask)
|
||||
{
|
||||
unsigned int val;
|
||||
|
||||
if (!MSVCRT_CHECK_PMT((newval & mask & INVALID_MASK) == 0))
|
||||
{
|
||||
if (cur) *cur = _controlfp(0, 0); /* retrieve it anyway */
|
||||
return EINVAL;
|
||||
}
|
||||
val = _controlfp(newval, mask);
|
||||
if (cur) *cur = val;
|
||||
return 0;
|
||||
}
|
@ -68,16 +68,3 @@ unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
|
||||
return flags;
|
||||
}
|
||||
|
||||
int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
|
||||
{
|
||||
unsigned int val;
|
||||
|
||||
if (!MSVCRT_CHECK_PMT( !(newval & mask & ~(_MCW_EM | _MCW_RC | _MCW_DN)) ))
|
||||
{
|
||||
if (cur) *cur = _controlfp(0, 0); /* retrieve it anyway */
|
||||
return EINVAL;
|
||||
}
|
||||
val = _controlfp(newval, mask);
|
||||
if (cur) *cur = val;
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ list(APPEND LIBCNTPR_FLOAT_SOURCE
|
||||
list(APPEND CRT_FLOAT_SOURCE
|
||||
${LIBCNTPR_FLOAT_SOURCE}
|
||||
float/chgsign.c
|
||||
float/_controlfp_s.c
|
||||
float/copysign.c
|
||||
float/fpclass.c
|
||||
float/fpecode.c
|
||||
|
@ -113,25 +113,3 @@ unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* _controlfp_s (MSVCRT.@)
|
||||
*/
|
||||
int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
|
||||
{
|
||||
#ifdef __i386__
|
||||
unsigned int val;
|
||||
|
||||
if (!MSVCRT_CHECK_PMT( !(newval & mask & ~(_MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC | _MCW_DN))))
|
||||
{
|
||||
if (cur) *cur = _controlfp( 0, 0 ); /* retrieve it anyway */
|
||||
return EINVAL;
|
||||
}
|
||||
val = _controlfp( newval, mask );
|
||||
if (cur) *cur = val;
|
||||
return 0;
|
||||
#else
|
||||
FIXME(":Not Implemented!\n");
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user