1996-07-25 22:56:11 +00:00
|
|
|
|
/* classes: h_files */
|
|
|
|
|
|
|
2001-07-30 19:35:15 +00:00
|
|
|
|
#ifndef SCM_NUMBERS_H
|
|
|
|
|
|
#define SCM_NUMBERS_H
|
2001-08-31 12:13:50 +00:00
|
|
|
|
|
2011-01-25 18:58:47 -05:00
|
|
|
|
/* Copyright (C) 1995,1996,1998,2000,2001,2002,2003,2004,2005, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
2001-08-31 12:13:50 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
|
|
* as published by the Free Software Foundation; either version 3 of
|
|
|
|
|
|
* the License, or (at your option) any later version.
|
2001-08-31 12:13:50 +00:00
|
|
|
|
*
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* This library is distributed in the hope that it will be useful, but
|
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
* Lesser General Public License for more details.
|
2001-08-31 12:13:50 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
|
* 02110-1301 USA
|
2003-04-05 19:15:35 +00:00
|
|
|
|
*/
|
1999-12-16 03:46:42 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2004-09-21 00:42:30 +00:00
|
|
|
|
#include <gmp.h>
|
|
|
|
|
|
|
* alist.h, append.h, arbiters.h, async.h, boolean.h, chars.h,
continuations.h, debug.h, dynwind.h, error.h, eval.h, fdsocket.h,
feature.h, filesys.h, fports.h, gc.h, gdbint.h, genio.h, gsubr.h,
hash.h, init.h, ioext.h, kw.h, list.h, markers.h, marksweep.h,
mbstrings.h, numbers.h, objprop.h, options.h, pairs.h, ports.h,
posix.h, print.h, procprop.h, procs.h, ramap.h, read.h, root.h,
sequences.h, smob.h, socket.h, srcprop.h, stackchk.h, stime.h,
strings.h, strop.h, strorder.h, strports.h, struct.h, symbols.h,
tag.h, throw.h, unif.h, variable.h, vectors.h, version.h,
vports.h, weaks.h: #include "libguile/__scm.h", not
<libguile/__scm.h>. This allows 'gcc -MM' to determine which
dependencies are within libguile properly.
1996-09-05 21:19:08 +00:00
|
|
|
|
#include "libguile/__scm.h"
|
1999-01-10 07:38:05 +00:00
|
|
|
|
#include "libguile/print.h"
|
|
|
|
|
|
|
Add full Unicode capability to ports and the default reader
Ports are given two additional properties: a character encoding and
a conversion failure strategy. These properties have getters and setters.
The new properties are used to convert any locale text to/from the
internal representation of strings.
If unspecified, ports use a default value. The default value of these
properties is held in a fluid. The default character encoding can be
modified by calling setlocale.
ISO-8859-1 is treated specially. Since it is a native encoding of
strings, it can be processed more quickly. Source code is assumed to be
ISO-8859-1 unless otherwise specified. The encoding of a source code
file can be given as 'coding: XXXXX' in a magic comment at the top of a
file.
The C functions that deal with encoding often use a null pointer
as shorthand for the native Latin-1 encoding, for efficiency's sake.
* test-suite/tests/encoding-iso88591.test: new tests
* test-suite/tests/encoding-iso88597.test: new tests
* test-suite/tests/encoding-utf8.test: new tests
* test-suite/tests/encoding-escapes.test: new tests
* test-suite/tests/numbers.test: declare 'binary' encoding
* test-suite/tests/ports.test: declare 'binary' encoding
* test-suite/tests/r6rs-ports.test: declare 'binary' encoding
* module/system/base/compile.scm (compile-file): use source-code
file's self-declared encoding when compiling files
* libguile/strports.c: store string ports in locale encoding
(scm_strport_to_locale_u8vector, scm_call_with_output_locale_u8vector)
(scm_open_input_locale_u8vector, scm_get_output_locale_u8vector):
new functions
* libguile/strings.h: new declaration for scm_i_string_contains_char
* libguile/strings.c (scm_i_string_contains_char): new function
(scm_from_stringn, scm_to_stringn): use NULL for Latin-1
(scm_from_locale_stringn, scm_to_locale_stringn): respect character
encoding of input and output ports
* libguile/read.h: declaration for scm_scan_for_encoding
* libguile/read.c:
(read_token): now takes scheme string instead of C string/length
(read_complete_token): new function
(scm_read_sexp, scm_read_number, scm_read_mixed_case_symbol)
(scm_read_number_and_radix, scm_read_quote, scm_read_semicolon_comment)
(scm_read_srfi4_vector, scm_read_bytevector, scm_read_guile_bit_vector)
(scm_read_scsh_block_comment, scm_read_commented_expression)
(scm_read_extended_symbol, scm_read_sharp_extension, scm_read_shart)
(scm_read_expression): use scm_t_wchar for char type, use read_complete_token
(scm_scan_for_encoding): new function to find a file's character encoding
(scm_file_encoding): new function to find a port's character encoding
* libguile/rdelim.c: don't unpack strings
* libguile/print.h: declaration for modified function
scm_i_charprint
* libguile/print.c: use locale when printing characters and
strings
(scm_i_charprint): input parameter is now scm_t_wchar
(scm_simple_format): don't unpack strings
* libguile/posix.h: new declaration for scm_setbinary.
* libguile/posix.c (scm_setlocale): set default and stdio port
encodings based on the locale's character encoding
(scm_setbinary): new function
* libguile/ports.h (scm_t_port): add encoding and failed
conversion handler to port type. Declarations for new or modified
functions scm_getc, scm_unget_byte, scm_ungetc,
scm_i_get_port_encoding, scm_i_set_port_encoding_x,
scm_port_encoding, scm_set_port_encoding_x,
scm_i_get_conversion_strategy, scm_i_set_conversion_strategy_x,
scm_port_conversion_strategy, scm_set_port_conversion_strategy_x.
* libguile/ports.c: assign the current ports to zero on startup so
we can see if they've been set.
(scm_current_input_port, scm_current_output_port,
scm_current_error_port): return #f if the port is not yet
initialized
(scm_new_port_table_entry): set up a new port's encoding and
illegal sequence handler based on the thread's current defaults
(scm_i_remove_port): free port encoding name when port is removed
(scm_i_mode_bits_n): now takes a scheme string instead of a c
string and length. All callers changed.
(SCM_MBCHAR_BUF_SIZE): new const
(scm_getc): new function, since the scm_getc in inline.h is now
scm_get_byte_or_eof. This pulls one codepoint from a port.
(scm_lfwrite_substr, scm_lfwrite_str): now uses port's encoding
(scm_unget_byte): new function, incorportaing the low-level functionality
of scm_ungetc
(scm_ungetc): uses scm_unget_byte
* libguile/numbers.h (scm_t_wchar): compilation order problem with
scm_t_wchar being use in functions in multiple headers. Forward
declare scm_t_wchar.
* libguile/load.c (scm_primitive_load): scan for file encoding at
top of file and use it to set the load port's encoding
* libguile/inline.h (scm_get_byte_or_eof): new function
incorporating most of the functionality of scm_getc.
* libguile/fports.c (fport_fill_input): now returns scm_t_wchar
* libguile/chars.h (scm_t_wchar): avoid compilation order problem
with declaration of scm_t_wchar
2009-08-25 07:54:37 -07:00
|
|
|
|
#ifndef SCM_T_WCHAR_DEFINED
|
|
|
|
|
|
typedef scm_t_int32 scm_t_wchar;
|
|
|
|
|
|
#define SCM_T_WCHAR_DEFINED
|
|
|
|
|
|
#endif /* SCM_T_WCHAR_DEFINED */
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2001-10-05 17:43:49 +00:00
|
|
|
|
/* Immediate Numbers, also known as fixnums
|
1996-07-25 22:56:11 +00:00
|
|
|
|
*
|
2001-10-05 17:43:49 +00:00
|
|
|
|
* Inums are exact integer data that fits within an SCM word. */
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-10-06 20:48:27 +00:00
|
|
|
|
/* SCM_T_SIGNED_MAX is (- (expt 2 n) 1),
|
|
|
|
|
|
* SCM_MOST_POSITIVE_FIXNUM should be (- (expt 2 (- n 2)) 1)
|
|
|
|
|
|
* which is the same as (/ (- (expt 2 n) 4) 4)
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2001-10-06 19:58:02 +00:00
|
|
|
|
#define SCM_I_FIXNUM_BIT (SCM_LONG_BIT - 2)
|
2001-10-06 20:48:27 +00:00
|
|
|
|
#define SCM_MOST_POSITIVE_FIXNUM ((SCM_T_SIGNED_BITS_MAX-3)/4)
|
2001-10-06 19:58:02 +00:00
|
|
|
|
#define SCM_MOST_NEGATIVE_FIXNUM (-SCM_MOST_POSITIVE_FIXNUM-1)
|
2001-01-18 13:35:45 +00:00
|
|
|
|
|
2000-05-16 12:11:08 +00:00
|
|
|
|
/* SCM_SRS is signed right shift */
|
|
|
|
|
|
#if (-1 == (((-1) << 2) + 2) >> 2)
|
2001-10-05 17:43:49 +00:00
|
|
|
|
# define SCM_SRS(x, y) ((x) >> (y))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
#else
|
2001-10-05 17:43:49 +00:00
|
|
|
|
# define SCM_SRS(x, y) ((x) < 0 ? ~((~(x)) >> (y)) : ((x) >> (y)))
|
2000-05-16 12:11:08 +00:00
|
|
|
|
#endif /* (-1 == (((-1) << 2) + 2) >> 2) */
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2004-07-23 15:29:27 +00:00
|
|
|
|
#define SCM_I_INUMP(x) (2 & SCM_UNPACK (x))
|
|
|
|
|
|
#define SCM_I_NINUMP(x) (!SCM_I_INUMP (x))
|
2004-07-08 15:41:48 +00:00
|
|
|
|
#define SCM_I_MAKINUM(x) \
|
2003-09-04 20:04:30 +00:00
|
|
|
|
(SCM_PACK ((((scm_t_signed_bits) (x)) << 2) + scm_tc2_int))
|
2004-07-23 15:29:27 +00:00
|
|
|
|
#define SCM_I_INUM(x) (SCM_SRS ((scm_t_signed_bits) SCM_UNPACK (x), 2))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2000-05-25 13:53:49 +00:00
|
|
|
|
/* SCM_FIXABLE is true if its long argument can be encoded in an SCM_INUM. */
|
|
|
|
|
|
#define SCM_POSFIXABLE(n) ((n) <= SCM_MOST_POSITIVE_FIXNUM)
|
|
|
|
|
|
#define SCM_NEGFIXABLE(n) ((n) >= SCM_MOST_NEGATIVE_FIXNUM)
|
2001-10-05 17:43:49 +00:00
|
|
|
|
#define SCM_FIXABLE(n) (SCM_POSFIXABLE (n) && SCM_NEGFIXABLE (n))
|
2000-05-25 13:53:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
2011-01-25 18:58:47 -05:00
|
|
|
|
#define SCM_INUM0 (SCM_I_MAKINUM (0)) /* A name for 0 */
|
|
|
|
|
|
#define SCM_INUM1 (SCM_I_MAKINUM (1)) /* A name for 1 */
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-10-06 20:48:27 +00:00
|
|
|
|
/* SCM_MAXEXP is the maximum double precision exponent
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
* SCM_FLTMAX is less than or scm_equal the largest single precision float
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2003-03-27 20:09:18 +00:00
|
|
|
|
#if SCM_HAVE_STDC_HEADERS
|
|
|
|
|
|
# ifndef GO32
|
2003-05-30 09:39:34 +00:00
|
|
|
|
# include <float.h>
|
|
|
|
|
|
# ifdef __MINGW32__
|
|
|
|
|
|
# define copysign _copysign
|
|
|
|
|
|
# define finite _finite
|
|
|
|
|
|
# endif /* __MINGW32__ */
|
2003-03-27 20:09:18 +00:00
|
|
|
|
# endif /* ndef GO32 */
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
#endif /* def STDC_HEADERS */
|
2003-03-27 20:09:18 +00:00
|
|
|
|
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
#ifdef DBL_MAX_10_EXP
|
2003-03-27 20:09:18 +00:00
|
|
|
|
# define SCM_MAXEXP DBL_MAX_10_EXP
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
#else
|
2003-03-27 20:09:18 +00:00
|
|
|
|
# define SCM_MAXEXP 308 /* IEEE doubles */
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
#endif /* def DBL_MAX_10_EXP */
|
2003-03-27 20:09:18 +00:00
|
|
|
|
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
#ifdef FLT_MAX
|
2003-03-27 20:09:18 +00:00
|
|
|
|
# define SCM_FLTMAX FLT_MAX
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
#else
|
2003-03-27 20:09:18 +00:00
|
|
|
|
# define SCM_FLTMAX 1e+23
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
#endif /* def FLT_MAX */
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-10-22 13:50:39 +00:00
|
|
|
|
/* SCM_INTBUFLEN is the maximum number of characters neccessary for
|
|
|
|
|
|
* the printed or scm_string representation of an scm_t_intmax in
|
|
|
|
|
|
* radix 2. The buffer passed to scm_iint2str and scm_iuint2str must
|
|
|
|
|
|
* be of this size, for example.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
*/
|
2004-10-22 13:50:39 +00:00
|
|
|
|
#define SCM_INTBUFLEN (5 + SCM_CHAR_BIT*sizeof(scm_t_intmax))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Numbers
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
This set of patches introduces a new tc7 code scm_tc7_number for
numbers. Bignums, reals and complex numbers are turned from smobs
into subtypes of scm_tc7_number.
* tags.h (scm_tc7_number): New.
* eq.c (scm_equal_p), eval.c (SCM_CEVAL), evalext.c
(scm_self_evaluating_p), gc-card.c (scm_i_sweep_card), gc-mark.c
(scm_gc_mark_dependencies), goops.c (create_smob_classes), hash.c
(scm_hasher), numbers.c, numbers.h (SCM_NUMP), objects.c
(scm_class_of), print.c (scm_iprin1), smob.c
(scm_smob_prehistory): Don't handle bignums, reals and complex
numbers as subtypes of scm_tc7_smob any more.
* numbers.h, tags.h (scm_tc16_big, scm_tc16_real,
scm_tc16_complex): Moved definitions from tags.h to numbers.h.
2003-09-18 20:55:40 +00:00
|
|
|
|
|
|
|
|
|
|
/* Note that scm_tc16_real and scm_tc16_complex are given tc16-codes that only
|
|
|
|
|
|
* differ in one bit: This way, checking if an object is an inexact number can
|
|
|
|
|
|
* be done quickly (using the TYP16S macro). */
|
|
|
|
|
|
|
2003-09-21 07:54:23 +00:00
|
|
|
|
/* Number subtype 1 to 3 (note the dependency on the predicates SCM_INEXACTP
|
|
|
|
|
|
* and SCM_NUMP) */
|
This set of patches introduces a new tc7 code scm_tc7_number for
numbers. Bignums, reals and complex numbers are turned from smobs
into subtypes of scm_tc7_number.
* tags.h (scm_tc7_number): New.
* eq.c (scm_equal_p), eval.c (SCM_CEVAL), evalext.c
(scm_self_evaluating_p), gc-card.c (scm_i_sweep_card), gc-mark.c
(scm_gc_mark_dependencies), goops.c (create_smob_classes), hash.c
(scm_hasher), numbers.c, numbers.h (SCM_NUMP), objects.c
(scm_class_of), print.c (scm_iprin1), smob.c
(scm_smob_prehistory): Don't handle bignums, reals and complex
numbers as subtypes of scm_tc7_smob any more.
* numbers.h, tags.h (scm_tc16_big, scm_tc16_real,
scm_tc16_complex): Moved definitions from tags.h to numbers.h.
2003-09-18 20:55:40 +00:00
|
|
|
|
#define scm_tc16_big (scm_tc7_number + 1 * 256L)
|
|
|
|
|
|
#define scm_tc16_real (scm_tc7_number + 2 * 256L)
|
|
|
|
|
|
#define scm_tc16_complex (scm_tc7_number + 3 * 256L)
|
* print.c (scm_iprin1): Handle fractions.
* objects.h (scm_class_fraction): New.
* objects.c (scm_class_fraction): New.
(scm_class_of): Handle fractions.
* hash.c (scm_hasher): Handle fractions.
* numbers.c: New code for handling fraction all over the place.
(scm_odd_p, scm_even_p): Handle inexact integers.
(scm_rational_p): New function, same as scm_real_p.
(scm_round_number, scm_truncate_number, scm_ceiling, scm_floor):
New exact functions that replace the inexact 'dsubr'
implementations.
(scm_numerator, scm_denominator): New.
* numbers.h (SCM_NUMP): Recognize fractions.
(SCM_FRACTIONP, SCM_SLOPPY_FRACTIONP, SCM_FRACTION_NUMERATOR,
SCM_FRACTION_DENOMINATOR, SCM_FRACTION_SET_NUMERATOR,
SCM_FRACTION_SET_DENOMINATOR, SCM_FRACTION_REDUCED_BIT,
SCM_FRACTION_REDUCED_SET, SCM_FRACTION_REDUCED_CLEAR,
SCM_FRACTION_REDUCED): New.
(scm_floor, scm_ceiling, scm_truncate_number, scm_round_number):
New prototypes.
(scm_make_ratio, scm_rationalize, scm_numerator, scm_denominator,
scm_rational_p): New prototypes.
(scm_i_dbl2num, scm_i_fraction2double, scm_i_fraction_equalp,
scm_i_print_fraction): New prototypes.
* goops.c (create_standard_classes): Create "<fraction>" class.
* gc-mark.c (scm_gc_mark_dependencies): Handle fractions.
* gc-card.c (scm_i_sweep_card): Include scm_tc16_fraction as a
case in the switch, but do nothing for now.
* eval.c (SCM_CEVAL, SCM_APPLY, call_dsubr_1): Convert fractions
to doubles when calling 'dsubr' functions.
* eq.c (scm_eqv_p, scm_equal_p): Handle fractions.
2003-11-18 19:59:53 +00:00
|
|
|
|
#define scm_tc16_fraction (scm_tc7_number + 4 * 256L)
|
This set of patches introduces a new tc7 code scm_tc7_number for
numbers. Bignums, reals and complex numbers are turned from smobs
into subtypes of scm_tc7_number.
* tags.h (scm_tc7_number): New.
* eq.c (scm_equal_p), eval.c (SCM_CEVAL), evalext.c
(scm_self_evaluating_p), gc-card.c (scm_i_sweep_card), gc-mark.c
(scm_gc_mark_dependencies), goops.c (create_smob_classes), hash.c
(scm_hasher), numbers.c, numbers.h (SCM_NUMP), objects.c
(scm_class_of), print.c (scm_iprin1), smob.c
(scm_smob_prehistory): Don't handle bignums, reals and complex
numbers as subtypes of scm_tc7_smob any more.
* numbers.h, tags.h (scm_tc16_big, scm_tc16_real,
scm_tc16_complex): Moved definitions from tags.h to numbers.h.
2003-09-18 20:55:40 +00:00
|
|
|
|
|
2003-09-21 07:54:23 +00:00
|
|
|
|
#define SCM_INEXACTP(x) \
|
|
|
|
|
|
(!SCM_IMP (x) && (0xfeff & SCM_CELL_TYPE (x)) == scm_tc16_real)
|
2003-09-06 09:17:29 +00:00
|
|
|
|
#define SCM_REALP(x) (!SCM_IMP (x) && SCM_TYP16 (x) == scm_tc16_real)
|
|
|
|
|
|
#define SCM_COMPLEXP(x) (!SCM_IMP (x) && SCM_TYP16 (x) == scm_tc16_complex)
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
|
2001-06-14 19:50:43 +00:00
|
|
|
|
#define SCM_REAL_VALUE(x) (((scm_t_double *) SCM2PTR (x))->real)
|
2010-10-12 22:57:08 +02:00
|
|
|
|
#define SCM_COMPLEX_REAL(x) (((scm_t_complex *) SCM2PTR (x))->real)
|
|
|
|
|
|
#define SCM_COMPLEX_IMAG(x) (((scm_t_complex *) SCM2PTR (x))->imag)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2003-04-04 21:49:55 +00:00
|
|
|
|
/* Each bignum is just an mpz_t stored in a double cell starting at word 1. */
|
2004-05-06 16:42:07 +00:00
|
|
|
|
#define SCM_I_BIG_MPZ(x) (*((mpz_t *) (SCM_CELL_OBJECT_LOC((x),1))))
|
2003-04-04 21:49:55 +00:00
|
|
|
|
#define SCM_BIGP(x) (!SCM_IMP (x) && SCM_TYP16 (x) == scm_tc16_big)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-07-23 15:29:27 +00:00
|
|
|
|
#define SCM_NUMBERP(x) (SCM_I_INUMP(x) || SCM_NUMP(x))
|
2003-04-04 21:49:55 +00:00
|
|
|
|
#define SCM_NUMP(x) (!SCM_IMP(x) \
|
* print.c (scm_iprin1): Handle fractions.
* objects.h (scm_class_fraction): New.
* objects.c (scm_class_fraction): New.
(scm_class_of): Handle fractions.
* hash.c (scm_hasher): Handle fractions.
* numbers.c: New code for handling fraction all over the place.
(scm_odd_p, scm_even_p): Handle inexact integers.
(scm_rational_p): New function, same as scm_real_p.
(scm_round_number, scm_truncate_number, scm_ceiling, scm_floor):
New exact functions that replace the inexact 'dsubr'
implementations.
(scm_numerator, scm_denominator): New.
* numbers.h (SCM_NUMP): Recognize fractions.
(SCM_FRACTIONP, SCM_SLOPPY_FRACTIONP, SCM_FRACTION_NUMERATOR,
SCM_FRACTION_DENOMINATOR, SCM_FRACTION_SET_NUMERATOR,
SCM_FRACTION_SET_DENOMINATOR, SCM_FRACTION_REDUCED_BIT,
SCM_FRACTION_REDUCED_SET, SCM_FRACTION_REDUCED_CLEAR,
SCM_FRACTION_REDUCED): New.
(scm_floor, scm_ceiling, scm_truncate_number, scm_round_number):
New prototypes.
(scm_make_ratio, scm_rationalize, scm_numerator, scm_denominator,
scm_rational_p): New prototypes.
(scm_i_dbl2num, scm_i_fraction2double, scm_i_fraction_equalp,
scm_i_print_fraction): New prototypes.
* goops.c (create_standard_classes): Create "<fraction>" class.
* gc-mark.c (scm_gc_mark_dependencies): Handle fractions.
* gc-card.c (scm_i_sweep_card): Include scm_tc16_fraction as a
case in the switch, but do nothing for now.
* eval.c (SCM_CEVAL, SCM_APPLY, call_dsubr_1): Convert fractions
to doubles when calling 'dsubr' functions.
* eq.c (scm_eqv_p, scm_equal_p): Handle fractions.
2003-11-18 19:59:53 +00:00
|
|
|
|
&& (((0xfcff & SCM_CELL_TYPE (x)) == scm_tc7_number) \
|
|
|
|
|
|
|| ((0xfbff & SCM_CELL_TYPE (x)) == scm_tc7_number)))
|
|
|
|
|
|
/* 0xfcff (#b1100) for 0 free, 1 big, 2 real, 3 complex, then 0xfbff (#b1011) for 4 fraction */
|
|
|
|
|
|
|
|
|
|
|
|
#define SCM_FRACTIONP(x) (!SCM_IMP (x) && SCM_TYP16 (x) == scm_tc16_fraction)
|
2004-05-15 15:50:24 +00:00
|
|
|
|
#define SCM_FRACTION_NUMERATOR(x) (SCM_CELL_OBJECT_1 (x))
|
|
|
|
|
|
#define SCM_FRACTION_DENOMINATOR(x) (SCM_CELL_OBJECT_2 (x))
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2001-06-14 19:50:43 +00:00
|
|
|
|
typedef struct scm_t_double
|
1996-07-25 22:56:11 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM type;
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
SCM pad;
|
|
|
|
|
|
double real;
|
2001-06-14 19:50:43 +00:00
|
|
|
|
} scm_t_double;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-06-14 19:50:43 +00:00
|
|
|
|
typedef struct scm_t_complex
|
1996-07-25 22:56:11 +00:00
|
|
|
|
{
|
2010-10-12 22:57:08 +02:00
|
|
|
|
SCM type;
|
|
|
|
|
|
SCM pad;
|
* __scm.h eq.c, eval.c, gc.c, hc.h, gh_data, hash.c, numbers.c,
numbers.h, objects.c, ramap.c, random.c, unif.c, unif.h: Extensive
rewrite of handling of real and complex numbers.
(SCM_FLOATS, SCM_SINGLES): These #ifdef conditionals have been
removed along with the support for floats. (Float vectors are
still supported.)
* numbers.h (SCM_BIGSIGN): Sign moved to bit 16.
(scm_makdbl): Deprecated.
(SCM_NEWREAL, SCM_NEWCOMPLEX): New macros.
(SCM_SINGP): Deprecated.
(SCM_FLO): Removed.
(SCM_INEXP, SCM_CPLXP): Deprecated.
(SCM_INEXACTP, SCM_COMPLEXP): New macros.
(SCM_COMPLEX_REAL, SCM_COMPLEX_IMAG): Renamed from
SCM_REAL, SCM_IMAG (and now only valid for complex numbers).
(SCM_REAL, SCM_IMAG): New, *deprecated*, selectors which work both
for doubles and complex numbers.
(SCM_REAL_VALUE): New selector for doubles.
(scm_double_t, scm_complex_t): New types.
(scm_dbl): Removed.
* numbers.h (struct scm_dbl): changed to represent a double cell,
with the number in the second half.
(struct scm_cplx): new, represents a complex number as a triple
cell.
2000-03-14 06:41:25 +00:00
|
|
|
|
double real;
|
|
|
|
|
|
double imag;
|
2001-06-14 19:50:43 +00:00
|
|
|
|
} scm_t_complex;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2009-07-29 06:38:32 -07:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_exact_p (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_odd_p (SCM n);
|
|
|
|
|
|
SCM_API SCM scm_even_p (SCM n);
|
Improve extensibility of core numeric procedures
* libguile/numbers.c (scm_quotient, scm_remainder, scm_modulo,
scm_zero_p, scm_positive_p, scm_negative_p, scm_real_part,
scm_imag_part, scm_numerator, scm_denominator, scm_magnitude,
scm_angle, scm_exact_to_inexact): Change from SCM_GPROC to
SCM_PRIMITIVE_GENERIC. As a side effect, all of these procedures now
have documentation strings.
(scm_exact_p, scm_inexact_p, scm_odd_p, scm_even_p, scm_finite_p,
scm_inf_p, scm_nan_p, scm_expt, scm_inexact_to_exact, scm_log,
scm_log10, scm_exp, scm_sqrt): Change from SCM_DEFINE to
SCM_PRIMITIVE_GENERIC, and make sure the code allows these functions
to be extended in practice.
(scm_real_part, scm_imag_part, scm_numerator, scm_denominator,
scm_inexact_to_exact): Simplify type dispatch code.
(scm_sqrt): Rename formal argument from x to z, since complex numbers
are supported.
(scm_abs): Fix empty FUNC_NAME.
* libguile/numbers.h (scm_finite_p): Add missing prototype.
(scm_inf_p, scm_nan_p): Rename formal parameter from n to x, since
the domain is the real numbers.
* test-suite/tests/numbers.test: Test for documentation strings. Change
from `expect-fail' to `pass-if' for several of these, and add tests
for others. Also add other tests for `real-part' and `imag-part',
which previously had none.
2011-01-30 09:52:51 -05:00
|
|
|
|
SCM_API SCM scm_finite_p (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_inf_p (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_nan_p (SCM x);
|
2002-05-06 22:27:42 +00:00
|
|
|
|
SCM_API SCM scm_inf (void);
|
|
|
|
|
|
SCM_API SCM scm_nan (void);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_abs (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_quotient (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_remainder (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_modulo (SCM x, SCM y);
|
2011-01-31 12:03:02 -05:00
|
|
|
|
SCM_API SCM scm_euclidean_divide (SCM x, SCM y);
|
Add two new sets of fast quotient and remainder operators
* libguile/numbers.c (scm_euclidean_quo_and_rem, scm_euclidean_quotient,
scm_euclidean_remainder, scm_centered_quo_and_rem,
scm_centered_quotient, scm_centered_remainder): New extensible
procedures `euclidean/', `euclidean-quotient', `euclidean-remainder',
`centered/', `centered-quotient', `centered-remainder'.
* libguile/numbers.h: Add function prototypes.
* module/rnrs/base.scm: Remove incorrect stub implementations of `div',
`mod', `div-and-mod', `div0', `mod0', and `div0-and-mod0'. Instead do
renaming imports of `euclidean-quotient', `euclidean-remainder',
`euclidean/', `centered-quotient', `centered-remainder', and
`centered/', which are equivalent to the R6RS operators.
* module/rnrs/arithmetic/fixnums.scm (fxdiv, fxmod, fxdiv-and-mod,
fxdiv0, fxmod0, fxdiv0-and-mod0): Remove redundant checks for division
by zero and unnecessary complexity.
(fx+/carry): Remove unneeded calls to `inexact->exact'.
* module/rnrs/arithmetic/flonums.scm (fldiv, flmod, fldiv-and-mod,
fldiv0, flmod0, fldiv0-and-mod0): Remove redundant checks for division
by zero and unnecessary complexity. Remove unneeded calls to
`inexact->exact' and `exact->inexact'
* test-suite/tests/numbers.test: (test-eqv?): New internal predicate for
comparing numerical outputs with expected values.
Add extensive test code for `euclidean/', `euclidean-quotient',
`euclidean-remainder', `centered/', `centered-quotient',
`centered-remainder'.
* test-suite/tests/r6rs-arithmetic-fixnums.test: Fix some broken test
cases, and remove `unresolved' test markers for `fxdiv', `fxmod',
`fxdiv-and-mod', `fxdiv0', `fxmod0', and `fxdiv0-and-mod0'.
* test-suite/tests/r6rs-arithmetic-flonums.test: Remove `unresolved'
test markers for `fldiv', `flmod', `fldiv-and-mod', `fldiv0',
`flmod0', and `fldiv0-and-mod0'.
* doc/ref/api-data.texi (Arithmetic): Document `euclidean/',
`euclidean-quotient', `euclidean-remainder', `centered/',
`centered-quotient', and `centered-remainder'.
(Operations on Integer Values): Add cross-references to `euclidean/'
et al, from `quotient', `remainder', and `modulo'.
* doc/ref/r6rs.texi (rnrs base): Improve documentation for `div', `mod',
`div-and-mod', `div0', `mod0', and `div0-and-mod0'. Add
cross-references to `euclidean/' et al.
* NEWS: Add NEWS entry.
2011-01-30 08:48:28 -05:00
|
|
|
|
SCM_API SCM scm_euclidean_quotient (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_euclidean_remainder (SCM x, SCM y);
|
2011-01-31 12:03:02 -05:00
|
|
|
|
SCM_API SCM scm_centered_divide (SCM x, SCM y);
|
Add two new sets of fast quotient and remainder operators
* libguile/numbers.c (scm_euclidean_quo_and_rem, scm_euclidean_quotient,
scm_euclidean_remainder, scm_centered_quo_and_rem,
scm_centered_quotient, scm_centered_remainder): New extensible
procedures `euclidean/', `euclidean-quotient', `euclidean-remainder',
`centered/', `centered-quotient', `centered-remainder'.
* libguile/numbers.h: Add function prototypes.
* module/rnrs/base.scm: Remove incorrect stub implementations of `div',
`mod', `div-and-mod', `div0', `mod0', and `div0-and-mod0'. Instead do
renaming imports of `euclidean-quotient', `euclidean-remainder',
`euclidean/', `centered-quotient', `centered-remainder', and
`centered/', which are equivalent to the R6RS operators.
* module/rnrs/arithmetic/fixnums.scm (fxdiv, fxmod, fxdiv-and-mod,
fxdiv0, fxmod0, fxdiv0-and-mod0): Remove redundant checks for division
by zero and unnecessary complexity.
(fx+/carry): Remove unneeded calls to `inexact->exact'.
* module/rnrs/arithmetic/flonums.scm (fldiv, flmod, fldiv-and-mod,
fldiv0, flmod0, fldiv0-and-mod0): Remove redundant checks for division
by zero and unnecessary complexity. Remove unneeded calls to
`inexact->exact' and `exact->inexact'
* test-suite/tests/numbers.test: (test-eqv?): New internal predicate for
comparing numerical outputs with expected values.
Add extensive test code for `euclidean/', `euclidean-quotient',
`euclidean-remainder', `centered/', `centered-quotient',
`centered-remainder'.
* test-suite/tests/r6rs-arithmetic-fixnums.test: Fix some broken test
cases, and remove `unresolved' test markers for `fxdiv', `fxmod',
`fxdiv-and-mod', `fxdiv0', `fxmod0', and `fxdiv0-and-mod0'.
* test-suite/tests/r6rs-arithmetic-flonums.test: Remove `unresolved'
test markers for `fldiv', `flmod', `fldiv-and-mod', `fldiv0',
`flmod0', and `fldiv0-and-mod0'.
* doc/ref/api-data.texi (Arithmetic): Document `euclidean/',
`euclidean-quotient', `euclidean-remainder', `centered/',
`centered-quotient', and `centered-remainder'.
(Operations on Integer Values): Add cross-references to `euclidean/'
et al, from `quotient', `remainder', and `modulo'.
* doc/ref/r6rs.texi (rnrs base): Improve documentation for `div', `mod',
`div-and-mod', `div0', `mod0', and `div0-and-mod0'. Add
cross-references to `euclidean/' et al.
* NEWS: Add NEWS entry.
2011-01-30 08:48:28 -05:00
|
|
|
|
SCM_API SCM scm_centered_quotient (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_centered_remainder (SCM x, SCM y);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_gcd (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_lcm (SCM n1, SCM n2);
|
|
|
|
|
|
SCM_API SCM scm_logand (SCM n1, SCM n2);
|
|
|
|
|
|
SCM_API SCM scm_logior (SCM n1, SCM n2);
|
|
|
|
|
|
SCM_API SCM scm_logxor (SCM n1, SCM n2);
|
|
|
|
|
|
SCM_API SCM scm_logtest (SCM n1, SCM n2);
|
|
|
|
|
|
SCM_API SCM scm_logbit_p (SCM n1, SCM n2);
|
|
|
|
|
|
SCM_API SCM scm_lognot (SCM n);
|
2004-03-25 21:55:20 +00:00
|
|
|
|
SCM_API SCM scm_modulo_expt (SCM n, SCM k, SCM m);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_integer_expt (SCM z1, SCM z2);
|
|
|
|
|
|
SCM_API SCM scm_ash (SCM n, SCM cnt);
|
|
|
|
|
|
SCM_API SCM scm_bit_extract (SCM n, SCM start, SCM end);
|
|
|
|
|
|
SCM_API SCM scm_logcount (SCM n);
|
|
|
|
|
|
SCM_API SCM scm_integer_length (SCM n);
|
* validate.h
(SCM_NUM2{SIZE,PTRDIFF,SHORT,USHORT,BITS,UBITS,INT,UINT}[_DEF]):
new macros.
* unif.h: type renaming:
scm_array -> scm_array_t
scm_array_dim -> scm_array_dim_t
the old names are deprecated, all in-Guile uses changed.
* tags.h (scm_ubits_t): new typedef, representing unsigned
scm_bits_t.
* stacks.h: type renaming:
scm_info_frame -> scm_info_frame_t
scm_stack -> scm_stack_t
the old names are deprecated, all in-Guile uses changed.
* srcprop.h: type renaming:
scm_srcprops -> scm_srcprops_t
scm_srcprops_chunk -> scm_srcprops_chunk_t
the old names are deprecated, all in-Guile uses changed.
* gsubr.c, procs.c, print.c, ports.c, read.c, rdelim.c, ramap.c,
rw.c, smob.c, sort.c, srcprop.c, stacks.c, strings.c, strop.c,
strorder.c, strports.c, struct.c, symbols.c, unif.c, values.c,
vectors.c, vports.c, weaks.c:
various int/size_t -> size_t/scm_bits_t changes.
* random.h: type renaming:
scm_rstate -> scm_rstate_t
scm_rng -> scm_rng_t
scm_i_rstate -> scm_i_rstate_t
the old names are deprecated, all in-Guile uses changed.
* procs.h: type renaming:
scm_subr_entry -> scm_subr_entry_t
the old name is deprecated, all in-Guile uses changed.
* options.h (scm_option_t.val): unsigned long -> scm_bits_t.
type renaming:
scm_option -> scm_option_t
the old name is deprecated, all in-Guile uses changed.
* objects.c: various long -> scm_bits_t changes.
(scm_i_make_class_object): flags: unsigned long -> scm_ubits_t
* numbers.h (SCM_FIXNUM_BIT): deprecated, renamed to
SCM_I_FIXNUM_BIT.
* num2integral.i.c: new file, multiply included by numbers.c, used
to "templatize" the various integral <-> num conversion routines.
* numbers.c (scm_mkbig, scm_big2num, scm_adjbig, scm_normbig,
scm_copybig, scm_2ulong2big, scm_dbl2big, scm_big2dbl):
deprecated.
(scm_i_mkbig, scm_i_big2inum, scm_i_adjbig, scm_i_normbig,
scm_i_copybig, scm_i_short2big, scm_i_ushort2big, scm_i_int2big,
scm_i_uint2big, scm_i_long2big, scm_i_ulong2big, scm_i_bits2big,
scm_i_ubits2big, scm_i_size2big, scm_i_ptrdiff2big,
scm_i_long_long2big, scm_i_ulong_long2big, scm_i_dbl2big,
scm_i_big2dbl, scm_short2num, scm_ushort2num, scm_int2num,
scm_uint2num, scm_bits2num, scm_ubits2num, scm_size2num,
scm_ptrdiff2num, scm_num2short, scm_num2ushort, scm_num2int,
scm_num2uint, scm_num2bits, scm_num2ubits, scm_num2ptrdiff,
scm_num2size): new functions.
* modules.c (scm_module_reverse_lookup): i, n: int -> scm_bits_t.x
* load.c: change int -> size_t in various places (where the
variable is used to store a string length).
(search-path): call scm_done_free, not scm_done_malloc.
* list.c (scm_ilength): return a scm_bits_t, not long.
some other {int,long} -> scm_bits_t changes.
* hashtab.c: various [u]int -> scm_bits_t changes.
scm_ihashx_closure -> scm_ihashx_closure_t (and made a typedef).
(scm_ihashx): n: uint -> scm_bits_t
use scm_bits2num instead of scm_ulong2num.
* gsubr.c: various int -> scm_bits_t changes.
* gh_data.c (gh_scm2double): no loss of precision any more.
* gh.h (gh_str2scm): len: int -> size_t
(gh_{get,set}_substr): start: int -> scm_bits_t,
len: int -> size_t
(gh_<num>2scm): n: int -> scm_bits_t
(gh_*vector_length): return scm_[u]size_t, not unsigned long.
(gh_length): return scm_bits_t, not unsigned long.
* fports.h: type renaming:
scm_fport -> scm_fport_t
the old name is deprecated, all in-Guile uses changed.
* fports.c (fport_fill_input): count: int -> scm_bits_t
(fport_flush): init_size, remaining, count: int -> scm_bits_t
* debug.h (scm_lookup_cstr, scm_lookup_soft, scm_evstr): removed
those prototypes, as the functions they prototype don't exist.
* fports.c (default_buffer_size): int -> size_t
(scm_fport_buffer_add): read_size, write_size: int -> scm_bits_t
default_size: int -> size_t
(scm_setvbuf): csize: int -> scm_bits_t
* fluids.c (n_fluids): int -> scm_bits_t
(grow_fluids): old_length, i: int -> scm_bits_t
(next_fluid_num, scm_fluid_ref, scm_fluid_set_x): n: int ->
scm_bits_t
(scm_c_with_fluids): flen, vlen: int -> scm_bits_t
* filesys.c (s_scm_open_fdes): changed calls to SCM_NUM2LONG to
the new and shiny SCM_NUM2INT.
* extensions.c: extension -> extension_t (and made a typedef).
* eval.h (SCM_IFRAME): cast to scm_bits_t, not int. just so
there are no nasty surprises if/when the various deeply magic tag
bits move somewhere else.
* eval.c: changed the locals used to store results of SCM_IFRAME,
scm_ilength and such to be of type scm_bits_t (and not int/long).
(iqq): depth, edepth: int -> scm_bits_t
(scm_eval_stack): int -> scm_bits_t
(SCM_CEVAL): various vars are not scm_bits_t instead of int.
(check_map_args, scm_map, scm_for_each): len: long -> scm_bits_t
i: int -> scm_bits_t
* environments.c: changed the many calls to scm_ulong2num to
scm_ubits2num.
(import_environment_fold): proc_as_ul: ulong -> scm_ubits_t
* dynwind.c (scm_dowinds): delta: long -> scm_bits_t
* debug.h: type renaming:
scm_debug_info -> scm_debug_info_t
scm_debug_frame -> scm_debug_frame_t
the old names are deprecated, all in-Guile uses changed.
(scm_debug_eframe_size): int -> scm_bits_t
* debug.c (scm_init_debug): use scm_c_define instead of the
deprecated scm_define.
* continuations.h: type renaming:
scm_contregs -> scm_contregs_t
the old name is deprecated, all in-Guile uses changed.
(scm_contregs_t.num_stack_items): size_t -> scm_bits_t
(scm_contregs_t.num_stack_items): ulong -> scm_ubits_t
* continuations.c (scm_make_continuation): change the type of
stack_size form long to scm_bits_t.
* ports.h: type renaming:
scm_port_rw_active -> scm_port_rw_active_t (and made a typedef)
scm_port -> scm_port_t
scm_ptob_descriptor -> scm_ptob_descriptor_t
the old names are deprecated, all in-Guile uses changed.
(scm_port_t.entry): int -> scm_bits_t.
(scm_port_t.line_number): int -> long.
(scm_port_t.putback_buf_size): int -> size_t.
* __scm.h (long_long, ulong_long): deprecated (they pollute the
global namespace and have little value besides that).
(SCM_BITS_LENGTH): new, is the bit size of scm_bits_t (i.e. of an
SCM handle).
(ifdef spaghetti): include sys/types.h and sys/stdtypes.h, if they
exist (for size_t & ptrdiff_t)
(scm_sizet): deprecated.
* Makefile.am (noinst_HEADERS): add num2integral.i.c
2001-05-24 00:50:51 +00:00
|
|
|
|
|
2009-09-06 16:47:19 +02:00
|
|
|
|
SCM_INTERNAL SCM scm_i_gcd (SCM x, SCM y, SCM rest);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_lcm (SCM x, SCM y, SCM rest);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_logand (SCM x, SCM y, SCM rest);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_logior (SCM x, SCM y, SCM rest);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_logxor (SCM x, SCM y, SCM rest);
|
|
|
|
|
|
|
2004-10-22 13:50:39 +00:00
|
|
|
|
SCM_API size_t scm_iint2str (scm_t_intmax num, int rad, char *p);
|
|
|
|
|
|
SCM_API size_t scm_iuint2str (scm_t_uintmax num, int rad, char *p);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_number_to_string (SCM x, SCM radix);
|
|
|
|
|
|
SCM_API int scm_print_real (SCM sexp, SCM port, scm_print_state *pstate);
|
|
|
|
|
|
SCM_API int scm_print_complex (SCM sexp, SCM port, scm_print_state *pstate);
|
|
|
|
|
|
SCM_API int scm_bigprint (SCM exp, SCM port, scm_print_state *pstate);
|
2006-04-17 00:05:42 +00:00
|
|
|
|
SCM_API SCM scm_c_locale_stringn_to_number (const char *mem, size_t len,
|
|
|
|
|
|
unsigned int radix);
|
2009-08-21 09:18:30 -07:00
|
|
|
|
SCM_INTERNAL SCM scm_i_string_to_number (SCM str, unsigned int radix);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_string_to_number (SCM str, SCM radix);
|
|
|
|
|
|
SCM_API SCM scm_bigequal (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_real_equalp (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_complex_equalp (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_number_p (SCM x);
|
2004-08-03 17:12:14 +00:00
|
|
|
|
SCM_API SCM scm_complex_p (SCM x);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_real_p (SCM x);
|
2004-08-03 17:12:14 +00:00
|
|
|
|
SCM_API SCM scm_rational_p (SCM z);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_integer_p (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_inexact_p (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_num_eq_p (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_less_p (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_gr_p (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_leq_p (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_geq_p (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_zero_p (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_positive_p (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_negative_p (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_max (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_min (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_sum (SCM x, SCM y);
|
2005-04-14 00:35:50 +00:00
|
|
|
|
SCM_API SCM scm_oneplus (SCM x);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_difference (SCM x, SCM y);
|
2005-04-14 00:35:50 +00:00
|
|
|
|
SCM_API SCM scm_oneminus (SCM x);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_product (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_divide (SCM x, SCM y);
|
* print.c (scm_iprin1): Handle fractions.
* objects.h (scm_class_fraction): New.
* objects.c (scm_class_fraction): New.
(scm_class_of): Handle fractions.
* hash.c (scm_hasher): Handle fractions.
* numbers.c: New code for handling fraction all over the place.
(scm_odd_p, scm_even_p): Handle inexact integers.
(scm_rational_p): New function, same as scm_real_p.
(scm_round_number, scm_truncate_number, scm_ceiling, scm_floor):
New exact functions that replace the inexact 'dsubr'
implementations.
(scm_numerator, scm_denominator): New.
* numbers.h (SCM_NUMP): Recognize fractions.
(SCM_FRACTIONP, SCM_SLOPPY_FRACTIONP, SCM_FRACTION_NUMERATOR,
SCM_FRACTION_DENOMINATOR, SCM_FRACTION_SET_NUMERATOR,
SCM_FRACTION_SET_DENOMINATOR, SCM_FRACTION_REDUCED_BIT,
SCM_FRACTION_REDUCED_SET, SCM_FRACTION_REDUCED_CLEAR,
SCM_FRACTION_REDUCED): New.
(scm_floor, scm_ceiling, scm_truncate_number, scm_round_number):
New prototypes.
(scm_make_ratio, scm_rationalize, scm_numerator, scm_denominator,
scm_rational_p): New prototypes.
(scm_i_dbl2num, scm_i_fraction2double, scm_i_fraction_equalp,
scm_i_print_fraction): New prototypes.
* goops.c (create_standard_classes): Create "<fraction>" class.
* gc-mark.c (scm_gc_mark_dependencies): Handle fractions.
* gc-card.c (scm_i_sweep_card): Include scm_tc16_fraction as a
case in the switch, but do nothing for now.
* eval.c (SCM_CEVAL, SCM_APPLY, call_dsubr_1): Convert fractions
to doubles when calling 'dsubr' functions.
* eq.c (scm_eqv_p, scm_equal_p): Handle fractions.
2003-11-18 19:59:53 +00:00
|
|
|
|
SCM_API SCM scm_floor (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_ceiling (SCM x);
|
2004-08-09 23:32:14 +00:00
|
|
|
|
SCM_API double scm_c_truncate (double x);
|
|
|
|
|
|
SCM_API double scm_c_round (double x);
|
* print.c (scm_iprin1): Handle fractions.
* objects.h (scm_class_fraction): New.
* objects.c (scm_class_fraction): New.
(scm_class_of): Handle fractions.
* hash.c (scm_hasher): Handle fractions.
* numbers.c: New code for handling fraction all over the place.
(scm_odd_p, scm_even_p): Handle inexact integers.
(scm_rational_p): New function, same as scm_real_p.
(scm_round_number, scm_truncate_number, scm_ceiling, scm_floor):
New exact functions that replace the inexact 'dsubr'
implementations.
(scm_numerator, scm_denominator): New.
* numbers.h (SCM_NUMP): Recognize fractions.
(SCM_FRACTIONP, SCM_SLOPPY_FRACTIONP, SCM_FRACTION_NUMERATOR,
SCM_FRACTION_DENOMINATOR, SCM_FRACTION_SET_NUMERATOR,
SCM_FRACTION_SET_DENOMINATOR, SCM_FRACTION_REDUCED_BIT,
SCM_FRACTION_REDUCED_SET, SCM_FRACTION_REDUCED_CLEAR,
SCM_FRACTION_REDUCED): New.
(scm_floor, scm_ceiling, scm_truncate_number, scm_round_number):
New prototypes.
(scm_make_ratio, scm_rationalize, scm_numerator, scm_denominator,
scm_rational_p): New prototypes.
(scm_i_dbl2num, scm_i_fraction2double, scm_i_fraction_equalp,
scm_i_print_fraction): New prototypes.
* goops.c (create_standard_classes): Create "<fraction>" class.
* gc-mark.c (scm_gc_mark_dependencies): Handle fractions.
* gc-card.c (scm_i_sweep_card): Include scm_tc16_fraction as a
case in the switch, but do nothing for now.
* eval.c (SCM_CEVAL, SCM_APPLY, call_dsubr_1): Convert fractions
to doubles when calling 'dsubr' functions.
* eq.c (scm_eqv_p, scm_equal_p): Handle fractions.
2003-11-18 19:59:53 +00:00
|
|
|
|
SCM_API SCM scm_truncate_number (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_round_number (SCM x);
|
2009-09-03 12:19:39 +02:00
|
|
|
|
SCM_API SCM scm_expt (SCM z1, SCM z2);
|
implement transcendental sin, cos etc in c; deprecate $sin, $cos, etc
* libguile/deprecated.h:
* libguile/deprecated.c (scm_asinh, scm_acosh, scm_atanh): Deprecate
these stand-ins for the C99 asinh, acosh, and atanh functions. Guile
is not gnulib.
(scm_sys_atan2): Deprecate as well, in favor of scm_atan.
* libguile/numbers.h:
* libguile/numbers.c (scm_sin, scm_cos, scm_tan)
(scm_sinh, scm_cosh, scm_tanh)
(scm_asin, scm_acos, scm_atan)
(scm_sys_asinh, scm_sys_acosh, scm_sys_atanh): New functions,
replacing the combination of dsubrs and boot-9 wrappers with C subrs
that handle complex values. The latter three have _sys_ in their names
due to the name conflict with the deprecated scm_asinh et al.
Remove the $abs, $sin etc "dsubrs".
* module/ice-9/boot-9.scm: Remove transcendental functions, as this all
happens in C now.
* module/ice-9/deprecated.scm: Add aliases for $sin et al.
* test-suite/tests/ramap.test ("array-map!"): Adjust "dsubr" tests to
use sqrt, not $sqrt. They don't actually test dsubrs now. In the
two-source test, I'm pretty sure the dsubr array-map! should have been
failing, as indeed it does now; I've changed the test case to expect
the failure. I'd still like to know why it was succeeding before.
2009-09-03 22:29:10 +02:00
|
|
|
|
SCM_API SCM scm_sin (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_cos (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_tan (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_sinh (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_cosh (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_tanh (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_asin (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_acos (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_atan (SCM x, SCM y);
|
|
|
|
|
|
SCM_API SCM scm_sys_asinh (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_sys_acosh (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_sys_atanh (SCM z);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_make_rectangular (SCM z1, SCM z2);
|
|
|
|
|
|
SCM_API SCM scm_make_polar (SCM z1, SCM z2);
|
|
|
|
|
|
SCM_API SCM scm_real_part (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_imag_part (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_magnitude (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_angle (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_exact_to_inexact (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_inexact_to_exact (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_trunc (SCM x);
|
2006-10-09 23:40:48 +00:00
|
|
|
|
SCM_API SCM scm_log (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_log10 (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_exp (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_sqrt (SCM z);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
|
2009-09-06 16:47:19 +02:00
|
|
|
|
SCM_INTERNAL SCM scm_i_min (SCM x, SCM y, SCM rest);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_max (SCM x, SCM y, SCM rest);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_sum (SCM x, SCM y, SCM rest);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_difference (SCM x, SCM y, SCM rest);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_product (SCM x, SCM y, SCM rest);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_divide (SCM x, SCM y, SCM rest);
|
|
|
|
|
|
|
2003-04-04 21:49:55 +00:00
|
|
|
|
/* bignum internal functions */
|
2008-05-14 05:20:47 +02:00
|
|
|
|
SCM_INTERNAL SCM scm_i_mkbig (void);
|
|
|
|
|
|
SCM_API /* FIXME: not internal */ SCM scm_i_normbig (SCM x);
|
|
|
|
|
|
SCM_INTERNAL int scm_i_bigcmp (SCM a, SCM b);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_dbl2big (double d);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_dbl2num (double d);
|
|
|
|
|
|
SCM_API /* FIXME: not internal */ double scm_i_big2dbl (SCM b);
|
|
|
|
|
|
SCM_API /* FIXME: not internal */ SCM scm_i_long2big (long n);
|
|
|
|
|
|
SCM_API /* FIXME: not internal */ SCM scm_i_ulong2big (unsigned long n);
|
|
|
|
|
|
SCM_API /* FIXME: not internal */ SCM scm_i_clonebig (SCM src_big, int same_sign_p);
|
2003-04-04 21:49:55 +00:00
|
|
|
|
|
* print.c (scm_iprin1): Handle fractions.
* objects.h (scm_class_fraction): New.
* objects.c (scm_class_fraction): New.
(scm_class_of): Handle fractions.
* hash.c (scm_hasher): Handle fractions.
* numbers.c: New code for handling fraction all over the place.
(scm_odd_p, scm_even_p): Handle inexact integers.
(scm_rational_p): New function, same as scm_real_p.
(scm_round_number, scm_truncate_number, scm_ceiling, scm_floor):
New exact functions that replace the inexact 'dsubr'
implementations.
(scm_numerator, scm_denominator): New.
* numbers.h (SCM_NUMP): Recognize fractions.
(SCM_FRACTIONP, SCM_SLOPPY_FRACTIONP, SCM_FRACTION_NUMERATOR,
SCM_FRACTION_DENOMINATOR, SCM_FRACTION_SET_NUMERATOR,
SCM_FRACTION_SET_DENOMINATOR, SCM_FRACTION_REDUCED_BIT,
SCM_FRACTION_REDUCED_SET, SCM_FRACTION_REDUCED_CLEAR,
SCM_FRACTION_REDUCED): New.
(scm_floor, scm_ceiling, scm_truncate_number, scm_round_number):
New prototypes.
(scm_make_ratio, scm_rationalize, scm_numerator, scm_denominator,
scm_rational_p): New prototypes.
(scm_i_dbl2num, scm_i_fraction2double, scm_i_fraction_equalp,
scm_i_print_fraction): New prototypes.
* goops.c (create_standard_classes): Create "<fraction>" class.
* gc-mark.c (scm_gc_mark_dependencies): Handle fractions.
* gc-card.c (scm_i_sweep_card): Include scm_tc16_fraction as a
case in the switch, but do nothing for now.
* eval.c (SCM_CEVAL, SCM_APPLY, call_dsubr_1): Convert fractions
to doubles when calling 'dsubr' functions.
* eq.c (scm_eqv_p, scm_equal_p): Handle fractions.
2003-11-18 19:59:53 +00:00
|
|
|
|
/* ratio functions */
|
|
|
|
|
|
SCM_API SCM scm_rationalize (SCM x, SCM err);
|
|
|
|
|
|
SCM_API SCM scm_numerator (SCM z);
|
|
|
|
|
|
SCM_API SCM scm_denominator (SCM z);
|
|
|
|
|
|
|
|
|
|
|
|
/* fraction internal functions */
|
2008-05-14 05:20:47 +02:00
|
|
|
|
SCM_INTERNAL double scm_i_fraction2double (SCM z);
|
|
|
|
|
|
SCM_INTERNAL SCM scm_i_fraction_equalp (SCM x, SCM y);
|
|
|
|
|
|
SCM_INTERNAL int scm_i_print_fraction (SCM sexp, SCM port, scm_print_state *pstate);
|
* print.c (scm_iprin1): Handle fractions.
* objects.h (scm_class_fraction): New.
* objects.c (scm_class_fraction): New.
(scm_class_of): Handle fractions.
* hash.c (scm_hasher): Handle fractions.
* numbers.c: New code for handling fraction all over the place.
(scm_odd_p, scm_even_p): Handle inexact integers.
(scm_rational_p): New function, same as scm_real_p.
(scm_round_number, scm_truncate_number, scm_ceiling, scm_floor):
New exact functions that replace the inexact 'dsubr'
implementations.
(scm_numerator, scm_denominator): New.
* numbers.h (SCM_NUMP): Recognize fractions.
(SCM_FRACTIONP, SCM_SLOPPY_FRACTIONP, SCM_FRACTION_NUMERATOR,
SCM_FRACTION_DENOMINATOR, SCM_FRACTION_SET_NUMERATOR,
SCM_FRACTION_SET_DENOMINATOR, SCM_FRACTION_REDUCED_BIT,
SCM_FRACTION_REDUCED_SET, SCM_FRACTION_REDUCED_CLEAR,
SCM_FRACTION_REDUCED): New.
(scm_floor, scm_ceiling, scm_truncate_number, scm_round_number):
New prototypes.
(scm_make_ratio, scm_rationalize, scm_numerator, scm_denominator,
scm_rational_p): New prototypes.
(scm_i_dbl2num, scm_i_fraction2double, scm_i_fraction_equalp,
scm_i_print_fraction): New prototypes.
* goops.c (create_standard_classes): Create "<fraction>" class.
* gc-mark.c (scm_gc_mark_dependencies): Handle fractions.
* gc-card.c (scm_i_sweep_card): Include scm_tc16_fraction as a
case in the switch, but do nothing for now.
* eval.c (SCM_CEVAL, SCM_APPLY, call_dsubr_1): Convert fractions
to doubles when calling 'dsubr' functions.
* eq.c (scm_eqv_p, scm_equal_p): Handle fractions.
2003-11-18 19:59:53 +00:00
|
|
|
|
|
2004-10-26 16:53:23 +00:00
|
|
|
|
/* general internal functions */
|
2008-05-14 05:20:47 +02:00
|
|
|
|
SCM_INTERNAL void scm_i_print_double (double val, SCM port);
|
|
|
|
|
|
SCM_INTERNAL void scm_i_print_complex (double real, double imag, SCM port);
|
2004-10-26 16:53:23 +00:00
|
|
|
|
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
/* conversion functions for integers */
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
|
|
|
|
|
|
SCM_API int scm_is_integer (SCM val);
|
|
|
|
|
|
SCM_API int scm_is_signed_integer (SCM val,
|
|
|
|
|
|
scm_t_intmax min, scm_t_intmax max);
|
|
|
|
|
|
SCM_API int scm_is_unsigned_integer (SCM val,
|
|
|
|
|
|
scm_t_uintmax min, scm_t_uintmax max);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API SCM scm_from_signed_integer (scm_t_intmax val);
|
|
|
|
|
|
SCM_API SCM scm_from_unsigned_integer (scm_t_uintmax val);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API scm_t_intmax scm_to_signed_integer (SCM val,
|
|
|
|
|
|
scm_t_intmax min,
|
|
|
|
|
|
scm_t_intmax max);
|
|
|
|
|
|
SCM_API scm_t_uintmax scm_to_unsigned_integer (SCM val,
|
|
|
|
|
|
scm_t_uintmax min,
|
|
|
|
|
|
scm_t_uintmax max);
|
|
|
|
|
|
|
* conv-integer.i.c, conv-uinteger.i.c: New files, used to generate
the functions below.
* numbers.c, numbers.h (scm_to_int8, scm_to_uint8, scm_to_int16,
scm_to_uint16, scm_to_int32, scm_to_uint32, scm_to_int64,
scm_to_uint64, scm_from_int8, scm_from_uint8, scm_from_int16,
scm_from_uint16, scm_from_int32, scm_from_uint32, scm_from_int64,
scm_from_uint64): Turned from macros into proper functions.
(scm_to_signed_integer, scm_to_unsigned_integer,
scm_from_signed_integer, scm_from_unsigned_integer): Generate via
conv-integer.i.c and conv-uinteger.i.c, as well.
2004-07-29 13:42:50 +00:00
|
|
|
|
SCM_API scm_t_int8 scm_to_int8 (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_from_int8 (scm_t_int8 x);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API scm_t_uint8 scm_to_uint8 (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_from_uint8 (scm_t_uint8 x);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API scm_t_int16 scm_to_int16 (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_from_int16 (scm_t_int16 x);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API scm_t_uint16 scm_to_uint16 (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_from_uint16 (scm_t_uint16 x);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API scm_t_int32 scm_to_int32 (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_from_int32 (scm_t_int32 x);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API scm_t_uint32 scm_to_uint32 (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_from_uint32 (scm_t_uint32 x);
|
|
|
|
|
|
|
2009-07-29 06:38:32 -07:00
|
|
|
|
SCM_API scm_t_wchar scm_to_wchar (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_from_wchar (scm_t_wchar x);
|
|
|
|
|
|
|
* conv-integer.i.c, conv-uinteger.i.c: New files, used to generate
the functions below.
* numbers.c, numbers.h (scm_to_int8, scm_to_uint8, scm_to_int16,
scm_to_uint16, scm_to_int32, scm_to_uint32, scm_to_int64,
scm_to_uint64, scm_from_int8, scm_from_uint8, scm_from_int16,
scm_from_uint16, scm_from_int32, scm_from_uint32, scm_from_int64,
scm_from_uint64): Turned from macros into proper functions.
(scm_to_signed_integer, scm_to_unsigned_integer,
scm_from_signed_integer, scm_from_unsigned_integer): Generate via
conv-integer.i.c and conv-uinteger.i.c, as well.
2004-07-29 13:42:50 +00:00
|
|
|
|
SCM_API scm_t_int64 scm_to_int64 (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_from_int64 (scm_t_int64 x);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API scm_t_uint64 scm_to_uint64 (SCM x);
|
|
|
|
|
|
SCM_API SCM scm_from_uint64 (scm_t_uint64 x);
|
|
|
|
|
|
|
2004-09-21 00:42:30 +00:00
|
|
|
|
SCM_API void scm_to_mpz (SCM x, mpz_t rop);
|
|
|
|
|
|
SCM_API SCM scm_from_mpz (mpz_t rop);
|
|
|
|
|
|
|
|
|
|
|
|
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
/* The conversion functions for other types are aliased to the
|
|
|
|
|
|
appropriate ones from above. We pick the right one based on the
|
|
|
|
|
|
size of the type.
|
|
|
|
|
|
|
|
|
|
|
|
Not each and every possibility is covered by the code below, and
|
|
|
|
|
|
while it is trivial to complete the tests, it might be better to
|
|
|
|
|
|
just test for the 'sane' possibilities. When one of the tests
|
|
|
|
|
|
below fails, chances are good that some silent assumption somewhere
|
|
|
|
|
|
else will also fail.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#if SCM_SIZEOF_CHAR == 1
|
|
|
|
|
|
#define scm_to_schar scm_to_int8
|
|
|
|
|
|
#define scm_from_schar scm_from_int8
|
|
|
|
|
|
#define scm_to_uchar scm_to_uint8
|
|
|
|
|
|
#define scm_from_uchar scm_from_uint8
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
#if CHAR_MIN == 0
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
#define scm_to_char scm_to_uint8
|
|
|
|
|
|
#define scm_from_char scm_from_uint8
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
#else
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
#define scm_to_char scm_to_int8
|
|
|
|
|
|
#define scm_from_char scm_from_int8
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
#endif
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
#else
|
|
|
|
|
|
#error sizeof(char) is not 1.
|
(scm_to_short, scm_to_ushort): It's SHRT_MIN, etc, not SHORT_MIN.
(scm_to_size_t): Use SIZE_MAX instead of cooking our own.
(scm_to_long_long, scm_to_ulong_long, scm_to_int8, scm_to_uint8,
scm_to_int16, scm_to_uint16, scm_to_int32, scm_to_uint32,
scm_to_int64, scm_to_uint64, scm_to_intmax, scm_to_uintmax,
scm_from_long_long, scm_from_ulong_long, scm_from_int8,
scm_from_uint8, scm_from_int16, scm_from_uint16, scm_from_int32,
scm_from_uint32, scm_from_int64, scm_from_uint64, scm_from_intmax,
scm_from_uintmax): New.
2004-07-07 15:22:56 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
#if SCM_SIZEOF_SHORT == 1
|
|
|
|
|
|
#define scm_to_short scm_to_int8
|
|
|
|
|
|
#define scm_from_short scm_from_int8
|
|
|
|
|
|
#define scm_to_ushort scm_to_uint8
|
|
|
|
|
|
#define scm_from_ushort scm_from_uint8
|
|
|
|
|
|
#else
|
|
|
|
|
|
#if SCM_SIZEOF_SHORT == 2
|
|
|
|
|
|
#define scm_to_short scm_to_int16
|
|
|
|
|
|
#define scm_from_short scm_from_int16
|
|
|
|
|
|
#define scm_to_ushort scm_to_uint16
|
|
|
|
|
|
#define scm_from_ushort scm_from_uint16
|
|
|
|
|
|
#else
|
|
|
|
|
|
#if SCM_SIZEOF_SHORT == 4
|
|
|
|
|
|
#define scm_to_short scm_to_int32
|
|
|
|
|
|
#define scm_from_short scm_from_int32
|
|
|
|
|
|
#define scm_to_ushort scm_to_uint32
|
|
|
|
|
|
#define scm_from_ushort scm_from_uint32
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
#else
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
#error sizeof(short) is not 1, 2, or 4.
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#endif
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
#if SCM_SIZEOF_INT == 4
|
|
|
|
|
|
#define scm_to_int scm_to_int32
|
|
|
|
|
|
#define scm_from_int scm_from_int32
|
|
|
|
|
|
#define scm_to_uint scm_to_uint32
|
|
|
|
|
|
#define scm_from_uint scm_from_uint32
|
|
|
|
|
|
#else
|
|
|
|
|
|
#if SCM_SIZEOF_INT == 8
|
|
|
|
|
|
#define scm_to_int scm_to_int64
|
|
|
|
|
|
#define scm_from_int scm_from_int64
|
|
|
|
|
|
#define scm_to_uint scm_to_uint64
|
|
|
|
|
|
#define scm_from_uint scm_from_uint64
|
|
|
|
|
|
#else
|
|
|
|
|
|
#error sizeof(int) is not 4 or 8.
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#endif
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
#if SCM_SIZEOF_LONG == 4
|
|
|
|
|
|
#define scm_to_long scm_to_int32
|
|
|
|
|
|
#define scm_from_long scm_from_int32
|
|
|
|
|
|
#define scm_to_ulong scm_to_uint32
|
|
|
|
|
|
#define scm_from_ulong scm_from_uint32
|
|
|
|
|
|
#else
|
|
|
|
|
|
#if SCM_SIZEOF_LONG == 8
|
|
|
|
|
|
#define scm_to_long scm_to_int64
|
|
|
|
|
|
#define scm_from_long scm_from_int64
|
|
|
|
|
|
#define scm_to_ulong scm_to_uint64
|
|
|
|
|
|
#define scm_from_ulong scm_from_uint64
|
|
|
|
|
|
#else
|
|
|
|
|
|
#error sizeof(long) is not 4 or 8.
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#endif
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
#if SCM_SIZEOF_INTMAX == 4
|
|
|
|
|
|
#define scm_to_intmax scm_to_int32
|
|
|
|
|
|
#define scm_from_intmax scm_from_int32
|
|
|
|
|
|
#define scm_to_uintmax scm_to_uint32
|
|
|
|
|
|
#define scm_from_uintmax scm_from_uint32
|
|
|
|
|
|
#else
|
|
|
|
|
|
#if SCM_SIZEOF_INTMAX == 8
|
|
|
|
|
|
#define scm_to_intmax scm_to_int64
|
|
|
|
|
|
#define scm_from_intmax scm_from_int64
|
|
|
|
|
|
#define scm_to_uintmax scm_to_uint64
|
|
|
|
|
|
#define scm_from_uintmax scm_from_uint64
|
|
|
|
|
|
#else
|
(scm_is_rational): New.
(scm_i_short2big, scm_i_int2big, scm_i_uint2big, scm_i_size2big,
scm_i_ptrdiff2big, scm_i_long_long2big, scm_i_ulong_long2big):
Removed prototypes.
(scm_make_real, scm_num2dbl, scm_float2num, scm_double2num):
Discouraged by moving to discouraged.h and discouraged.c.
Replaced all uses with scm_from_double.
(scm_num2float, scm_num2double): Discouraged by moving prototype
to discouraged.h and rewriting in terms of scm_to_double.
Replaced all uses with scm_to_double.
(scm_to_double): Do not implement in terms of scm_num2dbl, use
explicit code.
(scm_from_double): Do not implement in terms of scm_make_real, use
explicit code.
2004-08-03 15:03:35 +00:00
|
|
|
|
#error sizeof(scm_t_intmax) is not 4 or 8.
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
#endif
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
#if SCM_SIZEOF_LONG_LONG == 0
|
|
|
|
|
|
#else
|
|
|
|
|
|
#if SCM_SIZEOF_LONG_LONG == 8
|
|
|
|
|
|
#define scm_to_long_long scm_to_int64
|
|
|
|
|
|
#define scm_from_long_long scm_from_int64
|
|
|
|
|
|
#define scm_to_ulong_long scm_to_uint64
|
|
|
|
|
|
#define scm_from_ulong_long scm_from_uint64
|
|
|
|
|
|
#else
|
|
|
|
|
|
#error sizeof(long long) is not 8.
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#endif
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
|
* numbers.h (scm_to_schar, scm_to_uchar, scm_to_char,
scm_to_short, scm_to_ushort, scm_to_int, scm_to_uint, scm_to_long,
scm_to_ulong, scm_to_long_long, scm_to_ulong_long, scm_to_intmax,
scm_to_uintmax, scm_to_size_t, scm_to_ssize_t scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_long_long, scm_from_ulong_long, scm_from_intmax,
scm_from_uintmax, scm_from_size_t, scm_from_ssize_t): No longer
defined in terms of scm_to_signed_integer, etc, but in terms of
scm_to_int8, etc.
2004-07-29 15:48:44 +00:00
|
|
|
|
#if SCM_SIZEOF_SIZE_T == 4
|
|
|
|
|
|
#define scm_to_ssize_t scm_to_int32
|
|
|
|
|
|
#define scm_from_ssize_t scm_from_int32
|
|
|
|
|
|
#define scm_to_size_t scm_to_uint32
|
|
|
|
|
|
#define scm_from_size_t scm_from_uint32
|
|
|
|
|
|
#else
|
|
|
|
|
|
#if SCM_SIZEOF_SIZE_T == 8
|
|
|
|
|
|
#define scm_to_ssize_t scm_to_int64
|
|
|
|
|
|
#define scm_from_ssize_t scm_from_int64
|
|
|
|
|
|
#define scm_to_size_t scm_to_uint64
|
|
|
|
|
|
#define scm_from_size_t scm_from_uint64
|
|
|
|
|
|
#else
|
|
|
|
|
|
#error sizeof(size_t) is not 4 or 8.
|
|
|
|
|
|
#endif
|
(scm_to_short, scm_to_ushort): It's SHRT_MIN, etc, not SHORT_MIN.
(scm_to_size_t): Use SIZE_MAX instead of cooking our own.
(scm_to_long_long, scm_to_ulong_long, scm_to_int8, scm_to_uint8,
scm_to_int16, scm_to_uint16, scm_to_int32, scm_to_uint32,
scm_to_int64, scm_to_uint64, scm_to_intmax, scm_to_uintmax,
scm_from_long_long, scm_from_ulong_long, scm_from_int8,
scm_from_uint8, scm_from_int16, scm_from_uint16, scm_from_int32,
scm_from_uint32, scm_from_int64, scm_from_uint64, scm_from_intmax,
scm_from_uintmax): New.
2004-07-07 15:22:56 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2004-08-03 17:12:14 +00:00
|
|
|
|
/* conversion functions for double */
|
(scm_to_short, scm_to_ushort): It's SHRT_MIN, etc, not SHORT_MIN.
(scm_to_size_t): Use SIZE_MAX instead of cooking our own.
(scm_to_long_long, scm_to_ulong_long, scm_to_int8, scm_to_uint8,
scm_to_int16, scm_to_uint16, scm_to_int32, scm_to_uint32,
scm_to_int64, scm_to_uint64, scm_to_intmax, scm_to_uintmax,
scm_from_long_long, scm_from_ulong_long, scm_from_int8,
scm_from_uint8, scm_from_int16, scm_from_uint16, scm_from_int32,
scm_from_uint32, scm_from_int64, scm_from_uint64, scm_from_intmax,
scm_from_uintmax): New.
2004-07-07 15:22:56 +00:00
|
|
|
|
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
SCM_API int scm_is_real (SCM val);
|
(scm_is_rational): New.
(scm_i_short2big, scm_i_int2big, scm_i_uint2big, scm_i_size2big,
scm_i_ptrdiff2big, scm_i_long_long2big, scm_i_ulong_long2big):
Removed prototypes.
(scm_make_real, scm_num2dbl, scm_float2num, scm_double2num):
Discouraged by moving to discouraged.h and discouraged.c.
Replaced all uses with scm_from_double.
(scm_num2float, scm_num2double): Discouraged by moving prototype
to discouraged.h and rewriting in terms of scm_to_double.
Replaced all uses with scm_to_double.
(scm_to_double): Do not implement in terms of scm_num2dbl, use
explicit code.
(scm_from_double): Do not implement in terms of scm_make_real, use
explicit code.
2004-08-03 15:03:35 +00:00
|
|
|
|
SCM_API int scm_is_rational (SCM val);
|
(scm_is_integer, scm_is_signed_integer, scm_is_unsigned_integer,
scm_to_signed_integer, scm_to_unsigned_integer, scm_to_schar,
scm_to_uchar, scm_to_char, scm_to_short, scm_to_ushort, scm_to_long,
scm_to_ulong, scm_to_size_t, scm_to_ssize_t, scm_from_schar,
scm_from_uchar, scm_from_char, scm_from_short, scm_from_ushort,
scm_from_int, scm_from_uint, scm_from_long, scm_from_ulong,
scm_from_size_t, scm_from_ssize_t, scm_is_real, scm_to_double,
scm_from_double): New.
* deprecated.h, boolean.h (SCM_FALSEP, SCM_NFALSEP, SCM_BOOL,
SCM_NEGATE_BOOL, SCM_BOOLP): Deprecated by moving into "deprecated.h".
Replaced all uses with scm_is_false, scm_is_true, scm_from_bool, and
scm_is_bool, respectively.
2004-07-06 10:23:30 +00:00
|
|
|
|
SCM_API double scm_to_double (SCM val);
|
|
|
|
|
|
SCM_API SCM scm_from_double (double val);
|
|
|
|
|
|
|
2004-08-03 17:12:14 +00:00
|
|
|
|
/* conversion functions for complex */
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API int scm_is_complex (SCM val);
|
|
|
|
|
|
SCM_API SCM scm_c_make_rectangular (double re, double im);
|
|
|
|
|
|
SCM_API SCM scm_c_make_polar (double mag, double ang);
|
|
|
|
|
|
SCM_API double scm_c_real_part (SCM z);
|
|
|
|
|
|
SCM_API double scm_c_imag_part (SCM z);
|
|
|
|
|
|
SCM_API double scm_c_magnitude (SCM z);
|
|
|
|
|
|
SCM_API double scm_c_angle (SCM z);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API int scm_is_number (SCM val);
|
|
|
|
|
|
|
2008-05-14 05:20:47 +02:00
|
|
|
|
SCM_INTERNAL void scm_init_numbers (void);
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-07-30 19:35:15 +00:00
|
|
|
|
#endif /* SCM_NUMBERS_H */
|
2000-03-19 19:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|