Numeric Limits: Unterschied zwischen den Versionen

Aus expecco Wiki (Version 2.x)
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt: „== Integer Arithmetic == Expecco supports arbitrary precision integer arithmetic, arbitrary precision fractions and limited precision floating point numbers. …“)
 
Zeile 23: Zeile 23:
== Trigonmetric and other Math Functions ==
== Trigonmetric and other Math Functions ==


Trigonometric functions when applied to integer or fractional numbers will
Trigonometric and other math functions (sqrt, log, exp)
first convert the number to a limited precision real number (a C-double),
will first convert the number to a limited precision real number (a C-double),
and therefore may have a limited input value range.
and therefore may have a limited input value range and also generate inexact results.


For example, you will not get a valid result for:
For example, you will not get a valid result for:
Zeile 31: Zeile 31:
because it is not possible to represent that large number as real number.
because it is not possible to represent that large number as real number.
(expecco will signal a domain error, as the input to sin will be +INF)
(expecco will signal a domain error, as the input to sin will be +INF)

Also, the result from:
(9 / 64) sqrt
will be the (inexact) 0.75 (a double), instead of the exact 3/4 (a fraction).

Version vom 17. Februar 2017, 12:46 Uhr

Integer Arithmetic[Bearbeiten]

Expecco supports arbitrary precision integer arithmetic, arbitrary precision fractions and limited precision floating point numbers.

For integer operations, there is no overflow or error in the result for any legal operation. I.e. operations on two big numbers deliver a correct result:

4294967295 (0xFFFFFFFF) + 1 -> 4294967296 (0x100000000)
18446744073709551615 (0xFFFFFFFFFFFFFFFF) + 1 -> 18446744073709551616 (0x10000000000000000)


when dividing integers, the "/" operator will deliver an exact result, possibly as a fraction:

5 / 3 -> 5/3

and the truncating division "//" will deliver an integer, truncated towards negative infinity (i.e. the next smaller integer):

5 // 3 -> 2
-5 // 3 -> -3

Trigonmetric and other Math Functions[Bearbeiten]

Trigonometric and other math functions (sqrt, log, exp) will first convert the number to a limited precision real number (a C-double), and therefore may have a limited input value range and also generate inexact results.

For example, you will not get a valid result for:

10000 factorial sin

because it is not possible to represent that large number as real number. (expecco will signal a domain error, as the input to sin will be +INF)

Also, the result from:

(9 / 64) sqrt

will be the (inexact) 0.75 (a double), instead of the exact 3/4 (a fraction).



Copyright © 2014-2024 eXept Software AG