HI,
我试图使用Jonathan Richard Shewchuk的计算几何的 强大谓词.
我不是程序员,所以我甚至不确定我在说什么,我可能会做一些基本的错误.
关键是谓词应该允许具有自适应浮点精度的精确算法.在我的电脑上:华硕pro31/S(Core Due Centrino处理器)它们无法正常工作.问题可能在于我的计算机可能会使用与Shewchuk使用的浮点精度冲突的一些改进.作者说:
/* On some machines, the exact arithmetic routines might be defeated by the */
/* use of internal extended precision floating-point registers. Sometimes */
/* this problem can be fixed by defining certain values to be volatile, */
/* thus forcing them to be stored to memory and rounded off. This isn't */
/* a great solution, though, as it slows the arithmetic down. */
Run Code Online (Sandbox Code Playgroud)
现在我想知道的是,有一种方法,可能是一些编译器选项,来关闭内部扩展精度浮点寄存器.
我非常感谢你的帮助
为什么这个C程序输出"错误"?
#include<stdio.h>
void main()
{
float f = 12345.054321;
printf("%f", f);
getch();
}
Run Code Online (Sandbox Code Playgroud)
输出:
12345.054688
Run Code Online (Sandbox Code Playgroud)
但输出应该是,12345.054321.
我在VS2008中使用VC++.
我用的时候 Math.pow(9, 18) =150094635296999136
当我使用网络计算器9 ^ 18 = 150094635296999121(http://web2.0calc.com/)
当我使用谷歌计算器9 ^ 18 = 1.50094635×10 ^ 17
为什么会有所不同?
我无法理解这个程序的输出
int main()
{
double x = 1.8939201459282359e-308;
double y = 4.9406564584124654e-324;
printf("%23.16e\n", 1.6*y);
printf("%23.16e\n", 1.7*y);
printf("%23.16e\n", 1.8*y);
printf("%23.16e\n", 1.9*y);
printf("%23.16e\n", 2.0*y);
printf("%23.16e\n", x + 1.6*y);
printf("%23.16e\n", x + 1.7*y);
printf("%23.16e\n", x + 1.8*y);
printf("%23.16e\n", x + 1.9*y);
printf("%23.16e\n", x + 2.0*y);
}
Run Code Online (Sandbox Code Playgroud)
输出是
9.8813129168249309e-324
9.8813129168249309e-324
9.8813129168249309e-324
9.8813129168249309e-324
9.8813129168249309e-324
1.8939201459282364e-308
1.8939201459282364e-308
1.8939201459282369e-308
1.8939201459282369e-308
1.8939201459282369e-308
Run Code Online (Sandbox Code Playgroud)
我正在使用IEEE算法.该变量y保持最小的IEEE编号.前五张照片显示的数字是我预期的两倍.令我困惑的是,接下来的五个版画显示不同的数字.如果1.6*y是相同的2.0*y话怎么会x + 1.6*y有所不同x + 2.0*y?
在饼图上显示工具提示时,Highcharts 3.0似乎有浮点数精度问题.我能够通过使用一个highcharts演示饼图--Pie with Legend来重新创建确切的错误.单击"在JsFiddle中编辑"以编辑javascript.
在javascript面板中,查找系列和数据部分.保留Firefox和IE数据并丢弃其余数据,这样我们就可以专注于2片馅饼.两个数据夹头没有百分比加起来,因此highcharts将重新计算我们的百分比.单击顶部的"运行"按钮,将鼠标悬停在切片上,百分比非常准确,最大小数位数.但是等一下,看看javascript工具提示选项,highcharts显然忽略了"percentageDecimals:1"设置.这是问题#1.
现在让我们手动编辑数据百分比,如下所示:['Firefox',57.7],['IE',42.3]所以它们确实加起来恰好是100.0.再次点击运行按钮,切片工具提示显示'Firefox:57.0000000000001%'和'IE:42.3%'.无论百分比是否加起来,看起来都是百分比重新计算,因此这里引入了一个小的浮点不准确.这是问题#2.如果在这种情况下"percentageDecimals"舍入工作,这个问题可能是伪装的.
我想知道:*其他人看到同样的问题并进行某种解决方法吗?*highcharts能否回应这些问题并让我们知道他们是否已知错误?
参考BigDecimal课程文件,
n,m = a.precs
prec返回有效位数(n)和最大有效位数(m)a.
我对以下与之相关的输出感到困惑BigDecimal.
require 'bigdecimal'
BigDecimal.new('1').precs # => [9, 18]
BigDecimal.new(1).precs # => [9, 27]
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么当a String传递时,与传递a 相比,最大有效位数会减少Fixnum.
它还会导致任何精度问题吗?
这是一个有趣的问题,我试图在前几天工作.是否有可能强制一个的有效数或指数与Python中的float另一个相同float?
问题出现了,因为我试图重新缩放某些数据,以便min和max匹配另一个数据集.但是,我重新调整后的数据略有偏差(大约小数点后6位),这足以引起问题.
提出一个想法,我有f1和f2(type(f1) == type(f2) == numpy.ndarray).我想要np.max(f1) == np.max(f2) and np.min(f1) == np.min(f2).为此,我做到了:
import numpy as np
f2 = (f2-np.min(f2))/(np.max(f2)-np.min(f2)) # f2 is now between 0.0 and 1.0
f2 = f2*(np.max(f1)-np.min(f1)) + np.min(f1) # f2 is now between min(f1) and max(f1)
Run Code Online (Sandbox Code Playgroud)
结果(仅作为示例)将是:
np.max(f1) # 5.0230593
np.max(f2) # 5.0230602 but I need 5.0230593
Run Code Online (Sandbox Code Playgroud)
我最初的想法是,强制指数float将是正确的解决方案.我找不到多少,所以我为我的需要做了一个解决方法:
exp = 0
mm = np.max(f1)
# find where the decimal …Run Code Online (Sandbox Code Playgroud) 我正在使用一个双精度数组indata(在堆中,用malloc分配)和一个本地双精度调用sum.
我写了两个不同的函数来比较值indata,并获得不同的结果.最终我确定差异是由于一个函数在条件测试中使用表达式,而另一个函数在同一条件测试中使用局部变量.我希望这些是等价的.
我的功能A使用:
if (indata[i]+indata[j] > max) hi++;
Run Code Online (Sandbox Code Playgroud)
我的功能B使用:
sum = indata[i]+indata[j];
if (sum>max) hi++;
Run Code Online (Sandbox Code Playgroud)
经过相同的数据集之后max,我最终会得到不同的值,hi具体取决于我使用的功能.我认为功能B是正确的,功能A是误导性的.同样,当我尝试下面的代码片段时
sum = indata[i]+indata[j];
if ((indata[i]+indata[j]) != sum) etc.
Run Code Online (Sandbox Code Playgroud)
条件将评估为真.
虽然我理解浮点数不一定能提供精确的表示,但为什么在计算表达式vs存储在变量中时,精确表示会发生变化?建议的最佳做法是在条件之前始终评估这样的双重表达式吗?谢谢!
这里的代码是直截了当的,但我不明白结果:
float percent = 0.69f;
int firstInt = (int)(percent*100f);
float tempFloat = percent*100f;
int secondInt = (int)tempFloat;
Debug.Log(firstInt + " " + secondInt);
Run Code Online (Sandbox Code Playgroud)
为什么是firstInt68但是secondInt69?
如果以前曾经问过我,我很抱歉,但我找不到.
我想知道是否有办法计算用作计数器的单精度浮点数达到'最大值'的点(由于丢失而无法再添加其他值的点)精确).
例如,如果我不断添加0.1f到a,float我最终会达到值不会改变的点:
const float INCREMENT = 0.1f;
float value = INCREMENT;
float prevVal = 0.0f;
do {
prevVal = value;
value += INCREMENT;
} while (value != prevVal);
cout << value << endl;
Run Code Online (Sandbox Code Playgroud)
在海湾合作委员会这输出 2.09715e+06
有没有办法用数学方法计算不同的值INCREMENT?我认为理论上它应该是当指数部分float要求移位超过23位时,导致丢失尾数并简单地加0.
c ×3
c++ ×2
precision ×2
c# ×1
casting ×1
decimal ×1
expression ×1
highcharts ×1
ieee-754 ×1
java ×1
math ×1
numpy ×1
percentage ×1
pie-chart ×1
pow ×1
python ×1
ruby ×1
syntax ×1
visual-c++ ×1