(一)What will happen if so ?

Floating-Point Overflow and Underflow 
Suppose the biggest possible float value on your system is about 3.4E38 and you do this:

float toobig = 3.4E38 * 100.0f; 
printf("%e\n", toobig); 
What happens? This is an example of overflow—when a calculation leads to a number too large 
to be expressed. The behavior for this case used to be undefined, but now C specifies that 
toobig gets assigned a special value that stands for infinity and that printf() displays either 
inf or infinity (or some variation on that theme) for the value. 

What about dividing very small numbers? Here the situation is more involved. Recall that a 
float number is stored as an exponent and as a value part, or mantissa. There will be a number 
that has the smallest possible exponent and also the smallest value that still uses all the bits 
available to represent the mantissa. This will be the smallest number that still is represented to 
the full precision available to a float value. Now divide it by 2. Normally, this reduces the 
exponent, but the exponent already is as small as it can get. So, instead, the computer moves 
the bits in the mantissa over, vacating the first position and losing the last binary digit. An 
analogy would be taking a base 10 value with four significant digits, such as 0.1234E-10, 
dividing by 10, and getting 0.0123E-10. You get an answer, but you've lost a digit in the 
process. This situation is called underflow
, and C refers to floating-point values that have lost 
the full precision of the type as subnormal. So dividing the smallest positive normal floating-
point value by 2 results in a subnormal value. If you divide by a large enough value, you lose all 
the digits and are left with 0. The C library now provides functions that let you check whether 
your computations are producing subnormal values. 
There's another special floating-point value that can show up: NaN, or not-a-number. For 
example, you give the asin() function a value, and it returns the angle that has that value as 
its sine. But the value of a sine can't be greater than 1, so the function is undefined for values in 
excess of 1. In such cases, the function returns the NaN value, which printf() displays as nan, 
NaN, or something similar.

(二)its detection

https://stackoverflow.com/questions/15655070/how-to-detect-double-precision-floating-point-overflow-and-underflow

To be perfectly portable, you have to check before the operation, e.g. (for addition):

if ( (a < 0.0) == (b < 0.0)&& std::abs( b ) > std::numeric_limits<double>::max() - std::abs( a ) ) {//  Addition would overflow...
}

Similar logic can be used for the four basic operators.

If all of the machines you target support IEEE (which is probably the case if you don't have to consider mainframes), you can just do the operations, then use isfinite or isinf on the results.

For underflow, the first question is whether a gradual underflow counts as underflow or not. If not, then simply checking if the results are zero and a != -b would do the trick. If you want to detect gradual underflow (which is probably only present if you have IEEE), then you can use isnormal—this will return false if the results correspond to gradual underflow. (Unlike overflow, you test for underflow after the operation.)

(三)

https://hk.saowen.com/a/d229a08eae12ccedc4ce2dd540eaec49920c861c11679d6bb88a4276318fdf3f

自帶的函數limits,

#include<iostream>
#include<limits>
using namespace std;
int main(void){cout<<"int "<<"    所佔字節數: "<<sizeof(int);cout<<"    最大值: "<<(numeric_limits<int>::max)();cout<<"    最小值: "<<(numeric_limits<int>::min)()<<endl; cout<<"double "<<"    所佔字節數: "<<sizeof(double);cout<<"    最大值: "<<(numeric_limits<double>::max)();cout<<"    最小值: "<<(numeric_limits<double>::min)()<<endl; return 0;
}

輸出為

int     所佔字節數: 4  最大值: 2147483647      最小值: -2147483648
double  所佔字節數: 8  最大值: 1.79769e+308    最小值: 2.22507e-308

(四)C

integer limits: limits.h

floating point limits: float.h

Inside float.h

FLT_MAX 
DBL_MAX 
LDBL_MAX
1E+37 or greater
1E+37 or greater
1E+37 or greater
MAXimum Maximum finite representable floating-point number.
FLT_MIN 
DBL_MIN 
LDBL_MIN
1E-37 or smaller
1E-37 or smaller
1E-37 or smaller
MINimum Minimum representable positive floating-point number.

Floating-Point overflow and underflow相关推荐

  1. Solidity Integer Overflow and Underflow

    前言 实际上整形溢出并不仅仅是在智能合约中出现问题,在其他的地方也有出现.只不过我感觉我好像没咋遇到过...还是我太菜了.. 学习参考: underflow-overflow Integer Over ...

  2. 数值计算中的overflow and underflow

    数值计算中的overflow and underflow 以softmax为例 实数在计算机内用二进制标识,所以不是一个精确值,当数值过小的时候,被四舍五入为0,这就是下溢出,而指数函数容易出现无穷大 ...

  3. overflow and underflow

    Q: 什么叫underflow, 什么叫overflow? 对于很多的AI问题,如果出现很多概率的相乘,我们通常都在最前面加log, 为什么? ⽐如 argmax p(x), 通常求解 argmax ...

  4. 类型的Overflow与underflow

    Overflow:值超过了该类型所能表示的最大值 Underflow:值低于该类型所能表示的最小值 例如: short int  val=32767://short是两个字节,最高位是符号位 //va ...

  5. 如何防止softmax函数overflow和underflow?

    上溢出:c极其大的时候,计算 e c e^c ec 下溢出:当c趋于负无穷的时候,分母是一个极小的数,导致下溢出 解决方法 令 M = max ⁡ x i , i = 1 , 2 , ⋯ , n M= ...

  6. 浅谈上溢overflow和下溢underflow

    目录 一.为什么会出现overflow和underflow? 二.解决方法 一.为什么会出现overflow和underflow? 计算机只能使用有限的bit来描述数字,因此当被描述的数字需要超多的b ...

  7. 你应该知道的浮点数基础知识

    本文从一个有趣而又令人意外的实验展开,介绍一些关于浮点数你应该知道的基础知识 文章欢迎转载,但转载时请保留本段文字,并置于文章的顶部 作者:卢钧轶(cenalulu) 本文原文地址:http://ce ...

  8. Linux内核深入理解中断和异常(3):异常处理的实现(X86_TRAP_xx)

    Linux内核深入理解中断和异常(3):异常处理的实现(X86_TRAP_xx) rtoax 2021年3月 /*** start_kernel()->setup_arch()->idt_ ...

  9. Linux内核深入理解中断和异常(2):初步中断处理-中断加载

    Linux内核深入理解中断和异常(2):初步中断处理-中断加载 rtoax 2021年3月 1. 总体概览 关于idt_table结构的填充,在5.10.13中流程为: idt_setup_early ...

最新文章

  1. 细心看完这篇文章,刷新对Javascript Prototype的理解
  2. 中兴手机数据通道打不开_我用的是中兴手机,里面有流量,但是数据开不了,应该怎么办呢?...
  3. 数据库定时导出和互备一例
  4. android黑窗口获取md5_Android获取文件的MD5
  5. winrar 无法设置 xxx.aspx 的安全数据 -- 用批处理压缩文件在user账号下解压缩发生的错误...
  6. vi在一般指令模式下几个实用的命令
  7. 连接数_全国建成5G基站超48万个 5G终端连接数已过亿
  8. 第一百一十六期:不能错过!你必须知道的3种重要Python技能
  9. 上清华到底有多难?清华大学保送生的数学试题了解一下
  10. php网站接入微信支付,PHP接入微信H5支付的方法示例
  11. 蚂蚁回应渠道之争;微软更新致大规模服务中断;OpenSSH 8.4 发布 | 极客头条
  12. js总结1:数据类型
  13. CRM WEB UI 01 BOL向导创建的搜索
  14. 【Python3之模块及包的导入】
  15. matlab t分布 反函数,Excel 应用TINV函数计算学生的t分布的反函数
  16. Unable to start ServletWebServerApplicationContext due to missing ServletWeb解决办法
  17. python-opencv:在视频中显示fps等opencv快速入门
  18. html科学计算器,很剽悍的在线科学计算器
  19. 获得中国行政区划接口
  20. 大学毕业不用愁,一系列软件帮你轻松完成毕业论文

热门文章

  1. python对外正式发布年份_python正式对外发布的年份
  2. 海信85U7G-PRO怎么样 有什么优缺点
  3. 计算机考研408考试关键词、专有名词、术语等英文缩写和全称
  4. ExecutorService 详解 -- 执行器服务(线程池)
  5. unity游戏内拍照保存
  6. 电脑加一个固态硬盘,如何修改电脑的启动项。
  7. android hls检测,安卓大部分浏览器播放HLS协议直播流会从头开始
  8. 软件测试常用的8种功能测试类型
  9. 下载 raywenderlich.com 上的 iOS/android/Unity 视频、源码
  10. 旋转卡壳凸包(不用一下子就学完所有)