Back to index

php5  5.3.10
bcmath.h
Go to the documentation of this file.
00001 /* bcmath.h: bcmath library header.       */
00002 /*
00003     Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
00004     Copyright (C) 2000 Philip A. Nelson
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Lesser General Public License for more details.  (COPYING.LIB)
00015 
00016     You should have received a copy of the GNU Lesser General Public
00017     License along with this library; if not, write to:
00018 
00019       The Free Software Foundation, Inc.
00020       59 Temple Place, Suite 330
00021       Boston, MA 02111-1307 USA.
00022 
00023     You may contact the author by:
00024        e-mail:  philnelson@acm.org
00025       us-mail:  Philip A. Nelson
00026                 Computer Science Department, 9062
00027                 Western Washington University
00028                 Bellingham, WA 98226-9062
00029        
00030 *************************************************************************/
00031 
00032 #ifndef _BCMATH_H_
00033 #define _BCMATH_H_
00034 
00035 typedef enum {PLUS, MINUS} sign;
00036 
00037 typedef struct bc_struct *bc_num;
00038 
00039 typedef struct bc_struct
00040     {
00041       sign  n_sign;
00042       int   n_len;   /* The number of digits before the decimal point. */
00043       int   n_scale; /* The number of digits after the decimal point. */
00044       int   n_refs;     /* The number of pointers to this number. */
00045       bc_num n_next; /* Linked list for available list. */
00046       char *n_ptr;   /* The pointer to the actual storage.
00047                         If NULL, n_value points to the inside of
00048                         another number (bc_multiply...) and should
00049                         not be "freed." */
00050       char *n_value; /* The number. Not zero char terminated.
00051                         May not point to the same place as n_ptr as
00052                         in the case of leading zeros generated. */
00053     } bc_struct;
00054 
00055 #ifdef HAVE_CONFIG_H
00056 #include "config.h"
00057 #endif
00058 
00059 #include "php.h"
00060 #include "../../php_bcmath.h"
00061 
00062 /* The base used in storing the numbers in n_value above.
00063    Currently this MUST be 10. */
00064 
00065 #define BASE 10
00066 
00067 /*  Some useful macros and constants. */
00068 
00069 #define CH_VAL(c)     (c - '0')
00070 #define BCD_CHAR(d)   (d + '0')
00071 
00072 #ifdef MIN
00073 #undef MIN
00074 #undef MAX
00075 #endif
00076 #define MAX(a, b)      ((a)>(b)?(a):(b))
00077 #define MIN(a, b)      ((a)>(b)?(b):(a))
00078 #define ODD(a)        ((a)&1)
00079 
00080 #ifndef TRUE
00081 #define TRUE 1
00082 #define FALSE 0
00083 #endif
00084 
00085 #ifndef LONG_MAX
00086 #define LONG_MAX 0x7ffffff
00087 #endif
00088 
00089 
00090 /* Function Prototypes */
00091 
00092 /* Define the _PROTOTYPE macro if it is needed. */
00093 
00094 #ifndef _PROTOTYPE
00095 #ifdef __STDC__
00096 #define _PROTOTYPE(func, args) func args
00097 #else
00098 #define _PROTOTYPE(func, args) func()
00099 #endif
00100 #endif
00101 
00102 _PROTOTYPE(void bc_init_numbers, (TSRMLS_D));
00103 
00104 _PROTOTYPE(bc_num _bc_new_num_ex, (int length, int scale, int persistent));
00105 
00106 _PROTOTYPE(void _bc_free_num_ex, (bc_num *num, int persistent));
00107 
00108 _PROTOTYPE(bc_num bc_copy_num, (bc_num num));
00109 
00110 _PROTOTYPE(void bc_init_num, (bc_num *num TSRMLS_DC));
00111 
00112 _PROTOTYPE(void bc_str2num, (bc_num *num, char *str, int scale TSRMLS_DC));
00113 
00114 _PROTOTYPE(char *bc_num2str, (bc_num num));
00115 
00116 _PROTOTYPE(void bc_int2num, (bc_num *num, int val));
00117 
00118 _PROTOTYPE(long bc_num2long, (bc_num num));
00119 
00120 _PROTOTYPE(int bc_compare, (bc_num n1, bc_num n2));
00121 
00122 _PROTOTYPE(char bc_is_zero, (bc_num num TSRMLS_DC));
00123 
00124 _PROTOTYPE(char bc_is_near_zero, (bc_num num, int scale));
00125 
00126 _PROTOTYPE(char bc_is_neg, (bc_num num));
00127 
00128 _PROTOTYPE(void bc_add, (bc_num n1, bc_num n2, bc_num *result, int scale_min));
00129 
00130 _PROTOTYPE(void bc_sub, (bc_num n1, bc_num n2, bc_num *result, int scale_min));
00131 
00132 _PROTOTYPE(void bc_multiply, (bc_num n1, bc_num n2, bc_num *prod, int scale TSRMLS_DC));
00133 
00134 _PROTOTYPE(int bc_divide, (bc_num n1, bc_num n2, bc_num *quot, int scale TSRMLS_DC));
00135 
00136 _PROTOTYPE(int bc_modulo, (bc_num num1, bc_num num2, bc_num *result,
00137                         int scale TSRMLS_DC));
00138 
00139 _PROTOTYPE(int bc_divmod, (bc_num num1, bc_num num2, bc_num *quot,
00140                         bc_num *rem, int scale TSRMLS_DC));
00141 
00142 _PROTOTYPE(int bc_raisemod, (bc_num base, bc_num expo, bc_num mod,
00143                           bc_num *result, int scale TSRMLS_DC));
00144 
00145 _PROTOTYPE(void bc_raise, (bc_num num1, bc_num num2, bc_num *result,
00146                         int scale TSRMLS_DC));
00147 
00148 _PROTOTYPE(int bc_sqrt, (bc_num *num, int scale TSRMLS_DC));
00149 
00150 _PROTOTYPE(void bc_out_num, (bc_num num, int o_base, void (* out_char)(int),
00151                           int leading_zero TSRMLS_DC));
00152 
00153 /* Prototypes needed for external utility routines. */
00154 
00155 _PROTOTYPE(void bc_rt_warn, (char *mesg ,...));
00156 _PROTOTYPE(void bc_rt_error, (char *mesg ,...));
00157 _PROTOTYPE(void bc_out_of_memory, (void));
00158 
00159 #define bc_new_num(length, scale)  _bc_new_num_ex((length), (scale), 0)
00160 #define bc_free_num(num)                  _bc_free_num_ex((num), 0)
00161 
00162 #endif