Back to index

texmacs  1.0.7.15
Functions
numbers.c File Reference
#include "system.h"
#include "error.h"
#include "mfileio.h"
#include "numbers.h"

Go to the source code of this file.

Functions

UNSIGNED_BYTE get_unsigned_byte (FILE *file)
SIGNED_BYTE get_signed_byte (FILE *file)
UNSIGNED_PAIR get_unsigned_pair (FILE *file)
UNSIGNED_PAIR sget_unsigned_pair (unsigned char *s)
SIGNED_PAIR get_signed_pair (FILE *file)
UNSIGNED_TRIPLE get_unsigned_triple (FILE *file)
SIGNED_TRIPLE get_signed_triple (FILE *file)
SIGNED_QUAD get_signed_quad (FILE *file)
UNSIGNED_QUAD get_unsigned_quad (FILE *file)
SIGNED_QUAD sqxfw (SIGNED_QUAD sq, fixword fw)

Function Documentation

SIGNED_BYTE get_signed_byte ( FILE *  file)

Definition at line 45 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:

SIGNED_PAIR get_signed_pair ( FILE *  file)

Definition at line 78 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:

SIGNED_QUAD get_signed_quad ( FILE *  file)

Definition at line 114 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:

SIGNED_TRIPLE get_signed_triple ( FILE *  file)

Definition at line 102 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:

UNSIGNED_BYTE get_unsigned_byte ( FILE *  file)

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 call graph for this function:

Here is the caller graph for this function:

UNSIGNED_PAIR get_unsigned_pair ( FILE *  file)

Definition at line 54 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:

UNSIGNED_QUAD get_unsigned_quad ( FILE *  file)

Definition at line 130 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 92 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:

UNSIGNED_PAIR sget_unsigned_pair ( unsigned char *  s)

Definition at line 66 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;
}

Here is the caller graph for this function:

Definition at line 140 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 * -1L;
}

Here is the call graph for this function: