_nextafterf on Visual C++
I need to use the function _nextafterf on Visual C++ 32 bit to compute the distance in ULP of some results compare to reference func开发者_Python百科tions.
C99 provides nextafterf and nextafter for float and double but these functions are not supported by Visual C++. However, Visual C++ 2010 supports _nextafterf and nextafter from but only in 64 bits... With the 32 bits model only _nextafter is support and from ...
Is there a way to get _nextafterf working on Visual Studio maybe up to Visual C++ 2005?
Thanks, Christophe
There is a templatized equivalent nextafter
in Boost.Math, see Finding the Next Representable Value in a Specific Direction (nextafter).
The C99 functions must use suffixes f and l to distinguish float and long double versions. C++ uses the template mechanism instead.
You can always implement it...
https://www.google.com/search?q=libm%2Fsrc%2Fs_nextafterf.c
found a code here:
/*
* nextafterf.c
* cLibm
*
* Created by Ian Ollmann on 6/14/07.
* Copyright 2007 Apple Inc. All rights reserved.
*
*/
...
float nextafterf( float x, float y )
{
union{ float f; uint32_t u;} ux = { x };
uint32_t step = 1;
if( y != y || x != x)
return x + y;
if( y <= x ) // a subtraction here would risk Inf-Inf
{
if( y == x )
return y; //make sure sign of 0 is correct
step = -1;
}
//correct for the sign
int32_t signMask = (int32_t) ux.u >> 31;
step = (step ^ signMask) - signMask;
uint32_t absux = ux.u & 0x7fffffffU;
if( absux == 0 ) // zero
{
ux.f = y;
ux.u = (ux.u & 0x80000000U) + 1U;
return ux.f;
}
ux.u += step;
return ux.f;
}
http://www.opensource.apple.com/source/Libm/Libm-315/Source/ARM/nextafterf.c
work?
精彩评论