在C ++中获取最小NEGATIVE浮点值 [英] Obtain minimum NEGATIVE float value in C++

查看:120
本文介绍了在C ++中获取最小NEGATIVE浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看着 std :: numeric_limits< float> :: min / max(),但它看起来'min()'返回最小的绝对值, 最低值。是否安全使用



-std :: numeric_limits< float> :: max() IEEE 754浮点数使用一个符号位进行签名(而不是类似于下面这样的操作):

二进制补码),所以如果你确定你的编译器/平台使用该表示(非常常见),那么你可以使用 -std :: numeric_limits< float> :: max()您怀疑。


I was looking at std::numeric_limits<float>::min/max() but it appears 'min()' returns the smallest absolute value, not the lowest value. Is it safe to use

-std::numeric_limits<float>::max(), i.e is float symmetric in min/max limits?

解决方案

IEEE 754 floating point numbers use a sign bit for signed-ness (rather than something like twos complement), so if you're sure that your compiler/platform uses that representation (very common) then you can use -std::numeric_limits<float>::max() as you suspected.

这篇关于在C ++中获取最小NEGATIVE浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆