Git Product home page Git Product logo

Comments (6)

webmaster128 avatar webmaster128 commented on August 22, 2024 1

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.

webmaster128 avatar webmaster128 commented on August 22, 2024 1

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.

mcarrickscott avatar mcarrickscott commented on August 22, 2024 1

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.

lovesh avatar lovesh commented on August 22, 2024

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.

mcarrickscott avatar mcarrickscott commented on August 22, 2024

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.

webmaster128 avatar webmaster128 commented on August 22, 2024

so returning an illegal value does flag up the problem if the caller is paying attention

Nice one

from amcl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.