惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
博客园 - 司徒正美
爱范儿
爱范儿
F
Fortinet All Blogs
J
Java Code Geeks
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
V
V2EX
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog

博客园 - 紫雨轩 .Net

DNGuard Enterprise v3.56 released DNGuard Enterprise v3.30 released ComboBox 使用数据绑定时 Sorted 属性的bug DNGuard Enterprise v3.2 released DNGuard 企业版 v3.1 发布 DNGuard 专业版 v2.95 发布 DNGuard Enterprise v2.95 released 在 FlexGrid 控件中指定最右侧显示的列 .Net 中枚举AppDomains Windows 2003 上使用 Windows Live Writer .Net程序集的不同加载方式,以及其在内存中格式 DNGuard Enterprise v2.92 released - 紫雨轩 .Net DNGuard 标准版 v2.90发布 DNGuard Enterprise v2.90 released DNGuard Enterprise v2.82 released 采用Native 引导方式的.Net加密保护 C#中使用晚绑定实现压缩Access数据库 直接在.Net程序(C#)中执行 native code DNGuard HVM Trial V2.82 发布
C#复杂表达式的问题
紫雨轩 .Net · 2008-01-10 · via 博客园 - 紫雨轩 .Net

测试程序发现了一个bug, 几经调试最后定位到一条复杂表达式语句的计算结果不正确.

代码中用复杂表达式不是一个好习惯,调试起来很不方便.

为了方便跟踪调试,看看究竟是表达式的那部分计算出了问题.
就先把表达式拆开来写了.

再运行, 嗨, bug没有了. 跟踪看了表达式最终计算结果,也正确了.

问题表达式如下:
this.backgroundScaleFactor = ((this.fishEyeMagFactor * (this.LengthOfScale - (this.fishEyeHigh - this.fishEyeLo))) + (this.fishEyeHigh - this.fishEyeLo)) / (this.timeLine.VisibleTime(this.startTime, this.stopTime) * this.fishEyeMagFactor);

运行时得到的 结果不正确.
拆解为如下:
double tmp1 = ((this.fishEyeMagFactor * (this.LengthOfScale - (this.fishEyeHigh - this.fishEyeLo))) + (this.fishEyeHigh - this.fishEyeLo));
long tmplng = this.timeLine.VisibleTime(this.startTime, this.stopTime);
this.backgroundScaleFactor = tmp1 / (tmplng * this.fishEyeMagFactor);

 再运行结果就正确了.

教训: 尽量避免书写复杂表达式, 调试跟踪不方便.

问题的原因:
我估计是数据类型隐式转换造成的.

简单表达式的转换,很容易看清楚,可能有转换错误的一眼就能看出来.
复杂表达式自己都看得迷糊了.