mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-12-27 05:40:17 +05:30
floatscan-experiment.c: upgrade the experiment code, do not use STDIN
This commit is contained in:
parent
ca099f2797
commit
4f9ceae08f
@ -18,7 +18,12 @@
|
||||
#include <stdio.h>
|
||||
|
||||
/* wrapping code --- beginning */
|
||||
#define shgetc(f) fgetc(f)
|
||||
const char* fgetc_ptr = NULL;
|
||||
|
||||
int __shgetc(void);
|
||||
long double floatscan(const char* s, int prec);
|
||||
|
||||
#define shgetc(f) __shgetc()
|
||||
#define shlim(...)
|
||||
#define shunget(...)
|
||||
|
||||
@ -531,10 +536,28 @@ long double __floatscan(FILE *f, int prec, int pok)
|
||||
}
|
||||
/* the original musl libc code --- end */
|
||||
|
||||
/* wrapping code --- beginning */
|
||||
int __shgetc(void) {
|
||||
return *fgetc_ptr++;
|
||||
}
|
||||
|
||||
long double floatscan(const char* s, int prec) {
|
||||
fgetc_ptr = s;
|
||||
return __floatscan(NULL, prec, 1);
|
||||
}
|
||||
/* wrapping code --- end */
|
||||
|
||||
/* test code --- beginning */
|
||||
int main(void) {
|
||||
printf("LD_B1B_DIG = %d\n", LD_B1B_DIG);
|
||||
printf("%La\n", __floatscan(stdin, LONG_DOUBLE_TYPE, 1));
|
||||
int main(int argc, char** argv) {
|
||||
char* value = argc > 1 ? argv[1] : "+314.1e-2";
|
||||
const int prec = LD_B1B_DIG;
|
||||
|
||||
printf("Selected precision index = %d\n", prec);
|
||||
long double result = floatscan(value, LONG_DOUBLE_TYPE);
|
||||
printf("Input : %s\n", value);
|
||||
printf("Decimal floating-point format: %Lf\n", result);
|
||||
printf("Double floating-point format : %Lg\n", result);
|
||||
printf("Hexadecimal form : %La\n", result);
|
||||
return 0;
|
||||
}
|
||||
/* test code --- end */
|
||||
|
Loading…
Reference in New Issue
Block a user