#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <float.h>
//#pragma warning(disable : 4996)
#define L 1024
static const char Digit[] = "0123456789";
int GetDigit(int64_t N){
int i = 0;
while (N != 0){
i++;
N /= 10;
}
return i;
}
int MakeUpper(char Out[L], double N){
int64_t U
= (int64_t)floor(N
); int D = GetDigit(U);
int V = 0;
if (U == 0){
Out[0] = Digit[0];
Out[1] = '\0';
return 0;
}
Out[D] = '\0';
D--;
while (U != 0){
V = U % 10;
Out[D] = Digit[V];
D--;
U /= 10;
}
return 0;
}
int MakeBottom(char Out[L], double N){
double Diff = 1;
double P = 1;
int i = 0;
int j = 0;
char Z[L] = "\0";
char B[L] = "\0";
while ((Diff) > DBL_EPSILON){
P *= 10;
Diff
= (N
-U
)*P
- floor((N
-U
)*P
); }
for (i = 10; i < P; i *= 10){
if ((N - U) <= DBL_EPSILON) break;
if (floor((N
-U
)*i
) > 0) break; Z[j] = Digit[0];
j++;
}
Z[j] = '\0';
MakeUpper(B, (N-U)*P);
return 0;
}
int MakeHoge(char Out[L], double N){
char U[L] = "\0";
char D[L] = "\0";
MakeUpper(U, N);
MakeBottom(D, N);
Out[0] = '\0';
return 0;
}
int OutPut(char B[L]){
int i = 0;
for (i = 0; i < L; i++){
if (B[i] == '\0') break;
}
return 0;
}
int main(){
char Out[L];
MakeHoge(Out, 123456789.0123456789);
OutPut(Out);
MakeHoge(Out,0.031415926);
OutPut(Out);
MakeHoge(Out,0.31415926);
OutPut(Out);
MakeHoge(Out,3.1415926);
OutPut(Out);
MakeHoge(Out,31.415926);
OutPut(Out);
MakeHoge(Out,314.15926);
OutPut(Out);
MakeHoge(Out,0.00031415926);
OutPut(Out);
MakeHoge(Out,0.0);
OutPut(Out);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPG1hdGguaD4KI2luY2x1ZGUgPHN0ZGludC5oPgojaW5jbHVkZSA8ZmxvYXQ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