dolfptoa.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 1996 by Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* dolfptoa - do the grunge work of converting an l_fp number to decimal
*/
#include <stdio.h>
#include "ntp_fp.h"
#include "lib_strbuf.h"
#include "ntp_string.h"
#include "ntp_stdlib.h"
char *
int neg;
int ndec;
int msec;
{
register int dec;
char *buf;
char *bp;
/*
* Get a string buffer before starting
*/
/*
* Zero the character buffer
*/
/*
* Work on the integral part. This is biased by what I know
* compiles fairly well for a 68000.
*/
if (lwork & 0xffff0000) {
do {
} while (lwork & 0xffff0000);
}
if (lwork != 0) {
do {
} while (swork != 0);
}
/*
* Done that, now deal with the problem of the fraction. First
* determine the number of decimal places.
*/
if (msec) {
if (dec < 3)
dec = 3;
} else {
if (dec < 0)
dec = 0;
}
if (dec > 12)
dec = 12;
/*
* If there's a fraction to deal with, do so.
*/
if (fpv != 0) {
while (dec > 0) {
dec--;
/*
* The scheme here is to multiply the
* fraction (0.1234...) by ten. This moves
* a junk of BCD into the units part.
* record that and iterate.
*/
break;
}
/*
* Rounding is rotten
*/
*(--tp) += 1;
while (*tp >= 10) {
*tp = 0;
*(--tp) += 1;
};
}
}
/*
* We've now got the fraction in cbuf[], with cp pointing at
* the first character, cpend pointing past the last, and
* cpdec pointing at the first character past the decimal.
* Remove leading zeros, then format the number into the
* buffer.
*/
if (*cp != 0)
break;
cp++;
}
--cp;
if (neg)
*bp++ = '-';
*bp++ = '.';
}
*bp = '\0';
/*
* Done!
*/
return buf;
}