Number: Difference between revisions

Jump to navigation Jump to search
→‎Numeric types: Dyalog doesn't do complex decfs
(Created page with "In APL, a number is a scalar array representing a mathematical wikipedia:number. Numbers and characters were the only possible element types in APL\360 and remain the basic data types in modern APLs. In addition to quantities for computation, they are used to represent Booleans (0 and 1) and indices. Numeric operations may be subject to floating-point rounding and comparison tolerance. Traditionally, APL provides only one user-visib...")
 
(→‎Numeric types: Dyalog doesn't do complex decfs)
 
Line 11: Line 11:
Several dialects, beginning with [[SHARP APL]] in 1981, support [[complex number]]s implemented as pairs of floats. These can be used alongside individual floating-point numbers and other optimized representations because the real numbers are a subset of floating-point numbers. [[NARS2000]] goes further in providing [[wikipedia:quaternion|quaternion]] and [[wikipedia:octonion|octonion]] support.
Several dialects, beginning with [[SHARP APL]] in 1981, support [[complex number]]s implemented as pairs of floats. These can be used alongside individual floating-point numbers and other optimized representations because the real numbers are a subset of floating-point numbers. [[NARS2000]] goes further in providing [[wikipedia:quaternion|quaternion]] and [[wikipedia:octonion|octonion]] support.


Most often the numeric type has the precision of a 64-bit float, although some early implementations used smaller sizes because of resource limitations: for example [[APL\1130]] used 32-bit floats. Modern implementations overwhelmingly use the 64-bit [[wikipedia:IEEE 754|IEEE 754]] double because of its support in hardware. While IEEE supports both negative and positive zero, this distinction is usually hidden from the programmer because it's incompatible with integer representations. [[Dyalog APL]] also supports 128-bit [[decimal float]]s by setting <syntaxhighlight lang=apl inline>⎕FR</syntaxhighlight>; if a program uses a consistent <syntaxhighlight lang=apl inline>⎕FR</syntaxhighlight> value then it will see only one floating-point type.
Most often the numeric type has the precision of a 64-bit float, although some early implementations used smaller sizes because of resource limitations: for example [[APL\1130]] used 32-bit floats. Modern implementations overwhelmingly use the 64-bit [[wikipedia:IEEE 754|IEEE 754]] double because of its support in hardware. While IEEE supports both negative and positive zero, this distinction is usually hidden from the programmer because it's incompatible with integer representations. [[Dyalog APL]] also supports 128-bit [[decimal float]]s by setting <syntaxhighlight lang=apl inline>⎕FR</syntaxhighlight>; if a program uses a consistent <syntaxhighlight lang=apl inline>⎕FR</syntaxhighlight> value and real numbers only then it will see only one floating-point type, but complex numbers with non-zero imaginary part always use binary floats for the components.


Some newer dialects provide additional types that are distinguishable from floats, often by greater precision. Extended-precision integers are one possibility: for example, [[dzaima/APL]] provides these if requested with a trailing <code>L</code> in a numeric literal or <syntaxhighlight lang=apl inline>⎕BIG</syntaxhighlight>, while [[Kap]] uses exact rational numbers by default. [[NARS2000]] supports numerous numeric types, and [[April]] provides access to the [[wikipedia:Common Lisp|Common Lisp]] numeric tower, which also includes many types.
Some newer dialects provide additional types that are distinguishable from floats, often by greater precision. Extended-precision integers are one possibility: for example, [[dzaima/APL]] provides these if requested with a trailing <code>L</code> in a numeric literal or <syntaxhighlight lang=apl inline>⎕BIG</syntaxhighlight>, while [[Kap]] uses exact rational numbers by default. [[NARS2000]] supports numerous numeric types, and [[April]] provides access to the [[wikipedia:Common Lisp|Common Lisp]] numeric tower, which also includes many types.

Navigation menu