2

我需要在 Visual C++ 32 位上使用函数 _nextafterf 来计算 ULP 中某些结果与参考函数相比的距离。

C99 为 float 和 double 提供了 nextafterf 和 nextafter,但 Visual C++ 不支持这些函数。但是,Visual C++ 2010 支持 _nextafterf 和 nextafter from 但仅支持 64 位... 对于 32 位模型,仅支持 _nextafter 和 from ...

有没有办法让 _nextafterf 在 Visual Studio 上工作到 Visual C++ 2005?

谢谢,克里斯托夫

4

3 回答 3

3

nextafterBoost.Math 中有一个模板化的等价物,请参阅Find the Next Representable Value in a specific Direction (nextafter)

C99 函数必须使用后缀 f 和 l 来区分 float 和 long double 版本。C++ 使用模板机制。

于 2011-05-05T13:35:14.150 回答
1

你总是可以实现它...

https://www.google.com/search?q=libm%2Fsrc%2Fs_nextafterf.c

于 2011-05-05T13:31:18.643 回答
0

在这里找到了一个代码:

/*
 *  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

工作?

于 2015-04-28T01:39:22.217 回答