Arithmetic of a real number in a general language?

As (hopefully) most of you know, floating point arithmetic is different from real number arithmetic. This is inaccurate for beginners. Many numbers, especially decimal numbers (0,1, 0,3), cannot be represented, which leads to problems such as. A more detailed list can be found here .

Are there public languages that have built-in support for something closer to real-life arithmetic? If not, what good libraries support this?

EDIT: The arbitrary precision of decimaldatatypes is not what I am looking for. I want to be able to represent numbers such as 1/3, sqrt(3)or 1 + 2i.

+3
source share
12 answers

To cover real numbers with any miracle, you will need a symbolic package.

Boost, a C ++ project, has Rational , but this is only part of the story.

(pi, , , Champernowne constant, ). , , - . , e ^ pi, ? ?

Mathematica .

0

, . . , .

+2

, , , .

, , , , . .

+2

, , - (MATLAB , , ).

, , # - . , ( ) . , , , .

+1

, . -, , ( ) .

, , " ". - , , , ( ) (exp, sin, cos, log ..).

: , , (, , , ). , , , ( ) ( ).

.

, a/b (a/b + ic/d , a/b + sqrt (2) * a/b Q [sqrt (2)] ..). .

, . , , ( , - , , , ) , . Google boost::range gmp .

+1

. Scheme, , , ,

> (+ 1/2 1/3)
5/6
> (* 3 1+1/2i)
3+3/2i
> (+ 1/2 .5)
1.0

, algebraic , sqrt(2) - e, , , , Mathematica Maxima.

+1

Java: java.math.BigDecimal

#: decimal

0

: Java BigDecimal, Perl Math::BigFloat Math::BigRat, Haskell Integer, wikipedia.

0

Ada fixed-point , . , , .

, , IEEE, bignum.

, . (, 1/3). , , , , ​​ . (, pi e). , , , , , .

0

EDIT: , . , 1/3, sqrt (3) 1 + 2i .

Ruby Rational, 1/3 Rational (1,3). Complex.

0
source

The scheme defines rational, bonus, floating and complex numbers. Implementation is not required to support them all, but if they are present, you can mix them and they will be "right."

0
source

Until it is β€œbuilt-in”, I think C ++ (maybe C #) is your best bet. There are classes that have been written for this purpose.

http://www.oonumerics.org/oon/

-1
source

Source: https://habr.com/ru/post/1765328/