Main Page | Class List | Directories | File List | Class Members | File Members

bignum.h

Go to the documentation of this file.
00001 /*
00002 || This file is part of Pike. For copyright information see COPYRIGHT.
00003 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
00004 || for more information.
00005 || $Id: bignum.h,v 1.27 2005/04/08 16:54:01 grubba Exp $
00006 */
00007 
00008 #include "global.h"
00009 
00010 #ifndef BIGNUM_H
00011 #define BIGNUM_H
00012 
00013 /* Note: These functions assume some properties of the CPU. */
00014 
00015 #define INT_TYPE_SIGN(x)             ((x) < 0)
00016 
00017 #ifdef HAVE_NICE_FPU_DIVISION
00018 #define INT_TYPE_MUL_OVERFLOW(a, b)  ((b) && ((a)*(b))/(b) != (a))
00019 #else
00020 #define INT_TYPE_MUL_OVERFLOW(a, b)                                        \
00021         ((b) && (INT_TYPE_DIV_OVERFLOW(a, b) || ((a)*(b))/(b) != (a)))
00022 #endif
00023 
00024 #define INT_TYPE_DIV_OVERFLOW(a, b)  (INT_TYPE_NEG_OVERFLOW(a) && (b) == -1)
00025 
00026 #define INT_TYPE_NEG_OVERFLOW(x)     ((x) && (x) == -(x))
00027 
00028 #define INT_TYPE_ADD_OVERFLOW(a, b)                                        \
00029         (INT_TYPE_SIGN(a) == INT_TYPE_SIGN(b) &&                           \
00030          INT_TYPE_SIGN(a) != INT_TYPE_SIGN((a)+(b)))
00031 
00032 #define INT_TYPE_SUB_OVERFLOW(a, b)                                        \
00033         (INT_TYPE_SIGN(a) != INT_TYPE_SIGN(b) &&                           \
00034          INT_TYPE_SIGN(a) != INT_TYPE_SIGN((a)-(b)))
00035 
00036 #define INT_TYPE_LSH_OVERFLOW(a, b)                                        \
00037         ((((INT_TYPE)sizeof(INT_TYPE))*CHAR_BIT <= (b) && (a)) ||          \
00038          (((a)<<(b))>>(b)) != (a))
00039 
00040 /* Note: If this gives overflow, set the result to zero. */
00041 #define INT_TYPE_RSH_OVERFLOW(a, b)                                        \
00042         (((INT_TYPE)sizeof(INT_TYPE))*CHAR_BIT <= (b) && (a))
00043 
00044 #ifdef AUTO_BIGNUM
00045 
00046 /* Prototypes begin here */
00047 struct program *get_auto_bignum_program(void);
00048 struct program *get_auto_bignum_program_or_zero(void);
00049 void init_auto_bignum(void);
00050 void exit_auto_bignum(void);
00051 void convert_stack_top_to_bignum(void);
00052 void convert_stack_top_with_base_to_bignum(void);
00053 int is_bignum_object(struct object *o);
00054 int is_bignum_object_in_svalue(struct svalue *sv);
00055 struct object *make_bignum_object(void);
00056 struct object *bignum_from_svalue(struct svalue *s);
00057 struct pike_string *string_from_bignum(struct object *o, int base);
00058 void convert_svalue_to_bignum(struct svalue *s);
00059 
00060 #ifdef INT64
00061 PMOD_EXPORT extern void (*push_int64)(INT64 i);
00062 PMOD_EXPORT extern int (*int64_from_bignum) (INT64 *i, struct object *bignum);
00063 PMOD_EXPORT extern void (*reduce_stack_top_bignum) (void);
00064 PMOD_EXPORT void hook_in_int64_funcs (
00065   void (*push_int64_val)(INT64),
00066   int (*int64_from_bignum_val) (INT64 *, struct object *),
00067   void (*reduce_stack_top_bignum_val) (void));
00068 #else
00069 #define push_int64(i) push_int((INT_TYPE)(i))
00070 #define int64_from_bignum(I,BIGNUM)     0
00071 #endif /* INT64 */
00072 /* Prototypes end here */
00073 
00074 #else
00075 
00076 #define push_int64(i) push_int((INT_TYPE)(i))
00077 #define int64_from_bignum(I,BIGNUM)     0
00078 
00079 #endif /* AUTO_BIGNUM */
00080 
00081 #endif /* BIGNUM_H */

Generated on Fri Jul 22 23:44:24 2005 for Pike by  doxygen 1.3.9.1