drop extra 2006-02-06 heading
[bpt/guile.git] / libguile / numbers.h
index 19bd356..40b8369 100644 (file)
@@ -3,7 +3,7 @@
 #ifndef SCM_NUMBERS_H
 #define SCM_NUMBERS_H
 
-/* Copyright (C) 1995,1996,1998,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,2000,2001,2002,2003,2004,2005, 2006 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 \f
 
+#include <gmp.h>
+
 #include "libguile/__scm.h"
 #include "libguile/print.h"
 
@@ -90,7 +92,6 @@
 #  include <float.h>
 #  ifdef __MINGW32__
 #   define copysign _copysign
-#   define isnan _isnan
 #   define finite _finite
 #  endif /* __MINGW32__ */
 # endif /* ndef GO32 */
 #endif /* def FLT_MAX */
 
 
-/* SCM_INTBUFLEN is the maximum number of characters neccessary for the
- * printed or scm_string representation of an exact immediate.
+/* 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.
  */
-#define SCM_INTBUFLEN (5 + SCM_LONG_BIT)
+#define SCM_INTBUFLEN (5 + SCM_CHAR_BIT*sizeof(scm_t_intmax))
 
 \f
 
@@ -206,20 +209,22 @@ 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);
 
-SCM_API size_t scm_iint2str (long num, int rad, char *p);
+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);
 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);
-SCM_API SCM scm_i_mem2number (const char *mem, size_t len, unsigned int radix);
+SCM_API SCM scm_c_locale_stringn_to_number (const char *mem, size_t len,
+                                           unsigned int radix);
 SCM_API SCM scm_string_to_number (SCM str, SCM radix);
-SCM_API SCM scm_make_real (double x);
-SCM_API SCM scm_make_complex (double x, double y);
 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);
+SCM_API SCM scm_complex_p (SCM x);
 SCM_API SCM scm_real_p (SCM x);
+SCM_API SCM scm_rational_p (SCM z);
 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);
@@ -233,17 +238,18 @@ 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);
+SCM_API SCM scm_oneplus (SCM x);
 SCM_API SCM scm_difference (SCM x, SCM y);
+SCM_API SCM scm_oneminus (SCM x);
 SCM_API SCM scm_product (SCM x, SCM y);
-SCM_API double scm_num2dbl (SCM a, const char * why);
 SCM_API SCM scm_divide (SCM x, SCM y);
 SCM_API SCM scm_floor (SCM x);
 SCM_API SCM scm_ceiling (SCM x);
 SCM_API double scm_asinh (double x);
 SCM_API double scm_acosh (double x);
 SCM_API double scm_atanh (double x);
-SCM_API double scm_truncate (double x);
-SCM_API double scm_round (double x);
+SCM_API double scm_c_truncate (double x);
+SCM_API double scm_c_round (double x);
 SCM_API SCM scm_truncate_number (SCM x);
 SCM_API SCM scm_round_number (SCM x);
 SCM_API SCM scm_sys_expt (SCM z1, SCM z2);
@@ -258,47 +264,6 @@ 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);
 
-SCM_API SCM scm_short2num (short n);
-SCM_API SCM scm_ushort2num (unsigned short n);
-SCM_API SCM scm_int2num (int n);
-SCM_API SCM scm_uint2num (unsigned int n);
-SCM_API SCM scm_long2num (long n);
-SCM_API SCM scm_ulong2num (unsigned long n);
-SCM_API SCM scm_size2num (size_t n);
-SCM_API SCM scm_ptrdiff2num (scm_t_ptrdiff n);
-SCM_API short scm_num2short (SCM num, unsigned long int pos,
-                            const char *s_caller);
-SCM_API unsigned short scm_num2ushort (SCM num, unsigned long int pos,
-                                      const char *s_caller);
-SCM_API int scm_num2int (SCM num, unsigned long int pos,
-                        const char *s_caller);
-SCM_API unsigned int scm_num2uint (SCM num, unsigned long int pos,
-                                  const char *s_caller);
-SCM_API long scm_num2long (SCM num, unsigned long int pos,
-                          const char *s_caller);
-SCM_API unsigned long scm_num2ulong (SCM num, unsigned long int pos,
-                                    const char *s_caller);
-SCM_API scm_t_ptrdiff scm_num2ptrdiff (SCM num, unsigned long int pos,
-                                       const char *s_caller);
-SCM_API size_t scm_num2size (SCM num, unsigned long int pos,
-                            const char *s_caller);
-#if SCM_SIZEOF_LONG_LONG != 0
-SCM_API SCM scm_long_long2num (long long sl);
-SCM_API SCM scm_ulong_long2num (unsigned long long sl);
-SCM_API long long scm_num2long_long (SCM num, unsigned long int pos,
-                                    const char *s_caller);
-SCM_API unsigned long long scm_num2ulong_long (SCM num, unsigned long int pos,
-                                              const char *s_caller);
-#endif
-
-SCM_API SCM scm_float2num (float n);
-SCM_API SCM scm_double2num (double n);
-SCM_API float scm_num2float (SCM num, unsigned long int pos,
-                            const char *s_caller);
-SCM_API double scm_num2double (SCM num, unsigned long int pos,
-                              const char *s_caller);
-
-
 /* bignum internal functions */
 SCM_API SCM scm_i_mkbig (void);
 SCM_API SCM scm_i_normbig (SCM x);
@@ -306,37 +271,23 @@ SCM_API int scm_i_bigcmp (SCM a, SCM b);
 SCM_API SCM scm_i_dbl2big (double d);
 SCM_API SCM scm_i_dbl2num (double d);
 SCM_API double scm_i_big2dbl (SCM b);
-SCM_API SCM scm_i_short2big (short n);
-SCM_API SCM scm_i_ushort2big (unsigned short n);
-SCM_API SCM scm_i_int2big (int n);
-SCM_API SCM scm_i_uint2big (unsigned int n);
 SCM_API SCM scm_i_long2big (long n);
 SCM_API SCM scm_i_ulong2big (unsigned long n);
-SCM_API SCM scm_i_size2big (size_t n);
-SCM_API SCM scm_i_ptrdiff2big (scm_t_ptrdiff n);
-
-#if SCM_SIZEOF_LONG_LONG != 0
-SCM_API SCM scm_i_long_long2big (long long n);
-SCM_API SCM scm_i_ulong_long2big (unsigned long long n);
-#endif
-
+SCM_API SCM scm_i_clonebig (SCM src_big, int same_sign_p);
 
 /* ratio functions */
-SCM_API SCM scm_make_ratio (SCM num, SCM den);
 SCM_API SCM scm_rationalize (SCM x, SCM err);
 SCM_API SCM scm_numerator (SCM z);
 SCM_API SCM scm_denominator (SCM z);
-SCM_API SCM scm_rational_p (SCM z);
 
 /* fraction internal functions */
 SCM_API double scm_i_fraction2double (SCM z);
 SCM_API SCM scm_i_fraction_equalp (SCM x, SCM y);
 SCM_API int scm_i_print_fraction (SCM sexp, SCM port, scm_print_state *pstate);
 
-
-#ifdef GUILE_DEBUG
-SCM_API SCM scm_sys_check_number_conversions (void);
-#endif
+/* general internal functions */
+SCM_API void scm_i_print_double (double val, SCM port);
+SCM_API void scm_i_print_complex (double real, double imag, SCM port);
 
 /* conversion functions for integers */
 
@@ -384,6 +335,10 @@ SCM_API SCM          scm_from_uint64 (scm_t_uint64 x);
 
 #endif
 
+SCM_API void scm_to_mpz (SCM x, mpz_t rop);
+SCM_API SCM  scm_from_mpz (mpz_t rop);
+
+
 /* 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.
@@ -478,7 +433,7 @@ SCM_API SCM          scm_from_uint64 (scm_t_uint64 x);
 #define scm_to_uintmax   scm_to_uint64
 #define scm_from_uintmax scm_from_uint64
 #else
-#error sizeof(scm_t_intmax_t) is not 4 or 8.
+#error sizeof(scm_t_intmax) is not 4 or 8.
 #endif
 #endif
 
@@ -510,12 +465,25 @@ SCM_API SCM          scm_from_uint64 (scm_t_uint64 x);
 #endif
 #endif
 
-/* conversion functions for reals */
+/* conversion functions for double */
 
 SCM_API int scm_is_real (SCM val);
+SCM_API int scm_is_rational (SCM val);
 SCM_API double scm_to_double (SCM val);
 SCM_API SCM scm_from_double (double val);
 
+/* 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);
+
 SCM_API void scm_init_numbers (void);
 
 #endif  /* SCM_NUMBERS_H */