- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想要一个可以模拟无穷大的大 double ,但又不能大到占用大量内存。因此,最大的双倍可能可以多次使用而不会导致我的程序崩溃。
对于上下文:我正在尝试创建一个函数,该函数返回从两个点创建的两条线段之间的交点,如果没有交点,则返回 null(在更高的方法中使用,以确定对象是否在碰撞中)我的平台游戏)。作为数学/代码的一部分,我需要从两个点创建一个线函数,当该线恰好是垂直的时,它需要具有无限的斜率。这是我到目前为止所拥有的:
public static Point intersect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
//calcs slopes
double m1 = bigDouble; //infinity!
if (x1==x2) m1 = (y2-y1) / (x2-x1); //if its not vertical, calc the slope
double m2 = bigDouble;
if (x3==x4) m2 = (y4-y3) / (x4-x3);
//calcs b in y=mx+b
int b1 = (int) (m1*x1+y1);
int b2 = (int) (m2*x3+y3);
//checks that lines are not parallel
if (m1==m2) return null;
//calcs intersection
int x = (int) ((b2-b1)/(m1-m2));
int y = (int) (m1*x+b1);
//checks that intersection is within bounds of segments
if (isOutside(x,x1,x2)||isOutside(y,y1,y2)||isOutside(x,x3,x4)||isOutside(y,y3,y4)) return null;
//returns intersection point
return new Point(x,y);
}
public static boolean isOutside (int num, int bound1, int bound2) {
return num<getMin(bound1,bound2) || num>getMax(bound1, bound2);
}
public static int getMin(int num1, int num2) {
if (num1>num2) return num2;
return num1;
}
public static int getMax(int num1, int num2) {
if (num1>num2) return num1;
return num2;
}
那么我可以用什么来实现这个大双倍呢?谢谢!
最佳答案
使用其中之一:
Double.POSITIVE_INFINITY
Double.MAX_VALUE
关于java - 我可以用什么大 double 来模拟无穷大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59524609/
任何数字减去它本身应该是 0,对吗? 3 - 3 === 0 那为什么 Infinity - Infinity === NaN 因为 typeof Infinity 是 'number': 最佳答案
我有一个可能为零的数字。我除以那个数字所以我想测试它是否为零以防止 NaN 和无穷大。由于除法中的舍入误差,我是否仍可能创建 NaN/无穷大? double x; // might be zero d
我使用carrierwave 和mini_magick 上传图片。在开发中一切都很好,但在生产中它引发了 FloatDomainError (Infinity)当我尝试上传图片时。我在同一台服务器上托
我有一个递归函数,它从一组边生成路径列表。但是,有时由于图形的性质,它会进入循环并生成一个字典,其中在列表中包含无限循环符号 [...],例如: {('a', 'b'): [[1, 2, 8, 9,
我正在摆弄 JavaScript 中的按位运算符,我发现有一件事值得注意。 bitwise or operator返回1如果两个输入位之一是 1 作为输出位。这样做x | 0总是返回x ,因为| 0没
我检查二叉树是否是 BST 的解决方案如下: def is_BST(node): if node is None: return False stack = [(node, -floa
给定(Python3): >>> float('inf') == Decimal('inf') True >>> float('-inf') >> float('-inf') >> Decimal('
我正在尝试使用 scikit learn 拟合一个简单的机器学习模型。在这条线上: clf.fit(features, labels) 我得到一个熟悉的错误: Input contains NaN,
我有一个数据集,它是 2 个浮点类型数字的比率。有些值具有 inf 表示无穷大(除以零)的情况。如何使用 pd.qcut/pd.cut 和 inf 值? 我的数据可以访问 here . q = pd.
好的,我知道之前有人用一个有限的缩放示例问过这个问题 [-1, 1]间隔 [a, b] Different intervals for Gauss-Legendre quadrature in num
案例:我们有一个运行 bash 脚本的 docker 容器,该脚本需要永远“阻塞”(因为它为另一个容器公开了一个卷,但有时我们需要这样做还有其他原因)。 我当时认为这可以工作: exec sleep
我是一名优秀的程序员,十分优秀!