Fix some printf bugs and document other

This commit is contained in:
bumbread 2022-08-06 11:06:03 +11:00
parent 7582b91334
commit abd8710841
3 changed files with 9 additions and 7 deletions

View File

@ -773,8 +773,8 @@ static inline int pfx(_dtoa)(
// Print decimal point // Print decimal point
if(decimal_point_n) out('.'); if(decimal_point_n) out('.');
// Print fractional part that's made out of digits // Print fractional part that's made out of digits
int prec_digs = prec - mant_digits_n; int prec_digs = prec < mant_digits_n ? prec : mant_digits_n;
while(mant_digits_n) { while(mant_digits_n < prec_digs) {
if(-exp >= mant_digits_n) { if(-exp >= mant_digits_n) {
out('0'); out('0');
} }

View File

@ -106,15 +106,15 @@ int main() {
if(fetestexcept(FE_INVALID)) printf(" FE_INVALID was raised\n"); if(fetestexcept(FE_INVALID)) printf(" FE_INVALID was raised\n");
printf("\n\n=== exp === \n"); printf("\n\n=== exp === \n");
printf("exp(1) = %f\n", exp(1)); printf("exp(1) = %e\n", exp(1));
printf("FV of $100, continuously compounded at 3%% for 1 year = %f\n", printf("FV of $100, continuously compounded at 3%% for 1 year = %e\n",
100*exp(0.03)); 100*exp(0.03));
// special values // special values
printf("exp(-0) = %f\n", exp(-0.0)); printf("exp(-0) = %e\n", exp(-0.0));
printf("exp(-Inf) = %f\n", exp(-INFINITY)); printf("exp(-Inf) = %e\n", exp(-INFINITY));
//error handling //error handling
errno = 0; feclearexcept(FE_ALL_EXCEPT); errno = 0; feclearexcept(FE_ALL_EXCEPT);
printf("exp(710) = %f\n", exp(710)); printf("exp(710) = %e\n", exp(710));
if(errno == ERANGE) printf(" errno == ERANGE\n"); if(errno == ERANGE) printf(" errno == ERANGE\n");
if(fetestexcept(FE_OVERFLOW)) printf(" FE_OVERFLOW raised\n"); if(fetestexcept(FE_OVERFLOW)) printf(" FE_OVERFLOW raised\n");

2
todo
View File

@ -48,6 +48,8 @@ stdio.h:
* tmpnam * tmpnam
* tmpfile_s * tmpfile_s
* tmpnam_s * tmpnam_s
* Printing 8.98846567431157854073e+307
* Printing negative zero
stdlib.h: stdlib.h:
* Strtod base 16 must be correctly rounded * Strtod base 16 must be correctly rounded