2011-05-05 57 views
2

我需要在Visual C++ 32位上使用函數_nextafterf來計算ULP中的某些結果與參考函數的距離。__extafterfter在Visual c + +

C99爲float和double提供nextafterf和nextafter,但Visual C++不支持這些函數。但是,Visual C++ 2010支持_nextafterf和nextafter,但只支持64位...使用32位模型只_nextafter支持並從...

有沒有辦法讓_nextafterf在Visual Studio上工作也許最多Visual C++ 2005?

感謝, 克里斯托夫

+0

不知道C++。我聽說Visual Studio C編譯器不是C99編譯器。因此,如果您需要C99功能,請切換編譯器(或者向您的編譯器製造商施加壓力,在下一個版本中包含您需要的功能)。 – pmg 2011-05-05 13:35:47

回答

1
+0

謝謝!這太棒了! – Christophe 2011-05-05 14:26:32

+1

很抱歉,Google代碼搜索不再存在。這個答案不再有太大的幫助。 – cgmb 2012-06-06 20:45:45

+0

@ Slavik81 - 您可以使用code.ohloh.net(以前的koders.com)。我唯一的抱怨是,你必須複製並粘貼到一個項目的URL。 http://code.ohloh.net/search?s=nextafterf.c導致https://github.com/cloudius-systems/osv/blob/master/libc/math/nextafterf.c(並且該目錄包含一個很多其他數學函數)。從提交信息看來,該文件來自使用MIT許可的musl:http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT – Mark 2013-09-23 16:01:34

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

工作?