Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Supporting rational, real and complex numbers #14

Open
10 tasks
tommens opened this issue Dec 29, 2024 · 0 comments
Open
10 tasks

[FEATURE] Supporting rational, real and complex numbers #14

tommens opened this issue Dec 29, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@tommens
Copy link
Collaborator

tommens commented Dec 29, 2024

Describe the new functionality you would like to see

  • The calculator only provides support for integer arithmetic. It should also support arithmetics on other number domains, such as rational numbers (e.g. 1/3, 15/2), real numbers (e.g. 0.33, Pi, ...) with a given precision, and complex numbers (e.g. 2+3i). The detailed requirements for each number domain are provided below.
  • When supporting arithmetics on these number domains, care should be taken when carrying out operations that may result in an error. A clean, generic and reusable solution needs to be implemented; knowing that the same types of problems may also occur for all number domains (integers; rational numbers; real numbers; complex numbers; ...) E.g. for the real number domain, 0.0 / 0.0 is a NaN (an undefined number); 1.0/0.0 is +infinity (while 1/0 in the integer domain should report a division by zero error); -1.0/0.0 is -infinity (while -1/0 in the integer domain should report a division by zero error); taking the square root of a negative real number is a NaN, while it results in an imaginary number in the complex number domain; taking the logarithm of a negative value is not allowed, and so on.

Support for real numbers

  • All operations available in the calculator should support real numbers in floating point notation.
  • The user interface should allow to configure and change the precision of the real numbers (i.e., how many significant digits of a real number will be encoded)
  • Scientific notation should be available to be able express very large or very small decimal numbers. For example, 6.022E23 is equivalent to 6.022×10^23, which would be written as 6022 followed by 20 zeroes in "traditional" notation of natural numbers. Similarly, 1.6E-35 is equivalent to 1.6×10^(−35) which would be written as 0.00...00016 (with lots of zeroes after the floating point of the decimal number).
  • As on most scientific calculators, it should be possible to use and convert numbers from degrees or radians (the use of radians if often more intuitive and useful when working frequently with trigonometric functions like sin, cos, tan, and so on).

Support for rational numbers

  • All operations available in the calculator should support rational numbers, which can be seen as a fraction of two integer numbers (e.g. 3/4, 12/7, ...). See https://en.wikipedia.org/wiki/Rational_number
  • Operations on rational numbers should use their exact representation, rather than decimal floating point approximation to avoid loss of precision. E.g. 1/3 should not be represented as a floating point decimal number 0.333333 as this will lead to a loss of precision since it is not possible to represent an infinite sequence of numbers in the decimal notation.
  • It should be possible to simplify rational numbers to their canoncial form, e.g. 6/12 can be simplified to 1/2, and 18/12 can be simplified to 1 1/2.

Support for complex numbers

  • A complex number can be expressed in the form a + b i, where a and b are real numbers. a corresponds to the real part, and b to the imaginary part. Operations on complex numbers specify specific rules, see https://en.wikipedia.org/wiki/Complex_number

Recommendations for the implementation
For real number support, it is recommended to use something like java.math.BigDecimal, which allows for artibrary-precision decimal numbers and also provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion.

@tommens tommens added the enhancement New feature or request label Dec 29, 2024
@tommens tommens changed the title [FEATURE] Supporting rational and real numbers [FEATURE] Supporting rational, real and complex numbers Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant