dofptoa.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 1996 by Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* dofptoa - do the grunge work to convert an fp number to ascii
*/
#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 short dec;
char *buf;
char *bp;
/*
* Get a string buffer before starting
*/
/*
* Zero out the buffer
*/
/*
* Set the pointers to point at the first
* decimal place. Get a local copy of the value.
*/
/*
* If we have to, decode the integral part
*/
if (!(val & 0xffff0000))
cp--;
else {
do {
} while (sv != 0);
}
/*
* Figure out how much of the fraction to do
*/
if (msec) {
if (dec < 3)
dec = 3;
} else {
}
if (dec > 6)
dec = 6;
if (dec > 0) {
do {
val &= 0xffff;
} while (--dec > 0);
}
if (val & 0x8000) {
/*
* Round it. Ick.
*/
*(--tp) += 1;
while (*tp >= 10) {
*tp = 0;
*(--tp) += 1;
}
}
/*
* Remove leading zeroes if necessary
*/
cp++;
/*
* Copy it into the buffer, asciizing as we go.
*/
if (neg)
*bp++ = '-';
*bp++ = '.';
}
*bp = '\0';
return buf;
}