Problems About Rearrangement for Expressions in C
2010-06-07 13:03
302 查看
一些数学法则(如:结合律,分配律等)在C语言表达式中通常是不适用的。
比如下面的代码段:
由于舍入与精度的问题,上面的表达式通常是不相等的。
又如:
与下面的表达式也是不等的:
假设int的表示范围是[-32768, +32767],则如果a = -32754, b = -15,则第2个表达式会溢出,而原表达式不会。
比如下面的代码段:
double x, y, z; /* ... */ x = (x * y) * z; // not equivalent to x *= y * z; z = (x - y) + y ; // not equivalent to z = x; z = x + x * y; // not equivalent to z = x * (1.0 + y); y = x / 5.0; // not equivalent to y = x * 0.2;
由于舍入与精度的问题,上面的表达式通常是不相等的。
又如:
int a, b; /* ... */ a = a + 32760 + b + 5;
与下面的表达式也是不等的:
a = (a + b) + 32760;
假设int的表示范围是[-32768, +32767],则如果a = -32754, b = -15,则第2个表达式会溢出,而原表达式不会。
相关文章推荐
- Referenced file contains errors (http://www.springframework.org/schema/context). For more information, right click on the message in the Problems
- MS SQL错误:SQL Server failed with error code 0xc0000000 to spawn a thread to process a new login or connection. Check the SQL Server error log and the Windows event logs for information about possible related problems
- 1703.In Defense of the Triplet Loss for Person Re-Identification 论文阅读笔记
- Drag and Drop support for column reordering in DataGrid control
- Problems with System.OutOfMemoryException At System.String.GetStringForStringBuilder in 32-Bit Managed Solutions
- Problems with System.OutOfMemoryException At System.String.GetStringForStringBuilder in 32-Bit Managed Solutions
- Five levels of problems that might appear in books about mathematics
- 【Person Re-ID】In Defense of the Triplet Loss for Person Re-Identification
- Regular Expressions in Python with re module
- XML错误信息Referenced file contains errors (http://www.springframework.org/schema/beans/spring-beans-4.0.xsd). For more information, right click on the message in the Problems View ...
- The issue about using Git bash for Docker in window
- The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.
- Looking Beyond Appearances: Synthetic Training Data for Deep CNNs in Re-identification 学习笔记
- Paper Reading: In Defense of the Triplet Loss for Person Re-Identification
- Table View Programming Guide for iOS---(一)---About Table Views in iOS Apps
- Problems and Projections in CS for the Next 49 Years
- About the Player cache for framework----[the client frameWork can be used by all player plug in]
- 操作系统常见面试题整理(Most Common Problems in Interview for Operating System)
- 【论文笔记】In Defense of the Triplet Loss for Person Re-Identification
- Event Handling Guide for iOS--(一)--About Events in iOS(翻译)