Skip to content

Commit

Permalink
Regards #62.
Browse files Browse the repository at this point in the history
* Now using `DSS_HUGE` instead of `long` in all of of the `bcd2.*` functions.
* "Split" the `DSS_HUGE` format specifier macro in `config.h` so that the specifier can be used separately.
* `bcd2.*` now depend on `config.h`
  • Loading branch information
Eyal Rozenberg authored and valco1994 committed Feb 27, 2019
1 parent 8d35602 commit 78b0e36
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 40 deletions.
50 changes: 21 additions & 29 deletions src/bcd2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
/*
* bcd.c: conversion routines for multi-byte arithmetic
*
* defined routines:
* bin_bcd2(long binary, long *low_res, long *high_res)
* bcd2_bin(long *dest, long bcd)
* bcd2_add(long *bcd_low, long *bcd_high, long addend)
* bcd2_sub(long *bcd_low, long *bcd_high, long subend)
* bcd2_mul(long *bcd_low, long *bcd_high, long multiplier)
* bcd2_div(long *bcd_low, long *bcd_high, long divisor)
* long bcd2_mod(long *bcd_low, long *bcd_high, long modulo)
* long bcd2_cmp(long *bcd_low, long *bcd_high, long compare)
*/
#include <stdio.h>
#include "bcd2.h" /* for function prototypes */
Expand All @@ -34,16 +25,17 @@
*low = (*low & (0xFFFFFFF ^ (0xF << (4 * (num))))); \
*low |= (value << (4 * (num))); \
}

int
bin_bcd2(long binary, long *low_res, long *high_res)
bin_bcd2(DSS_HUGE binary, DSS_HUGE *low_res, DSS_HUGE *high_res)
{
char number[15],
*current;
int count;
long *dest;
DSS_HUGE *dest;

*low_res = *high_res = 0;
sprintf(number, "%014ld", binary);
sprintf(number, "%014" HUGE_FORMAT_SPECIFIER, binary);
for (current = number, count=13; *current; current++, count--)
{
dest = (count < DIGITS_PER_LONG)?low_res:high_res;
Expand All @@ -54,10 +46,10 @@ bin_bcd2(long binary, long *low_res, long *high_res)
}

int
bcd2_bin(long *dest, long bcd)
bcd2_bin(DSS_HUGE *dest, DSS_HUGE bcd)
{
int count;
long mask;
DSS_HUGE mask;

count = DIGITS_PER_LONG - 1;
mask = 0xF000000;
Expand All @@ -73,9 +65,9 @@ bcd2_bin(long *dest, long bcd)
}

int
bcd2_add(long *bcd_low, long *bcd_high, long addend)
bcd2_add(DSS_HUGE *bcd_low, DSS_HUGE *bcd_high, DSS_HUGE addend)
{
long tmp_lo, tmp_hi, carry, res;
DSS_HUGE tmp_lo, tmp_hi, carry, res;
int digit;

bin_bcd2(addend, &tmp_lo, &tmp_hi);
Expand All @@ -93,9 +85,9 @@ bcd2_add(long *bcd_low, long *bcd_high, long addend)
}

int
bcd2_sub(long *bcd_low, long *bcd_high, long subend)
bcd2_sub(DSS_HUGE *bcd_low, DSS_HUGE *bcd_high, DSS_HUGE subend)
{
long tmp_lo, tmp_hi, carry, res;
DSS_HUGE tmp_lo, tmp_hi, carry, res;
int digit;

bin_bcd2(subend, &tmp_lo, &tmp_hi);
Expand All @@ -116,9 +108,9 @@ bcd2_sub(long *bcd_low, long *bcd_high, long subend)
}

int
bcd2_mul(long *bcd_low, long *bcd_high, long multiplier)
bcd2_mul(DSS_HUGE *bcd_low, DSS_HUGE *bcd_high, DSS_HUGE multiplier)
{
long tmp_lo, tmp_hi, carry, m_lo, m_hi, m1, m2;
DSS_HUGE tmp_lo, tmp_hi, carry, m_lo, m_hi, m1, m2;
int udigit, ldigit, res;

tmp_lo = *bcd_low;
Expand Down Expand Up @@ -153,9 +145,9 @@ bcd2_mul(long *bcd_low, long *bcd_high, long multiplier)
}

int
bcd2_div(long *bcd_low, long *bcd_high, long divisor)
bcd2_div(DSS_HUGE *bcd_low, DSS_HUGE *bcd_high, DSS_HUGE divisor)
{
long tmp_lo, tmp_hi, carry, d1, res, digit;
DSS_HUGE tmp_lo, tmp_hi, carry, d1, res, digit;


carry = 0;
Expand All @@ -173,10 +165,10 @@ bcd2_div(long *bcd_low, long *bcd_high, long divisor)
return(carry);
}

long
bcd2_mod(long *bcd_low, long *bcd_high, long modulo)
DSS_HUGE
bcd2_mod(DSS_HUGE *bcd_low, DSS_HUGE *bcd_high, DSS_HUGE modulo)
{
long tmp_low, tmp_high;
DSS_HUGE tmp_low, tmp_high;

tmp_low = *bcd_low;
tmp_high = *bcd_high;
Expand All @@ -185,10 +177,10 @@ bcd2_mod(long *bcd_low, long *bcd_high, long modulo)
return(tmp_low);
}

long
bcd2_cmp(long *low1, long *high1, long comp)
DSS_HUGE
bcd2_cmp(DSS_HUGE *low1, DSS_HUGE *high1, DSS_HUGE comp)
{
long temp = 0;
DSS_HUGE temp = 0;

bcd2_bin(&temp, *high1);
if (temp > 214)
Expand All @@ -202,7 +194,7 @@ bcd2_cmp(long *low1, long *high1, long comp)

int main()
{
long bin, low_bcd, high_bcd;
DSS_HUGE bin, low_bcd, high_bcd;
int i;

bin = MAXINT;
Expand Down
19 changes: 11 additions & 8 deletions src/bcd2.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/*
* Sccsid: @(#)bcd2.h 2.1.8.1
*/
int bin_bcd2(long binary, long *low_res, long *high_res);
int bcd2_bin(long *dest, long bcd);
int bcd2_add(long *bcd_low, long *bcd_high, long addend);
int bcd2_sub(long *bcd_low, long *bcd_high, long subend);
int bcd2_mul(long *bcd_low, long *bcd_high, long multiplier);
int bcd2_div(long *bcd_low, long *bcd_high, long divisor);
long bcd2_mod(long *bcd_low, long *bcd_high, long modulo);
long bcd2_cmp(long *bcd_low, long *bcd_high, long compare);

#include "config.h"

int bin_bcd2(DSS_HUGE binary, DSS_HUGE *low_res, DSS_HUGE *high_res);
int bcd2_bin(DSS_HUGE *dest, DSS_HUGE bcd);
int bcd2_add(DSS_HUGE *bcd_low, DSS_HUGE *bcd_high, DSS_HUGE addend);
int bcd2_sub(DSS_HUGE *bcd_low, DSS_HUGE *bcd_high, DSS_HUGE subend);
int bcd2_mul(DSS_HUGE *bcd_low, DSS_HUGE *bcd_high, DSS_HUGE multiplier);
int bcd2_div(DSS_HUGE *bcd_low, DSS_HUGE *bcd_high, DSS_HUGE divisor);
DSS_HUGE bcd2_mod(DSS_HUGE *bcd_low, DSS_HUGE *bcd_high, DSS_HUGE modulo);
DSS_HUGE bcd2_cmp(DSS_HUGE *bcd_low, DSS_HUGE *bcd_high, DSS_HUGE compare);
2 changes: 1 addition & 1 deletion src/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ ez_sparse(long i, DSS_HUGE *ok, long seq)
void
hd_sparse(long i, DSS_HUGE *ok, long seq)
{
long low_mask, seq_mask;
DSS_HUGE low_mask, seq_mask;
static int init = 0;
static DSS_HUGE *base, *res;

Expand Down
5 changes: 3 additions & 2 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@
#endif

#define DSS_HUGE SIGNED_64_BIT_C_TYPE
#define HUGE_FORMAT "%" SIGNED_64_BIT_PRINTF_MODIFIER "d"
#define HUGE_FORMAT_SPECIFIER SIGNED_64_BIT_PRINTF_MODIFIER "d"
#define HUGE_FORMAT "%" HUGE_FORMAT_SPECIFIER
#define HUGE_COUNT 1
#define HUGE_DATE_FORMAT "%02" SIGNED_64_BIT_PRINTF_MODIFIER "d"
#define HUGE_DATE_FORMAT "%02" HUGE_FORMAT_SPECIFIER

#cmakedefine01 HAVE_GETOPT
#if (HAVE_GETOPT == 1)
Expand Down

0 comments on commit 78b0e36

Please sign in to comment.