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

推荐订阅源

WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Visual Studio Blog
宝玉的分享
宝玉的分享
IT之家
IT之家
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
I
InfoQ
B
Blog RSS Feed
T
Threatpost
博客园_首页
M
MIT News - Artificial intelligence
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
U
Unit 42
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
Scott Helme
Scott Helme
T
Tor Project blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
S
Schneier on Security
Vercel News
Vercel News
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
L
LangChain Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
S
Security Affairs
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
大猫的无限游戏
大猫的无限游戏
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos 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);

 再运行结果就正确了.

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

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

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