Blame h/number.h

Packit 70b277
/* number.h: Arbitrary precision numbers header file. */
Packit 70b277
/*
Packit 70b277
    Copyright (C) 1991, 1992, 1993, 1994, 1997, 2000, 2012-2017 Free Software Foundation, Inc.
Packit 70b277
Packit 70b277
    This program is free software; you can redistribute it and/or modify
Packit 70b277
    it under the terms of the GNU General Public License as published by
Packit 70b277
    the Free Software Foundation; either version 3 of the License , or
Packit 70b277
    (at your option) any later version.
Packit 70b277
Packit 70b277
    This program is distributed in the hope that it will be useful,
Packit 70b277
    but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 70b277
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 70b277
    GNU General Public License for more details.
Packit 70b277
Packit 70b277
    You should have received a copy of the GNU General Public License
Packit 70b277
    along with this program; see the file COPYING.  If not, write to:
Packit 70b277
Packit 70b277
      The Free Software Foundation, Inc.
Packit 70b277
      51 Franklin Street, Fifth Floor
Packit 70b277
      Boston, MA 02110-1301  USA
Packit 70b277
Packit 70b277
Packit 70b277
    You may contact the author by:
Packit 70b277
       e-mail:  philnelson@acm.org
Packit 70b277
      us-mail:  Philip A. Nelson
Packit 70b277
                Computer Science Department, 9062
Packit 70b277
                Western Washington University
Packit 70b277
                Bellingham, WA 98226-9062
Packit 70b277
       
Packit 70b277
*************************************************************************/
Packit 70b277
Packit 70b277
#ifndef _NUMBER_H_
Packit 70b277
#define _NUMBER_H_
Packit 70b277
Packit 70b277
typedef enum {PLUS, MINUS} sign;
Packit 70b277
Packit 70b277
typedef struct bc_struct *bc_num;
Packit 70b277
Packit 70b277
typedef struct bc_struct
Packit 70b277
    {
Packit 70b277
      sign  n_sign;
Packit 70b277
      int   n_len;	/* The number of digits before the decimal point. */
Packit 70b277
      int   n_scale;	/* The number of digits after the decimal point. */
Packit 70b277
      int   n_refs;     /* The number of pointers to this number. */
Packit 70b277
      bc_num n_next;	/* Linked list for available list. */
Packit 70b277
      char *n_ptr;	/* The pointer to the actual storage.
Packit 70b277
			   If NULL, n_value points to the inside of
Packit 70b277
			   another number (bc_multiply...) and should
Packit 70b277
			   not be "freed." */
Packit 70b277
      char *n_value;	/* The number. Not zero char terminated.
Packit 70b277
			   May not point to the same place as n_ptr as
Packit 70b277
			   in the case of leading zeros generated. */
Packit 70b277
    } bc_struct;
Packit 70b277
Packit 70b277
Packit 70b277
/* The base used in storing the numbers in n_value above.
Packit 70b277
   Currently this MUST be 10. */
Packit 70b277
Packit 70b277
#define BASE 10
Packit 70b277
Packit 70b277
/*  Some useful macros and constants. */
Packit 70b277
Packit 70b277
#define CH_VAL(c)     (c - '0')
Packit 70b277
#define BCD_CHAR(d)   (d + '0')
Packit 70b277
Packit 70b277
#ifdef MIN
Packit 70b277
#undef MIN
Packit 70b277
#undef MAX
Packit 70b277
#endif
Packit 70b277
#define MAX(a,b)      ((a)>(b)?(a):(b))
Packit 70b277
#define MIN(a,b)      ((a)>(b)?(b):(a))
Packit 70b277
#define ODD(a)        ((a)&1)
Packit 70b277
Packit 70b277
#ifndef TRUE
Packit 70b277
#define TRUE 1
Packit 70b277
#define FALSE 0
Packit 70b277
#endif
Packit 70b277
Packit 70b277
#ifndef LONG_MAX
Packit 70b277
#define LONG_MAX 0x7fffffff
Packit 70b277
#endif
Packit 70b277
Packit 70b277
Packit 70b277
/* Global numbers. */
Packit 70b277
extern bc_num _zero_;
Packit 70b277
extern bc_num _one_;
Packit 70b277
extern bc_num _two_;
Packit 70b277
Packit 70b277
Packit 70b277
/* Function Prototypes */
Packit 70b277
Packit 70b277
void bc_init_numbers (void);
Packit 70b277
Packit 70b277
bc_num bc_new_num (int length, int scale);
Packit 70b277
Packit 70b277
void bc_free_num (bc_num *num);
Packit 70b277
Packit 70b277
bc_num bc_copy_num (bc_num num);
Packit 70b277
Packit 70b277
void bc_init_num (bc_num *num);
Packit 70b277
Packit 70b277
void bc_str2num (bc_num *num, char *str, int scale);
Packit 70b277
Packit 70b277
char *bc_num2str (bc_num num);
Packit 70b277
Packit 70b277
void bc_int2num (bc_num *num, int val);
Packit 70b277
Packit 70b277
long bc_num2long (bc_num num);
Packit 70b277
Packit 70b277
int bc_compare (bc_num n1, bc_num n2);
Packit 70b277
Packit 70b277
char bc_is_zero (bc_num num);
Packit 70b277
Packit 70b277
char bc_is_near_zero (bc_num num, int scale);
Packit 70b277
Packit 70b277
char bc_is_neg (bc_num num);
Packit 70b277
Packit 70b277
void bc_add (bc_num n1, bc_num n2, bc_num *result, int scale_min);
Packit 70b277
Packit 70b277
void bc_sub (bc_num n1, bc_num n2, bc_num *result, int scale_min);
Packit 70b277
Packit 70b277
void bc_multiply (bc_num n1, bc_num n2, bc_num *prod, int scale);
Packit 70b277
Packit 70b277
int bc_divide (bc_num n1, bc_num n2, bc_num *quot, int scale);
Packit 70b277
Packit 70b277
int bc_modulo (bc_num num1, bc_num num2, bc_num *result, int scale);
Packit 70b277
Packit 70b277
int bc_divmod (bc_num num1, bc_num num2, bc_num *quot,
Packit 70b277
			   bc_num *rem, int scale);
Packit 70b277
Packit 70b277
int bc_raisemod (bc_num base, bc_num expo, bc_num mod,
Packit 70b277
			     bc_num *result, int scale);
Packit 70b277
Packit 70b277
void bc_raise (bc_num num1, bc_num num2, bc_num *result,
Packit 70b277
			   int scale);
Packit 70b277
Packit 70b277
int bc_sqrt (bc_num *num, int scale);
Packit 70b277
Packit 70b277
void bc_out_num (bc_num num, int o_base, void (* out_char)(int),
Packit 70b277
			     int leading_zero);
Packit 70b277
Packit 70b277
void bc_out_long (long val, int size, int space, void (*out_char)(int));
Packit 70b277
#endif