Back to index

tetex-bin  3.0
Defines | Typedefs | Functions
numbers.h File Reference
#include <stdio.h>
#include <math.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ROUND(n, acc)   (floor(((double)n)/(acc)+0.5)*(acc))
#define MAX(a, b)   ((a)>(b)?(a):(b))
#define MIN(a, b)   ((a)<(b)?(a):(b))
#define ISODD(n)   (((n)/2)*2!=(n))
#define ISEVEN(n)   (((n)/2)*2==(n))
#define IDIVRND(a, b)   ((a)>0? ((a)+(b)/2)/(b): -((-(a)+(b)/2)/(b)))
#define IDIV(a, b)   ((a)>0? (a)/(b): -(-(a))/(b))

Typedefs

typedef unsigned char Ubyte
typedef int UNSIGNED_BYTE
typedef int SIGNED_BYTE
typedef int SIGNED_PAIR
typedef unsigned UNSIGNED_PAIR
typedef long UNSIGNED_TRIPLE
typedef long SIGNED_TRIPLE
typedef long SIGNED_QUAD
typedef unsigned long UNSIGNED_QUAD
typedef signed long fixword

Functions

UNSIGNED_BYTE get_unsigned_byte (FILE *)
UNSIGNED_BYTE sget_unsigned_byte (char *)
SIGNED_BYTE get_signed_byte (FILE *)
UNSIGNED_PAIR get_unsigned_pair (FILE *)
UNSIGNED_PAIR sget_unsigned_pair (unsigned char *)
SIGNED_PAIR get_signed_pair (FILE *)
UNSIGNED_TRIPLE get_unsigned_triple (FILE *)
SIGNED_TRIPLE get_signed_triple (FILE *)
SIGNED_QUAD get_signed_quad (FILE *)
UNSIGNED_QUAD get_unsigned_quad (FILE *)
SIGNED_QUAD sqxfw (SIGNED_QUAD sq, fixword fw)
SIGNED_QUAD axboverc (SIGNED_QUAD n1, SIGNED_QUAD n2, SIGNED_QUAD div)
int fixnumtoa (char *s, long int i)
int inttoa (char *s, long int i)
int centi_u_to_a (char *s, long int i)

Define Documentation

#define IDIV (   a,
  b 
)    ((a)>0? (a)/(b): -(-(a))/(b))

Definition at line 82 of file numbers.h.

#define IDIVRND (   a,
  b 
)    ((a)>0? ((a)+(b)/2)/(b): -((-(a)+(b)/2)/(b)))

Definition at line 80 of file numbers.h.

#define ISEVEN (   n)    (((n)/2)*2==(n))

Definition at line 68 of file numbers.h.

#define ISODD (   n)    (((n)/2)*2!=(n))

Definition at line 67 of file numbers.h.

#define MAX (   a,
  b 
)    ((a)>(b)?(a):(b))

Definition at line 61 of file numbers.h.

#define MIN (   a,
  b 
)    ((a)<(b)?(a):(b))

Definition at line 64 of file numbers.h.

#define ROUND (   n,
  acc 
)    (floor(((double)n)/(acc)+0.5)*(acc))

Definition at line 59 of file numbers.h.


Typedef Documentation

typedef signed long fixword

Definition at line 70 of file numbers.h.

typedef int SIGNED_BYTE

Definition at line 34 of file numbers.h.

typedef int SIGNED_PAIR

Definition at line 34 of file numbers.h.

typedef long SIGNED_QUAD

Definition at line 36 of file numbers.h.

typedef long SIGNED_TRIPLE

Definition at line 36 of file numbers.h.

typedef unsigned char Ubyte

Definition at line 32 of file numbers.h.

typedef int UNSIGNED_BYTE

Definition at line 34 of file numbers.h.

typedef unsigned UNSIGNED_PAIR

Definition at line 35 of file numbers.h.

typedef unsigned long UNSIGNED_QUAD

Definition at line 37 of file numbers.h.

typedef long UNSIGNED_TRIPLE

Definition at line 36 of file numbers.h.


Function Documentation

Definition at line 171 of file numbers.c.

{
  int sign = 1;
  unsigned long a, b, c, d, ad, bd, bc, ac, e, f, g, h, i, j, o;
  unsigned long high, low;
  SIGNED_QUAD result = 0;
  /*  Make positive. */
  if (n1 < 0) {
    sign = -sign;
    n1 = -n1;
  }
  if (n2 < 0) {
    sign = -sign;
    n2 = -n2;
  }
  if (div < 0) {
    sign = -sign;
    div = -div;
  }
  a = ((unsigned long) n1) >> 16u;
  b = ((unsigned long) n1) & 0xffffu;
  c = ((unsigned long) n2) >> 16u;
  d = ((unsigned long) n2) & 0xffffu;
  ad = a*d; bd = b*d; bc = b*c; ac = a*c;
  e = bd >> 16u; f = bd & 0xffffu;
  g = ad >> 16u; h = ad & 0xffffu;
  i = bc >> 16u; j = bc & 0xffffu;
  o = e+h+j;
  high = g+i+(o>>16u)+ac; o &= 0xffffu;
  low = (o << 16) + f;
  if (high >= div)
    ERROR ("Overflow in axboc");
  {
    int i;
    for (i=0; i<32; i++) {
      high *= 2;
      result *= 2;
      if (low >= 0x80000000) {
       low -= 0x80000000;
       high += 1;
      }
      low *= 2;
      if (high > div) {
       high -= div;
       result += 1;
      }
    }
  }
  high *= 2;
  if (high >= div)
    result += 1;
  return (sign>0)?result:-result;
}
int centi_u_to_a ( char *  s,
long int  i 
)

Definition at line 258 of file numbers.c.

{
  char *p = s;
  unsigned long whole_part;
  int frac_part;
  if (n<0) {
    *(p++) = '-';
    n = -n;
  }
  whole_part = ((unsigned long) n) / 100;
  frac_part = ((unsigned long) n) % 100;
  /* Print the whole part */
  p += private_itoa (p, whole_part, 0);
  if (frac_part) {
    int mindigits = 2;
    *(p++) = '.';
    while (!(frac_part % 10)) {
      frac_part /= 10;
      mindigits -= 1;
    }
    p += private_itoa (p, frac_part, mindigits);
  }
  return (p-s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int fixnumtoa ( char *  s,
long int  i 
)

Definition at line 283 of file numbers.c.

{
   int j, thresh;
   char *p = s;
   unsigned long whole_part, frac_part;
   if (n<0) {
      *(p++) = '-';
      n = -n;
   }
   whole_part = ((unsigned long) n) / (65536l);
   frac_part = ((unsigned long) n) % 65536l;
   /* Print the whole part */
   p += private_itoa (p, whole_part, 0);

   #define BASE ((unsigned long)(256*65536l))
   frac_part *= 256;
   thresh = BASE / 10000;
   /* Round last digit */
   frac_part += thresh/2;
   if (frac_part > thresh) {
      *(p++) = '.';
   }
   for (j=0; j<4 && frac_part> thresh; j++) {
      char next_digit;
      next_digit = (10*frac_part)/BASE;
      frac_part = (10*frac_part)%BASE;
      *(p++) = next_digit + '0';
      thresh *= 10;
   }
   *p = 0;
   return (p-s);
}

Here is the call graph for this function:

Definition at line 43 of file numbers.c.

{
  int byte;
  byte = get_unsigned_byte(file);
  if (byte >= 0x80) 
    byte -= 0x100;
  return (SIGNED_BYTE) byte;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 76 of file numbers.c.

{
  int i;
  long pair = 0;
  for (i=0; i<2; i++) {
    pair = pair*0x100 + get_unsigned_byte(file);
  }
  if (pair >= 0x8000) {
    pair -= 0x10000l;
  }
  return (SIGNED_PAIR) pair;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 112 of file numbers.c.

{
  int byte, i;
  long quad = 0;

  /* Check sign on first byte before reading others */
  byte = get_unsigned_byte(file);
  quad = byte;
  if (quad >= 0x80) 
    quad = byte - 0x100;
  for (i=0; i<3; i++) {
    quad = quad*0x100 + get_unsigned_byte(file);
  }
  return (SIGNED_QUAD) quad;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 100 of file numbers.c.

{
  int i;
  long triple = 0;
  for (i=0; i<3; i++) {
    triple = triple*0x100 + get_unsigned_byte(file);
  }
  if (triple >= 0x800000l) 
    triple -= 0x1000000l;
  return (SIGNED_TRIPLE) triple;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 30 of file numbers.c.

{
  int ch;
  if ((ch = fgetc (file)) < 0)
    ERROR ("File ended prematurely\n");
  return (UNSIGNED_BYTE) ch;
}

Here is the caller graph for this function:

Definition at line 52 of file numbers.c.

{
  int i;
  UNSIGNED_BYTE byte;
  UNSIGNED_PAIR pair = 0;
  for (i=0; i<2; i++) {
    byte = get_unsigned_byte(file);
    pair = pair*0x100u + byte;
  }
  return pair;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 128 of file numbers.c.

{
  int i;
  unsigned long quad = 0;
  for (i=0; i<4; i++) {
    quad = quad*0x100u + get_unsigned_byte(file);
  }
  return (UNSIGNED_QUAD) quad;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 90 of file numbers.c.

{
  int i;
  long triple = 0;
  for (i=0; i<3; i++) {
    triple = triple*0x100u + get_unsigned_byte(file);
  }
  return (UNSIGNED_TRIPLE) triple;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int inttoa ( char *  s,
long int  i 
)

Definition at line 252 of file numbers.c.

{
  /* Call the private one */
  return private_itoa (s, i, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 38 of file numbers.c.

{
  return *((unsigned char *) s);
}
UNSIGNED_PAIR sget_unsigned_pair ( unsigned char *  )

Definition at line 64 of file numbers.c.

{
  int i;
  UNSIGNED_BYTE byte;
  UNSIGNED_PAIR pair = 0;
  for (i=0; i<2; i++) {
    byte = *(s++);
    pair = pair*0x100u + byte;
  }
  return pair;
}

Definition at line 138 of file numbers.c.

{
  int sign = 1;
  unsigned long a, b, c, d, ad, bd, bc, ac;
  unsigned long e, f, g, h, i, j, k;
  unsigned long result;
  /* Make positive. */
  if (sq < 0) {
    sign = -sign;
    sq = -sq;
  }
  if (fw < 0) {
    sign = -sign;
    fw = -fw;
  }
  a = ((unsigned long) sq) >> 16u;
  b = ((unsigned long) sq) & 0xffffu;
  c = ((unsigned long) fw) >> 16u;
  d = ((unsigned long) fw) & 0xffffu;
  ad = a*d; bd = b*d; bc = b*c; ac = a*c;
  e = bd >> 16u;
  f = ad >> 16u;
  g = ad & 0xffffu;
  h = bc >> 16u;
  i = bc & 0xffffu;
  j = ac >> 16u;
  k = ac & 0xffffu;
  result = (e+g+i + (1<<3)) >> 4u;  /* 1<<3 is for rounding */
  result += (f+h+k) << 12u;
  result += j << 28u;
  return (sign>0)?result:-result;
}

Here is the caller graph for this function: