Python中文
首页
教程
问答
标签
搜索
登录
注册
Delphi映射函数意外输出
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>在Arduino库中发现了这个天才<a href="https://www.arduino.cc/en/Reference/Map" rel="nofollow">map</a>函数。德尔菲写了同样的话:</p> <pre><code>procedure TForm1.Button1Click(Sender: TObject); function map(x, in_min, in_max, out_min, out_max: Integer): extended; begin result := (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; end; var y, in_min, in_max, out_min, out_max: Integer; i: integer; m: extended; begin in_min := 0; in_max := 6406963; out_min := 0; out_max := 474; y := 0; for i := in_min to in_max do begin m := map(i, in_min, in_max, out_min, out_max); if round(m) <> y then begin y := round(m); Memo1.Lines.Add(IntToStr(i) + ' = ' + FloatToStr(m)); end; end; end; </code></pre> <p>从中得到了一些有趣的结果,所以我用Python编写了同样的东西来检查和验证:</p> ^{pr2}$ <p>以下是我的结果片段:</p> <pre><code>DELPI EXPECTED (Python) 6759 = 0,500044404813 6759 = 0.50004440481395 1358439 = 100,500047526418 1358439 = 100.50004752641775 2710119 = 200,500050648022 2710119 = 200.50005064802153 4061799 = 300,500053769625 4061799 = 300.5000537696253 4521370 = 334,500040034569 4521370 = 334.50004003456866 4530557 = -335,179597260043 4534887 = 335.50005486218663 5418335 = -269,499996488196 5413479 = 400.5000568912291 6405062 = -196,499949820219 6400205 = 473.50002957719596 </code></pre> <p>那么,为什么我的Delphi代码会产生负数作为输出?应该怎么做才能纠正这个问题呢?在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>整数溢出,应该使用Double。在</p> <p>改变</p> <pre><code>function map(x, in_min, in_max, out_min, out_max: Integer): extended; </code></pre> <p>到</p> ^{pr2}$
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在PyObj中使用respondsToSelector和performSelector
8 回答
如何在pyobj中停止线程
6 回答
如何在pyobj中生成线程
9 回答
如何在pyodbc中为记录集指定游标类型?
10 回答
如何在pyodbc中从用户处获取表名,同时避免SQL注入?
7 回答
如何在pyodbc中使用executemany运行多个SELECT查询
5 回答
如何在pyodbc中同时在n个游标上并行运行n个进程?
7 回答
如何在pyodbc中控制连接池的大小?
8 回答
如何在pyodbc中自动调用fetchall()而不进行异常处理?
2 回答
如何在pyODBC查询中参数化日期戳?
4 回答
如何在pyodbc输出转换器函数中解压sqlserver DATETIME?
6 回答
如何在pyodb中安装所有驱动程序
8 回答
如何在pyodb嵌套循环中调用不同的查询
8 回答
如何在pyomo.environ公司modu装置
1 回答
如何在Pyomoconstraints中建模逻辑或量词
7 回答
如何在Pyomo中为约束使用数组
3 回答
如何在pyomo中使用集和范围集的多级索引?
1 回答
如何在PYOMO中分配伪二进制变量
3 回答
如何在Pyomo中创建OR约束?
1 回答
如何在Pyomo中动态地将变量添加到列表中?
7 回答