Comments (6)
I can reproduce the behaviour in a JS test. For integers, this is typically a case for a division by zero exception, like e.g. in Python
>>> 1/0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
However, as far as I can see, no exceptions are used in the library. This is probably because not all supported languages have exceptions. But is there a better way to report those kind of errors?
from amcl.
I think returning 0 hides a logic error of the caller code much better than an infinite loop, such that bugs might be undetected much longer. At the end of the day, the caller must not call invmodp
on 0.
from amcl.
Fair point. But in the multiplicative group GF(p) the value 0 is actually not a group member, so returning an illegal value does flag up the problem if the caller is paying attention. Also the alternate constant time method for modular inversion that is actually used in the elliptic curve code uses Fermats method, 1/x = x^{p-2} mod p, which does naturally return 0 for x=0.
from amcl.
Ideally, the code for every language should be idiomatic in that language. So the Rust code should raise an error while the C code should return a non-zero error code.
from amcl.
I guess just returning 0 is better than an infinite loop, while admittedly not mathematically correct. And yes I want to avoid language specific constructs if at all possible, otherwise maintenance becomes a nightmare.
from amcl.
so returning an illegal value does flag up the problem if the caller is paying attention
Nice one
from amcl.
Related Issues (20)
- API inconsistency in ECP.mul HOT 2
- Potential bug in is_infinity in ecp.rs
- Point compression for ECP2 HOT 1
- Question about SECP256K1 curve in go HOT 2
- Pairing function does not fulfil point addition property for infinity HOT 2
- Pairing function does not return 1 for P=infinity, Q=infinity HOT 5
- Methods add, sub missing in FP12, FP24, FP48 HOT 1
- Please check the code for FP12.pow(BIG) HOT 23
- Add new curve
- bls.js and bls256.js don't load in IE 11 HOT 1
- Two small change suggestions HOT 1
- Swift issues HOT 5
- Swift compile for iOS
- A bug might exit in amcl-go
- Error compiling on armhf platform HOT 4
- FP256BN Plus and math.MaxInt64 HOT 7
- Use JS version of amcl in nodejs environments HOT 2
- Does the library support type-1 curvers? HOT 2
- Help!Urgent! HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amcl.