作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个允许我使用椭圆曲线的库。它还处于萌芽状态,到目前为止它只包含两个类,EllipticCurve 和 Point。
现在我正在实现存在、归属、总和、反射等基本操作。
不幸的是,我现在陷入困境,我必须实现零的概念,即椭圆曲线 E 与 P 和 -P 相交的点,其中 P = (x,y) 和 -P = (x,-y)。所以,我的问题可以改写为“如何实现无穷远点?”
这是到目前为止 Point 类的一部分:
public class Point implements Comparable<Point> {
private static final BigDecimal MINUSONE = new BigDecimal(-1);
private BigDecimal x;
private BigDecimal y;
private EllipticCurve e;
public Point(BigDecimal x, BigDecimal y, EllipticCurve e) {
if(x != null && y != null && e != null) {
if(liesOn(x,y,e)) {
this.x = x;
this.y = y;
this.e = e;
}
}
}
public Point reflect() {
return new Point(x,y.multiply(MINUSONE),e);
}
public Point add(Point o) {
if(this.e == o.getE()) {
if(this == o) {
return this.multiply(2);
}
if(o == this.reflect()) {
return /*THE INFAMOUS ZERO POINT*/;
}
BigDecimal a;
BigDecimal b;
/*
* computation I still haven't implemented
*/
return new Point(a,b,e);
}
}
/*
* other methods
*/
}
P.S.:我知道 java.security.spec.EllipticCurve 的存在,但由于我主要将此类用于数学目的,所以我觉得有必要创建我的个人库ex novo.
最佳答案
无法使用 BigDecimal 来表示无穷大本身。我所知道的 Java 中唯一的方法是:
Double.POSITIVE_INFINITY;
或Integer
、Float
等。您也不能从上面获取valueOf
,因为它会抛出NumberFormatException
。
您可以使用解决方法,即。 e.一个非常大的值,您知道它总是比任何其他值都大。
关于java - 椭圆曲线上的零点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29231792/
我是一名优秀的程序员,十分优秀!