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

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

博客园 - 紫雨轩 .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);

 再运行结果就正确了.

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

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

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