| 1 |
@node Numbers |
| 2 |
@section Numbers |
| 3 |
|
| 4 |
@menu |
| 5 |
* Numbers - Numeric types:: |
| 6 |
* Numbers - Floating point exceptions:: |
| 7 |
* Numbers - Random-States:: |
| 8 |
* Numbers - Infinity and Not a Number:: |
| 9 |
* Numbers - Branch cuts and signed zero:: |
| 10 |
* Numbers - Dictionary:: |
| 11 |
* Numbers - C Reference:: |
| 12 |
@end menu |
| 13 |
|
| 14 |
@node Numbers - Numeric types |
| 15 |
@subsection Numeric types |
| 16 |
ECL supports all of the Common Lisp numeric tower, which is shown in @ref{tab:num-types}. The details, however, depend both on the platform on which ECL runs and on the configuration which was chosen when building ECL. |
| 17 |
|
| 18 |
@float Table, tab:num-types |
| 19 |
@caption{Numeric types in ECL} |
| 20 |
@multitable @columnfractions .18 .82 |
| 21 |
@headitem Type @tab Description |
| 22 |
@item fixnum @tab Signed integer with a number of bits given by ext:fixnum-bits, fit in a machine word. |
| 23 |
@item bignum @tab Arbitrary size integers, only limited by amount of memory. |
| 24 |
@item ratio @tab Arbitrary size rational number, made up of two integers. |
| 25 |
@item short-float @tab Equivalent to single-float. |
| 26 |
@item single-float @tab 32-bits IEEE floating point number. |
| 27 |
@item double-float @tab 64-bits IEEE floating point number. |
| 28 |
@item long-float @tab Either equivalent to double-float, or a 96/128 bits IEEE floating point number (long double in C/C++). |
| 29 |
@item rational @tab An alias for (or integer ratio) |
| 30 |
@item float @tab An alias for (or single-float double-float short-float long-float) |
| 31 |
@item real @tab An alias for (or rational float) |
| 32 |
@item complex @tab Complex number made of two real numbers of the above mentioned types or a <float> _Complex type in C99. |
| 33 |
@end multitable |
| 34 |
@end float |
| 35 |
|
| 36 |
In general, the size of a @code{fixnum} is determined by the word size |
| 37 |
of a machine, which ranges from 32 to 64 bits. Integers larger than |
| 38 |
this are implemented using the @url{https://gmplib.org/, GNU |
| 39 |
Multiprecision library}. Rationals are implemented using two integers, |
| 40 |
without caring whether they are fixnum or not. Floating point numbers |
| 41 |
include at least the two IEEE types of 32 and 64 bits respectively. |
| 42 |
|
| 43 |
@cindex long-float internal representation |
| 44 |
@ftindex LONG-FLOAT |
| 45 |
In machines where it is supported, it is possible to associate the |
| 46 |
lisp @code{long-float} with the machine type @code{long double} whose |
| 47 |
size ranges from 96 to 128 bits, and which are a bit slower. |
| 48 |
|
| 49 |
@cindex (complex float) internal representation |
| 50 |
@ftindex COMPLEX-FLOAT |
| 51 |
In machines where a type @code{<float> _Complex} is supported numbers |
| 52 |
of type @code{(complex float)} are implemented with it, otherwise like |
| 53 |
ratios all complex numbers are pairs of numbers. |
| 54 |
|
| 55 |
@node Numbers - Floating point exceptions |
| 56 |
@subsection Floating point exceptions |
| 57 |
@cfindex --with-ieee-fp [YES|no] |
| 58 |
@cfindex --with-fpe [YES|no] |
| 59 |
|
| 60 |
ECL supports two ways of dealing with special floating point values, |
| 61 |
such as Not a Number (NaN), infinity or denormalized floats, which can |
| 62 |
occur in floating point computations. Either a condition is signaled or |
| 63 |
the value is silently used as it is. There are multiple options |
| 64 |
controlling which behaviour is selected: If ECL is built with the |
| 65 |
@code{--without-ieee-fp} configure option, then a condition is signaled |
| 66 |
for every infinity or NaN encountered. If not, floating point exceptions |
| 67 |
can be disabled at build time using the @code{--without-fpe} configure |
| 68 |
option. Otherwise, if both @code{--with-ieee-fp} and @code{--with-fpe} |
| 69 |
options are on, by default, a condition is signaled for invalid |
| 70 |
operation, division by zero and floating point overflows. This can be |
| 71 |
changed at runtime by using @coderef{ext:trap-fpe}. If the |
| 72 |
@code{ECL_OPT_TRAP_SIGFPE} boot option is false (see |
| 73 |
@ref{tab:boot-options}), no conditions are signaled by default (Note |
| 74 |
that in this case, if you enable trapping of floating point exceptions |
| 75 |
with @coderef{ext:trap-fpe}, then you have to install your own signal |
| 76 |
handler). |
| 77 |
|
| 78 |
@lspdef ext:trap-fpe |
| 79 |
@defun ext:trap-fpe condition flag |
| 80 |
Control the signaling of the floating point exceptions |
| 81 |
|
| 82 |
@paragraph Synopsis |
| 83 |
@table @var |
| 84 |
@item condition |
| 85 |
a symbol - one of @code{cl:last}, @code{cl:t}, @code{cl:division-by-zero}, |
| 86 |
@code{cl:floating-point-overflow}, @code{cl:floating-point-underflow}, |
| 87 |
@code{cl:floating-point-invalid-operation}, |
| 88 |
@code{cl:floating-point-inexact} or an integer. |
| 89 |
@item flag |
| 90 |
a generalized boolean |
| 91 |
@end table |
| 92 |
|
| 93 |
@paragraph Description |
| 94 |
If @var{condition} is @code{last}, @var{flag} is ignored and the |
| 95 |
currently enabled floating point exceptions are returned in an |
| 96 |
implementation depended format (currently an integer). Otherwise, |
| 97 |
@var{flag} determines whether the current thread will signal a floating |
| 98 |
point exception for the conditions passed in @var{condition}. |
| 99 |
@var{condition} can be either a symbol denoting a single condition, |
| 100 |
@code{t} for all conditions that are enabled by default or a value |
| 101 |
obtained from an earlier call to @coderef{ext:trap-fpe} with |
| 102 |
@code{last}. |
| 103 |
|
| 104 |
@seealso{ECL_WITH_LISP_FPE} |
| 105 |
|
| 106 |
@end defun |
| 107 |
|
| 108 |
@node Numbers - Random-States |
| 109 |
@subsection Random-States |
| 110 |
ECL relies internally on a 32-bit Mersenne-Twister random number |
| 111 |
generator, using a relatively large buffer to precompute about 5000 |
| 112 |
pseudo-random bytes. This implies also that random states can be |
| 113 |
printed readably and also read, using the @code{#$} macro. There is no |
| 114 |
provision to create random states from user arrays, though. Random |
| 115 |
state is printed unreadably by default. |
| 116 |
|
| 117 |
The @code{#$} macro can be used to initialize the generator with a |
| 118 |
random seed (an integer), an array of random bytes (mainly used for |
| 119 |
reading back printed random-state) and another random-state (syntactic |
| 120 |
sugar for copying the random-state). |
| 121 |
|
| 122 |
@node Numbers - Infinity and Not a Number |
| 123 |
@subsection Infinity and Not a Number |
| 124 |
The @ansi{} standard does not specify the behaviour of numeric |
| 125 |
functions for infinite or not number valued floating point numbers. If |
| 126 |
ECL is configured to support these special values (see the |
| 127 |
@code{--with-ieee-fp} configure option) and floating point exceptions |
| 128 |
are disabled, numeric functions generally return the same value as the |
| 129 |
corresponding C function. This means, that the output will be a NaN |
| 130 |
for a NaN input, and the ``mathematically correct'' value (which may |
| 131 |
be NaN, e.g. for ∞-∞) for an infinite real input. For complex floats, |
| 132 |
however, the return value of a numeric function called with a complex |
| 133 |
number for which the real or imaginary part is infinite, is |
| 134 |
undefined@footnote{The main reason for this is that some numeric |
| 135 |
functions for C complex numbers return mathematically incorrect |
| 136 |
values, for example sinh(i*∞) returns i*NaN instead of the |
| 137 |
mathematically correct i*∞. Keeping this consistent with our own |
| 138 |
implementation of complex arithmetic that is used when C complex |
| 139 |
numbers are not available would require to much work. Furthermore, |
| 140 |
complex arithmetic with infinities is unreliable anyway, since it |
| 141 |
quickly leads to NaN values (consider i*∞ = (0+i*1)*(∞+i*0) = NaN+i*∞; |
| 142 |
even this simple example is already mathematically incorrect).}. |
| 143 |
|
| 144 |
For other functions dealing with numbers, we adopt the following |
| 145 |
behaviour: |
| 146 |
|
| 147 |
@table @asis |
| 148 |
@item Comparison functions |
| 149 |
All numeric comparisons with @code{=,<,<=,>,>=} involving NaN return |
| 150 |
false. Comparing two NaNs of the same type with @code{eql} returns |
| 151 |
true. |
| 152 |
@item @code{min/max} |
| 153 |
NaN values are ignored, i.e. the maximum/minimum is taken only over |
| 154 |
the number valued parameters. |
| 155 |
@item Rounding functions |
| 156 |
All rounding functions signal an @code{arithmetic-error} if any of the |
| 157 |
given parameters are not number valued or infinite. |
| 158 |
@end table |
| 159 |
|
| 160 |
@node Numbers - Branch cuts and signed zero |
| 161 |
@subsection Branch cuts and signed zero |
| 162 |
For multi-valued complex functions like @code{asin}, @code{acos}, etc. |
| 163 |
the @ansi{} standard specifies in detail the location of the branch cuts |
| 164 |
and in particular the value of these functions on the branch cuts. ECL |
| 165 |
diverges from the standard in that the sign of zero distinguishes two |
| 166 |
sides of a branch cut. For example, the @code{asin} function includes a |
| 167 |
branch cut running from 1 to ∞ on the real axis. The ANSI standard |
| 168 |
specifies a negative imaginary part for @code{asin} on this branch cut |
| 169 |
consistent with approaching the cut from below. Evaluating @code{(asin |
| 170 |
z)} in ECL, on the other hand, returns a result with positive imaginary |
| 171 |
part if the imaginary part of @code{z} is @code{+0.0} (consistent with |
| 172 |
approaching the cut from above) and a result with negative imaginary |
| 173 |
part if the imaginary part of @code{z} is @code{-0.0} (consistent with |
| 174 |
approaching the cut from below)@footnote{The reason for this behaviour |
| 175 |
is twofold: first, the approach taken by ECL is mathematically more |
| 176 |
sensible in a number system with signed zero and second, it is |
| 177 |
consistent with the specification of multi-valued complex functions in |
| 178 |
the C programming language.}. This applies to @code{sqrt}, @code{asin}, |
| 179 |
@code{acos}, @code{atan}, @code{asinh}, @code{acosh} and @code{atanh}. |
| 180 |
|
| 181 |
@node Numbers - Dictionary |
| 182 |
@subsection Dictionary |
| 183 |
|
| 184 |
@lspdef ext:short-float-positive-infinity |
| 185 |
@lspdef ext:short-float-negative-infinity |
| 186 |
@lspdef ext:single-float-positive-infinity |
| 187 |
@lspdef ext:single-float-negative-infinity |
| 188 |
@lspdef ext:double-float-positive-infinity |
| 189 |
@lspdef ext:double-float-negative-infinity |
| 190 |
@lspdef ext:long-float-positive-infinity |
| 191 |
@lspdef ext:long-float-negative-infinity |
| 192 |
@defvr Constant {ext:@{short,single,double,long@}-float-@{positive,negative@}-infinity} |
| 193 |
Constant positive/negative infinity for the different floating point types. |
| 194 |
@end defvr |
| 195 |
|
| 196 |
|
| 197 |
@lspdef ext:nan |
| 198 |
@defun ext:nan |
| 199 |
Returns a double float NaN value. Coerce to other floating point types |
| 200 |
to get NaN values e.g. for single floats. |
| 201 |
@end defun |
| 202 |
|
| 203 |
@lspdef ext:float-infinity-p |
| 204 |
@lspindex ext:float-nan-p |
| 205 |
@defun ext:float-infinity-p x |
| 206 |
@defunx ext:float-nan-p x |
| 207 |
Predicates to test if @var{x} is infinite or NaN. |
| 208 |
@end defun |
| 209 |
|
| 210 |
@node Numbers - C Reference |
| 211 |
@subsection C Reference |
| 212 |
|
| 213 |
@menu |
| 214 |
* Numbers - Number C types:: |
| 215 |
* Numbers - Number constructors:: |
| 216 |
* Numbers - Number accessors:: |
| 217 |
* Numbers - Number coercion:: |
| 218 |
* Numbers - ANSI dictionary:: |
| 219 |
@end menu |
| 220 |
|
| 221 |
@node Numbers - Number C types |
| 222 |
@subsubsection Number C types |
| 223 |
Numeric C types understood by ECL |
| 224 |
|
| 225 |
@subsubheading Type names |
| 226 |
@multitable @columnfractions .21 .40 .25 .14 |
| 227 |
@item cl_fixnum @tab fixnum |
| 228 |
@item cl_index @tab (integer 0 most-positive-fixnum) |
| 229 |
@item float @tab short-float, single-float |
| 230 |
@item double @tab double-float |
| 231 |
@item long double (*) @tab long-float @tab ECL_LONG_FLOAT @tab :long-float |
| 232 |
@item float _Complex (**) @tab (complex single-float) @tab ECL_COMPLEX_FLOAT @tab :complex-float |
| 233 |
@item double _Complex (**) @tab (complex double-float) @tab ECL_COMPLEX_FLOAT @tab :complex-float |
| 234 |
@item long-double _Complex (**) @tab (complex long-float) @tab ECL_COMPLEX_FLOAT @tab :complex-float |
| 235 |
@item uint8_t @tab (unsigned-byte 8) @tab ecl_uint8_t |
| 236 |
@item int8_t @tab (signed-byte 8) @tab ecl_int8_t |
| 237 |
@item uint16_t @tab (unsigned-byte 16) @tab ecl_uint16_t @tab :uint16-t |
| 238 |
@item int16_t @tab (signed-byte 16) @tab ecl_int16_t @tab :int16-t |
| 239 |
@item uint32_t @tab (unsigned-byte 32) @tab ecl_uint32_t @tab :uint32-t |
| 240 |
@item int32_t @tab (signed-byte 32) @tab ecl_int32_t @tab :int32-t |
| 241 |
@item uint64_t @tab (unsigned-byte 64) @tab ecl_uint64_t @tab :uint64-t |
| 242 |
@item int64_t @tab (signed-byte 64) @tab ecl_int64_t @tab :int64-t |
| 243 |
@item short @tab (integer ffi:c-short-min ffi:c-short-max) |
| 244 |
@item unsigned short @tab (integer 0 ffi:c-ushort-max) |
| 245 |
@item int @tab (integer ffi:c-int-min ffi:c-int-max) |
| 246 |
@item unsigned int @tab (integer 0 ffi:c-uint-max) |
| 247 |
@item long @tab (integer ffi:c-long-min ffi:c-long-max) |
| 248 |
@item unsigned long @tab (integer 0 ffi:c-long-max) |
| 249 |
@item long long @tab (integer ffi:c-long-long-min ffi:c-long-long-max) @tab ecl_long_long_t @tab :long-long |
| 250 |
@item unsigned long long @tab (integer 0 ffi:c-ulong-long-max) @tab ecl_ulong_long_t @tab :ulong-long |
| 251 |
@end multitable |
| 252 |
|
| 253 |
@paragraph Description |
| 254 |
The table above shows the relation between C types and the equivalent Common Lisp types. All types are standard C99 types, except for two. First, @code{cl_fixnum} is the smallest signed integer that can fit a fixnum. Second, @code{cl_index} is the smallest unsigned integer that fits a fixnum and is typically the unsigned counterpart of @code{cl_fixnum}. |
| 255 |
|
| 256 |
(*) @strong{DEPRECATED} Previous versions of ECL supported compilers |
| 257 |
that did not define the long double type. The @code{ECL_LONG_DOUBLE} |
| 258 |
macro and @code{long-double} features indicating whether support for |
| 259 |
long double was available are removed now. |
| 260 |
|
| 261 |
@cfindex --enable-c99complex [auto] |
| 262 |
(**) The <float> _Complex types do not exist on all platforms. When |
| 263 |
they exist the macro @code{ECL_COMPLEX_FLOAT} will be defined. |
| 264 |
|
| 265 |
Many other types might also not exist on all platforms. This includes |
| 266 |
not only @code{long long} and @code{unsigned long long}, but also some |
| 267 |
of the C99 integer types. There are two ways to detect which integer |
| 268 |
types are available in your system: |
| 269 |
|
| 270 |
@itemize |
| 271 |
@item |
| 272 |
Check for the definition of C macros with a similar name, shown in the fifth column above. |
| 273 |
@item |
| 274 |
In Lisp code, check for the presence of the associated features, shown in the fourth column above. |
| 275 |
@end itemize |
| 276 |
|
| 277 |
@node Numbers - Number constructors |
| 278 |
@subsubsection Number constructors |
| 279 |
Creating Lisp types from C numbers |
| 280 |
|
| 281 |
@subsubheading Functions |
| 282 |
@cppdef ecl_make_fixnum |
| 283 |
@cppdef ecl_make_integer |
| 284 |
@cppdef ecl_make_unsigned_integer |
| 285 |
@cppdef ecl_make_single_float |
| 286 |
@cppdef ecl_make_double_float |
| 287 |
@cppdef ecl_make_long_float |
| 288 |
@cppdef ecl_make_csfloat |
| 289 |
@cppdef ecl_make_cdfloat |
| 290 |
@cppdef ecl_make_clfloat |
| 291 |
@cppdef ecl_make_uint8_t |
| 292 |
@cppdef ecl_make_int8_t |
| 293 |
@cppdef ecl_make_uint16_t |
| 294 |
@cppdef ecl_make_int16_t |
| 295 |
@cppdef ecl_make_uint32_t |
| 296 |
@cppdef ecl_make_int32_t |
| 297 |
@cppdef ecl_make_uint64_t |
| 298 |
@cppdef ecl_make_int64_t |
| 299 |
@cppdef ecl_make_short_t |
| 300 |
@cppdef ecl_make_ushort_t |
| 301 |
@cppdef ecl_make_int |
| 302 |
@cppdef ecl_make_uint |
| 303 |
@cppdef ecl_make_long |
| 304 |
@cppdef ecl_make_ulong |
| 305 |
@cppdef ecl_make_long_long |
| 306 |
@cppdef ecl_make_ulong_long |
| 307 |
@cppdef ecl_make_ratio |
| 308 |
@cppdef ecl_make_complex |
| 309 |
|
| 310 |
@deftypefun cl_object ecl_make_fixnum (cl_fixnum n) |
| 311 |
@deftypefunx cl_object ecl_make_integer (cl_fixnum n) |
| 312 |
@deftypefunx cl_object ecl_make_unsigned_integer (cl_index n) |
| 313 |
@deftypefunx cl_object ecl_make_single_float (float n) |
| 314 |
@deftypefunx cl_object ecl_make_double_float (double n) |
| 315 |
@deftypefunx cl_object ecl_make_long_float (long double n) |
| 316 |
@deftypefunx cl_object ecl_make_csfloat (float _Complex n) |
| 317 |
@deftypefunx cl_object ecl_make_cdfloat (double _Complex n) |
| 318 |
@deftypefunx cl_object ecl_make_clfloat (long double _Complex n) |
| 319 |
@deftypefunx cl_object ecl_make_uint8_t (uint8_t n) |
| 320 |
@deftypefunx cl_object ecl_make_int8_t (int8_t n) |
| 321 |
@deftypefunx cl_object ecl_make_uint16_t (uint16_t n) |
| 322 |
@deftypefunx cl_object ecl_make_int16_t (int16_t n) |
| 323 |
@deftypefunx cl_object ecl_make_uint32_t (uint32_t n) |
| 324 |
@deftypefunx cl_object ecl_make_int32_t (int32_t n) |
| 325 |
@deftypefunx cl_object ecl_make_uint64_t (uint64_t n) |
| 326 |
@deftypefunx cl_object ecl_make_int64_t (int64_t n) |
| 327 |
@deftypefunx cl_object ecl_make_short_t (short n) |
| 328 |
@deftypefunx cl_object ecl_make_ushort_t (unsigned short n) |
| 329 |
@deftypefunx cl_object ecl_make_int (int n) |
| 330 |
@deftypefunx cl_object ecl_make_uint (unsigned int n) |
| 331 |
@deftypefunx cl_object ecl_make_long (long n) |
| 332 |
@deftypefunx cl_object ecl_make_ulong (unsigned long n) |
| 333 |
@deftypefunx cl_object ecl_make_long_long (long long n) |
| 334 |
@deftypefunx cl_object ecl_make_ulong_long (unsigned long long n) |
| 335 |
@deftypefunx cl_object ecl_make_ratio (cl_object numerator, cl_object denominator) |
| 336 |
@deftypefunx cl_object ecl_make_complex (cl_object real, cl_object imag) |
| 337 |
|
| 338 |
@paragraph Description |
| 339 |
These functions create a Lisp object from the corresponding C |
| 340 |
number. If the number is an integer type, the result will always be an |
| 341 |
integer, which may be a bignum. If on the other hand the C number is a |
| 342 |
float, double or long double, the result will be a float. |
| 343 |
|
| 344 |
There is some redundancy in the list of functions that convert from |
| 345 |
cl_fixnum and cl_index to lisp. On the one hand, |
| 346 |
@coderef{ecl_make_fixnum} always creates a fixnum, dropping bits if |
| 347 |
necessary. On the other hand, @coderef{ecl_make_integer} and |
| 348 |
@coderef{ecl_make_unsigned_integer} faithfully convert to a Lisp |
| 349 |
integer, which may be a bignum. |
| 350 |
|
| 351 |
Note also that some of the constructors do not use C numbers. This is |
| 352 |
the case of @coderef{ecl_make_ratio} and @coderef{ecl_make_complex}, |
| 353 |
because they are composite Lisp types. When c99 complex float support is |
| 354 |
built in @coderef{ecl_make_complex} will use C number for float types. |
| 355 |
|
| 356 |
These functions or macros signal no errors. |
| 357 |
@end deftypefun |
| 358 |
|
| 359 |
@node Numbers - Number accessors |
| 360 |
@subsubsection Number accessors |
| 361 |
Unchecked conversion from Lisp types to C numbers |
| 362 |
|
| 363 |
@subsubheading Functions |
| 364 |
@cppdef ecl_fixnum |
| 365 |
@cppdef ecl_single_float |
| 366 |
@cppdef ecl_double_float |
| 367 |
@cppdef ecl_long_float |
| 368 |
@cppdef ecl_csfloat |
| 369 |
@cppdef ecl_cdfloat |
| 370 |
@cppdef ecl_clfloat |
| 371 |
|
| 372 |
@deftypefun cl_fixnum ecl_fixnum (cl_object n) |
| 373 |
@deftypefunx float ecl_single_float (cl_object n) |
| 374 |
@deftypefunx double ecl_double_float (cl_object n) |
| 375 |
@deftypefunx {long double} ecl_long_float (cl_object n) |
| 376 |
@deftypefunx {float _Complex} ecl_csfloat (cl_object n) |
| 377 |
@deftypefunx {double _Complex} ecl_cdfloat (cl_object n) |
| 378 |
@deftypefunx {long double _Complex} ecl_clfloat (cl_object n) |
| 379 |
|
| 380 |
@paragraph Description |
| 381 |
These functions and macros extract a C number from a Lisp object. They do not check the type of the Lisp object as they typically just access directly the value from a C structure. |
| 382 |
@end deftypefun |
| 383 |
|
| 384 |
@node Numbers - Number coercion |
| 385 |
@subsubsection Number coercion |
| 386 |
Checked conversion from Lisp types to C numbers |
| 387 |
|
| 388 |
@subsubheading Functions |
| 389 |
@cppdef ecl_to_fixnum |
| 390 |
@cppdef ecl_to_unsigned_integer |
| 391 |
@cppdef ecl_to_float |
| 392 |
@cppdef ecl_to_double |
| 393 |
@cppdef ecl_to_long_double |
| 394 |
@cppdef ecl_to_csfloat |
| 395 |
@cppdef ecl_to_cdfloat |
| 396 |
@cppdef ecl_to_clfloat |
| 397 |
@cppdef ecl_to_uint8_t |
| 398 |
@cppdef ecl_to_int8_t |
| 399 |
@cppdef ecl_to_uint16_t |
| 400 |
@cppdef ecl_to_int16_t |
| 401 |
@cppdef ecl_to_uint32_t |
| 402 |
@cppdef ecl_to_int32_t |
| 403 |
@cppdef ecl_to_uint64_t |
| 404 |
@cppdef ecl_to_int64_t |
| 405 |
@cppdef ecl_to_short |
| 406 |
@cppdef ecl_to_ushort |
| 407 |
@cppdef ecl_to_int |
| 408 |
@cppdef ecl_to_uint |
| 409 |
@cppdef ecl_to_long |
| 410 |
@cppdef ecl_to_ulong |
| 411 |
@cppdef ecl_to_long_long |
| 412 |
@cppdef ecl_to_ulong_long |
| 413 |
|
| 414 |
@deftypefun cl_fixnum ecl_to_fixnum (cl_object n); |
| 415 |
@deftypefunx cl_index ecl_to_unsigned_integer (cl_object n); |
| 416 |
@deftypefunx float ecl_to_float (cl_object n); |
| 417 |
@deftypefunx double ecl_to_double (cl_object n); |
| 418 |
@deftypefunx {long double} ecl_to_long_double (cl_object n); |
| 419 |
@deftypefunx {float _Complex} ecl_to_csfloat (cl_object n); |
| 420 |
@deftypefunx {double _Complex} ecl_to_cdfloat (cl_object n); |
| 421 |
@deftypefunx {long double _Complex} ecl_to_clfloat (cl_object n); |
| 422 |
@deftypefunx uint8_t ecl_to_uint8_t (cl_object n); |
| 423 |
@deftypefunx int8_t ecl_to_int8_t (cl_object n); |
| 424 |
@deftypefunx uint16_t ecl_to_uint16_t (cl_object n); |
| 425 |
@deftypefunx int16_t ecl_to_int16_t (cl_object n); |
| 426 |
@deftypefunx uint32_t ecl_to_uint32_t (cl_object n); |
| 427 |
@deftypefunx int32_t ecl_to_int32_t (cl_object n); |
| 428 |
@deftypefunx uint64_t ecl_to_uint64_t (cl_object n); |
| 429 |
@deftypefunx int64_t ecl_to_int64_t (cl_object n); |
| 430 |
@deftypefunx short ecl_to_short (cl_object n); |
| 431 |
@deftypefunx {unsigned short} ecl_to_ushort (cl_object n); |
| 432 |
@deftypefunx int ecl_to_int (cl_object n); |
| 433 |
@deftypefunx {unsigned int} ecl_to_uint (cl_object n); |
| 434 |
@deftypefunx long ecl_to_long (cl_object n); |
| 435 |
@deftypefunx {unsigned long} ecl_to_ulong (cl_object n); |
| 436 |
@deftypefunx {long long} ecl_to_long_long (cl_object n); |
| 437 |
@deftypefunx {unsigned long long} ecl_to_ulong_long (cl_object n); |
| 438 |
|
| 439 |
@paragraph Description |
| 440 |
These functions and macros convert a Lisp object to the corresponding |
| 441 |
C number type. The conversion is done through a coercion process which |
| 442 |
may signal an error if the argument does not fit the expected type. |
| 443 |
@end deftypefun |
| 444 |
|
| 445 |
@node Numbers - ANSI dictionary |
| 446 |
@subsubsection ANSI dictionary |
| 447 |
Common Lisp and C equivalence |
| 448 |
|
| 449 |
@multitable @columnfractions .30 .70 |
| 450 |
@headitem Lisp symbol @tab C function |
| 451 |
@item @clhs{f_eq_sle.htm,=} @tab cl_object cl_E(cl_narg narg, ...) |
| 452 |
@item @clhs{f_eq_sle.htm,/=} @tab cl_object cl_NE(cl_narg narg, ...) |
| 453 |
@item @clhs{f_eq_sle.htm,<} @tab cl_object cl_L(cl_narg narg, ...) |
| 454 |
@item @clhs{f_eq_sle.htm,>} @tab cl_object cl_G(cl_narg narg, ...) |
| 455 |
@item @clhs{f_eq_sle.htm,<=} @tab cl_object cl_LE(cl_narg narg, ...) |
| 456 |
@item @clhs{f_eq_sle.htm,>=} @tab cl_object cl_GE(cl_narg narg, ...) |
| 457 |
@item @clhs{f_max_m.htm,max} @tab cl_object cl_max(cl_narg narg, ...) |
| 458 |
@item @clhs{f_max_m.htm,min} @tab cl_object cl_min(cl_narg narg, ...) |
| 459 |
@item @clhs{f_minusp.htm,minusp} @tab cl_object cl_minusp(cl_object real) |
| 460 |
@item @clhs{f_minusp.htm,plusp} @tab cl_object cl_plusp(cl_object real) |
| 461 |
@item @clhs{f_zerop.htm,zerop} @tab cl_object cl_zerop(cl_object number) |
| 462 |
@item @clhs{f_floorc.htm,floor} @tab cl_object cl_floor(cl_narg narg, cl_object number, ...) |
| 463 |
@item @clhs{f_floorc.htm,ffloor} @tab cl_object cl_ffloor(cl_narg narg, cl_object number, ...) |
| 464 |
@item @clhs{f_floorc.htm,ceiling} @tab cl_object cl_ceiling(cl_narg narg, cl_object number, ...) |
| 465 |
@item @clhs{f_floorc.htm,fceiling} @tab cl_object cl_fceiling(cl_narg narg, cl_object number, ...) |
| 466 |
@item @clhs{f_floorc.htm,truncate} @tab cl_object cl_truncate(cl_narg narg, cl_object number, ...) |
| 467 |
@item @clhs{f_floorc.htm,ftruncate} @tab cl_object cl_ftruncate(cl_narg narg, cl_object number, ...) |
| 468 |
@item @clhs{f_floorc.htm,round} @tab cl_object cl_round(cl_narg narg, cl_object number, ...) |
| 469 |
@item @clhs{f_floorc.htm,fround} @tab cl_object cl_fround(cl_narg narg, cl_object number, ...) |
| 470 |
@item @clhs{f_sin_c.htm,sin} @tab cl_object cl_sin(cl_object radians) |
| 471 |
@item @clhs{f_sin_c.htm,cos} @tab cl_object cl_cos(cl_object radians) |
| 472 |
@item @clhs{f_sin_c.htm,tan} @tab cl_object cl_tan(cl_object radians) |
| 473 |
@item @clhs{f_asin_.htm,asin} @tab cl_object cl_asin(cl_object number) |
| 474 |
@item @clhs{f_asin_.htm,acos} @tab cl_object cl_acos(cl_object number) |
| 475 |
@item @clhs{f_asin_.htm,atan} @tab cl_object cl_atan(cl_narg narg, cl_object number1, ...) |
| 476 |
@item @clhs{c_number.htm,sinh} @tab cl_object cl_sinh(cl_object number) |
| 477 |
@item @clhs{c_number.htm,cosh} @tab cl_object cl_cosh(cl_object number) |
| 478 |
@item @clhs{c_number.htm,tanh} @tab cl_object cl_tanh(cl_object number) |
| 479 |
@item @clhs{c_number.htm,asinh} @tab cl_object cl_asinh(cl_object number) |
| 480 |
@item @clhs{c_number.htm,acosh} @tab cl_object cl_acosh(cl_object number) |
| 481 |
@item @clhs{c_number.htm,atanh} @tab cl_object cl_atanh(cl_object number) |
| 482 |
@item @clhs{f_st.htm,*} @tab cl_object cl_X(cl_narg narg, ...) |
| 483 |
@item @clhs{f_pl.htm,+} @tab cl_object cl_P(cl_narg narg, ...) |
| 484 |
@item @clhs{f__.htm,-} @tab cl_object cl_M(cl_narg narg, cl_object number, ...) |
| 485 |
@item @clhs{f_sl.htm,/} @tab cl_object cl_N(cl_narg narg, cl_object number, ...) |
| 486 |
@item @clhs{f_1pl_1_.htm,1+} @tab cl_object cl_1P(cl_object number) |
| 487 |
@item @clhs{f_1pl_1_.htm,1-} @tab cl_object cl_1M(cl_object number) |
| 488 |
@item @clhs{f_abs.htm,abs} @tab cl_object cl_abs(cl_object number) |
| 489 |
@item @clhs{f_evenpc.htm,evenp} @tab cl_object cl_evenp(cl_object integer) |
| 490 |
@item @clhs{f_evenpc.htm,oddp} @tab cl_object cl_oddp(cl_object integer) |
| 491 |
@item @clhs{f_exp_e.htm,exp} @tab cl_object cl_exp(cl_object number) |
| 492 |
@item @clhs{f_exp_e.htm,expt} @tab cl_object cl_expt(cl_object base, cl_object power) |
| 493 |
@item @clhs{f_gcd.htm,gcd} @tab cl_object cl_gcd(cl_narg narg, ...) |
| 494 |
@item @clhs{f_lcm.htm,lcm} @tab cl_object cl_lcm(cl_narg narg, ...) |
| 495 |
@item @clhs{f_log.htm,log} @tab cl_object cl_log(cl_narg narg, cl_object number, ...) |
| 496 |
@item @clhs{f_mod_r.htm,mod} @tab cl_object cl_mod(cl_object number, cl_object divisor) |
| 497 |
@item @clhs{f_mod_r.htm,rem} @tab cl_object cl_rem(cl_object number, cl_object divisor) |
| 498 |
@item @clhs{f_signum.htm,signum} @tab cl_object cl_signum(cl_object number) |
| 499 |
@item @clhs{f_sqrt_.htm,sqrt} @tab cl_object cl_sqrt(cl_object number) |
| 500 |
@item @clhs{f_sqrt.htm,isqrt} @tab cl_object cl_isqrt(cl_object natural) |
| 501 |
@item @clhs{f_mk_rnd.htm,make-random-state} @tab cl_object cl_make_random_state(cl_narg narg, ...) |
| 502 |
@item @clhs{f_random.htm,random} @tab cl_object cl_random(cl_narg narg, cl_object limit, ...) |
| 503 |
@item @clhs{f_rnd_st.htm,random-state-p} @tab cl_object cl_random_state_p(cl_object object) |
| 504 |
@item @clhs{f_nump.htm,numberp} @tab cl_object cl_numberp(cl_object object) |
| 505 |
@item @clhs{f_cis.htm,cis} @tab cl_object cl_cis(cl_object radians) |
| 506 |
@item @clhs{f_comp_2.htm,complex} @tab cl_object cl_complex(cl_narg narg, cl_object realpart, ...) |
| 507 |
@item @clhs{f_comp_3.htm,complexp} @tab cl_object cl_complexp(cl_object object) |
| 508 |
@item @clhs{f_conjug.htm,conjugate} @tab cl_object cl_conjugate(cl_object number) |
| 509 |
@item @clhs{f_phase.htm,phase} @tab cl_object cl_phase(cl_object number) |
| 510 |
@item @clhs{f_realpa.htm,realpart} @tab cl_object cl_realpart(cl_object number) |
| 511 |
@item @clhs{f_realpa.htm,imagpart} @tab cl_object cl_imagpart(cl_object number) |
| 512 |
@item @clhs{f_upgrad.htm,upgraded-complex-part-type} @tab cl_object cl_upgraded_complex_part_type(cl_narg narg, cl_object typespec, ...) |
| 513 |
@item @clhs{f_realp.htm,realp} @tab cl_object cl_realp(cl_object object) |
| 514 |
@item @clhs{f_numera.htm,numerator} @tab cl_object cl_numerator(cl_object rational) |
| 515 |
@item @clhs{f_numera.htm,denominator} @tab cl_object cl_denominator(cl_object rational) |
| 516 |
@item @clhs{f_ration.htm,rational} @tab cl_object cl_rational(cl_object number) |
| 517 |
@item @clhs{f_ration.htm,rationalize} @tab cl_object cl_rationalize(cl_object number) |
| 518 |
@item @clhs{f_rati_1.htm,rationalp} @tab cl_object cl_rationalp(cl_object object) |
| 519 |
@item @clhs{f_ash.htm,ash} @tab cl_object cl_ash(cl_object integer, cl_object count) |
| 520 |
@item @clhs{f_intege.htm,integer-length} @tab cl_object cl_integer_length(cl_object integer) |
| 521 |
@item @clhs{f_inte_1.htm,integerp} @tab cl_object cl_integerp(cl_object object) |
| 522 |
@item @clhs{f_parse_.htm,parse-integer} @tab cl_object cl_parse_integer(cl_narg narg, cl_object string, ...) |
| 523 |
@item @clhs{f_boole.htm,boole} @tab cl_object cl_boole(cl_object op, cl_object integer1, cl_object integer2) |
| 524 |
@item @clhs{f_logand.htm,logand} @tab cl_object cl_logand(cl_narg narg, ...) |
| 525 |
@item @clhs{f_logand.htm,logandc1} @tab cl_object cl_logandc1(cl_object integer1, cl_object integer2) |
| 526 |
@item @clhs{f_logand.htm,logandc2} @tab cl_object cl_logandc2(cl_object integer1, cl_object integer2) |
| 527 |
@item @clhs{f_logand.htm,logeqv} @tab cl_object cl_logeqv(cl_narg narg, ...) |
| 528 |
@item @clhs{f_logand.htm,logior} @tab cl_object cl_logior(cl_narg narg, ...) |
| 529 |
@item @clhs{f_logand.htm,lognand} @tab cl_object cl_lognand(cl_object integer1, cl_object integer2) |
| 530 |
@item @clhs{f_logand.htm,lognor} @tab cl_object cl_lognor(cl_object integer1, cl_object integer2) |
| 531 |
@item @clhs{f_logand.htm,lognot} @tab cl_object cl_lognot(cl_object integer) |
| 532 |
@item @clhs{f_logand.htm,logorc1} @tab cl_object cl_logorc1(cl_object integer1, cl_object integer2) |
| 533 |
@item @clhs{f_logand.htm,logorc2} @tab cl_object cl_logorc2(cl_object integer1, cl_object integer2) |
| 534 |
@item @clhs{f_logand.htm,logxor} @tab cl_object cl_logxor(cl_narg narg, ...) |
| 535 |
@item @clhs{f_logbtp.htm,logbitp} @tab cl_object cl_logbitp(cl_object index, cl_object integer) |
| 536 |
@item @clhs{f_logcou.htm,logcount} @tab cl_object cl_logcount(cl_object integer) |
| 537 |
@item @clhs{f_logtes.htm,logtest} @tab cl_object cl_logtest(cl_object integer1, cl_object integer2) |
| 538 |
@item @clhs{f_by_by.htm,byte} @tab cl_object cl_byte(cl_object size, cl_object position) |
| 539 |
@item @clhs{f_by_by.htm,bytes-size} @tab cl_object cl_byte_size(cl_object bytespec) |
| 540 |
@item @clhs{f_by_by.htm,byte-position} @tab cl_object cl_byte_position(cl_object bytespec) |
| 541 |
@item @clhs{f_deposi.htm,deposit-field} @tab cl_object cl_deposit_field(cl_object newbyte, cl_object bytespec, cl_object integer) |
| 542 |
@item @clhs{f_dpb.htm,dpb} @tab cl_object cl_dpb(cl_object newbyte, cl_object bytespec, cl_object integer) |
| 543 |
@item @clhs{f_ldb.htm,ldb} @tab cl_object cl_ldb(cl_object bytespec, cl_object integer) |
| 544 |
@item @clhs{f_ldb_te.htm,ldb-test} @tab cl_object cl_ldb_test(cl_object bytespec, cl_object integer) |
| 545 |
@item @clhs{f_mask_f.htm,mask-field} @tab cl_object cl_mask_field(cl_object bytespec, cl_object integer) |
| 546 |
@item @clhs{f_dec_fl.htm,decode-float} @tab cl_object cl_decode_float(cl_object float) |
| 547 |
@item @clhs{f_dec_fl.htm,scale-float} @tab cl_object cl_scale_float(cl_object float, cl_object integer) |
| 548 |
@item @clhs{f_dec_fl.htm,float-radix} @tab cl_object cl_float_radix(cl_object float) |
| 549 |
@item @clhs{f_dec_fl.htm,float-sign} @tab cl_object cl_float_sign(cl_narg narg, cl_object float1, ...) |
| 550 |
@item @clhs{f_dec_fl.htm,float-digits} @tab cl_object cl_float_digits(cl_object float) |
| 551 |
@item @clhs{f_dec_fl.htm,float-precision} @tab cl_object cl_float_precision(cl_object float) |
| 552 |
@item @clhs{f_dec_fl.htm,integer-decode-float} @tab cl_object cl_integer_decode_float(cl_object float) |
| 553 |
@item @clhs{f_float.htm,float} @tab cl_object cl_float(cl_narg narg, cl_object number, ...) |
| 554 |
@item @clhs{f_floatp.htm,floatp} @tab cl_object cl_floatp(cl_object object) |
| 555 |
@item @clhs{f_arithm.htm,arithmetic-error-operands} @tab [Only in Common Lisp] |
| 556 |
@item @clhs{f_arithm.htm,arithmetic-error-operation} @tab [Only in Common Lisp] |
| 557 |
@end multitable |