"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libnetbsd/snprintf.c" between
tnftp-20151004.tar.gz and tnftp-20200705.tar.gz

About: tnftp is an enhanced ftp client (prior name "lukemftp").

snprintf.c  (tnftp-20151004):snprintf.c  (tnftp-20200705)
/* $NetBSD: snprintf.c,v 1.6 2007/07/22 05:19:02 lukem Exp $ */ /* $NetBSD: snprintf.c,v 1.7 2020/07/05 10:08:59 lukem Exp $ */
/* /*
* Copyright Patrick Powell 1995 * Copyright Patrick Powell 1995
* This code is based on code written by Patrick Powell (papowell@astart.com) * This code is based on code written by Patrick Powell (papowell@astart.com)
* It may be used for any purpose as long as this notice remains intact * It may be used for any purpose as long as this notice remains intact
* on all source code distributions * on all source code distributions
*/ */
/************************************************************** /**************************************************************
* Original: * Original:
skipping to change at line 502 skipping to change at line 502
{ {
LDOUBLE result = value; LDOUBLE result = value;
if (value < 0) if (value < 0)
result = -value; result = -value;
return result; return result;
} }
static LDOUBLE static LDOUBLE
pow10(int exp) sn_pow10(int exp)
{ {
LDOUBLE result = 1; LDOUBLE result = 1;
while (exp) { while (exp) {
result *= 10; result *= 10;
exp--; exp--;
} }
return result; return result;
} }
static long static long
round(LDOUBLE value) sn_round(LDOUBLE value)
{ {
long intpart; long intpart;
intpart = (long) value; intpart = (long) value;
value = value - intpart; value = value - intpart;
if (value >= 0.5) if (value >= 0.5)
intpart++; intpart++;
return intpart; return intpart;
} }
skipping to change at line 571 skipping to change at line 571
intpart = (long) ufvalue; intpart = (long) ufvalue;
/* Sorry, we only support 9 digits past the decimal because of our /* Sorry, we only support 9 digits past the decimal because of our
* conversion method */ * conversion method */
if (max > 9) if (max > 9)
max = 9; max = 9;
/* We "cheat" by converting the fractional part to integer by /* We "cheat" by converting the fractional part to integer by
* multiplying by a factor of 10 */ * multiplying by a factor of 10 */
fracpart = round((pow10(max)) * (ufvalue - intpart)); fracpart = sn_round((sn_pow10(max)) * (ufvalue - intpart));
if (fracpart >= pow10(max)) { if (fracpart >= sn_pow10(max)) {
intpart++; intpart++;
fracpart -= pow10(max); fracpart -= sn_pow10(max);
} }
#ifdef DEBUG_SNPRINTF #ifdef DEBUG_SNPRINTF
printf("fmtfp: %g %d.%d min=%d max=%d\n", printf("fmtfp: %g %d.%d min=%d max=%d\n",
(double) fvalue, intpart, fracpart, min, max); (double) fvalue, intpart, fracpart, min, max);
#endif #endif
/* Convert integer part */ /* Convert integer part */
do { do {
iconvert[iplace++] = iconvert[iplace++] =
(caps ? "0123456789ABCDEF" (caps ? "0123456789ABCDEF"
 End of changes. 6 change blocks. 
6 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)