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?
- Objective-C++ and .cpp files in Xcode
- Qt: How to create a .mp4 from a collection of QOpenGLFramebufferObjects or QImages or Glunit textures
- How to call C from Swift?
- Adding Qt to Xcode project?
- Use of external C++ headers in Objective-C
- OpenCv 2.4.3: can't find imread and SurfFeatureDetector::detect
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).
- Top aligned UILabel, make text stick to top of label view -ios
- Why the Missing 64-bit support happened when upload to the iTunes connect?
- UINavigationController-Alike for Desktop-Cocoa?
- Update storyboard constraint using code
- What is the preferred way of getting value in swift, var vs. func?
- Upload an image with AFNetworking 2.0
- Using Core Location in Apple WatchKit
- How do I get a background location update every n minutes in my iOS application?
- Xcode storyboard issue with auto layout not allowing me to move an objects origin.y value
- Is it legal to use the well-known free memory code in ipad/iphone app?
- NSMutableString appendString generates SIGABRT Error
- Mac App Store invalid signature issues
- Is it possible to disable Swift documentation in Xcode?
- How to put Google Map in a custom UIView
- NSButton Multiple clicks