The difference between max and fmax (Cross platform compiling)
In Xcode, this compiles fine:
float falloff = fmin(1.0, fmax(0.0, distanceSqrd/cRadius));
However in Visual Studio 2010 it errors, and I have to use max instead of fmax.
distanceSqrd and cRadius are also both floats.
It’s the only part of my code that doesn’t seamlessly cross compile…
Any ideas why?
- C++ not showing cout in Xcode console but runs perfectly in Terminal
- subnormal IEEE 754 floating point numbers support on iOS ARM devices (iPhone 4)
- Why we used double and triple pointer in objective-C or C language?
- Why does rand() % 7 always return 0?
- A Guide for Creating your own Library for Cocoa(touch) development
- What happens to a .h file that is not included in a target during compilation?
Solutions Collect From Internet About “The difference between max and fmax (Cross platform compiling)”
std::fmin from the
<cmath> header (or
<math.h>) are a C++11 feature and along with many other new mathematical functions one that Visual Studio 2010 doesn’t support yet (neither does 2012). So for portability it is advisable to replace them by
The actual difference is, that
fmax are mathematical functions working on floating point numbers and originating from
C99 (and might be implemented intrisically by actual specialized CPU instructions where possible), while
max are general algorithms usable on any type supporting
< (and are probably just a simple
(b<a) ? b : a instead of a floating point instruction, though an implementation could even do that with a specialization of
max, but I doubt this).
They also behave slightly different for special floating point arguments. While it is not entirely specified how
max will respond to
NaNs, I think (though from the above definition they should always return the 1st operand),
fmax are clearly specified to always return the other (non-
NaN) argument when one is
NaN, if the implementation is IEEE 754 conformant (which any modern PC implementation usually is).
- iOS – Keep the old sqlite database while updating to new version
- Finding Path/Route Between two points on MapKit in iPhone
- get url event on app open in objective c (Mac OSX)
- ios interface iVar vs Property
- Linker error with libpng under MacOSX
- XCode 7: xcdatamodeld doesn’t exist
- Ambiguous use of ‘subscript’ error when importing AVFoundation
- CLLocation returning negative speed
- Cannot call value of non-function type 'Any?!' :- Firebase,Swift3
- How to convert server response date to local timezone?
- Reachability takes too long to fail when connected to WIFI without internet
- How to create percentage of total width using autolayout?
- Reading from txt file in Swift 3
- Modal transition style like in Mail app
- iOS7 and iOS8: how to detect when user said No to a request for push notifications