[bugfix] some paths in no-libc mode depend on lib

This commit is contained in:
Yuichi Nishiwaki 2015-07-20 02:45:57 +09:00
parent c2754509f2
commit 86a056c70a
3 changed files with 22 additions and 27 deletions

View File

@ -353,24 +353,26 @@ int xvfprintf(pic_state *pic, xFILE *stream, const char *fmt, va_list ap) {
break; break;
} }
#else #else
# define fabs(x) ((x) >= 0 ? (x) : -(x))
case 'f': { case 'f': {
double dval, dint; double dval = va_arg(ap, double);
dval = modf(va_arg(ap, double), &dint); long lval;
if (dint < 0 || dval < 0) { /* either may be zero */ if (dval < 0) {
dval = -dval;
xputc(pic, '-', stream); xputc(pic, '-', stream);
cnt++; cnt++;
} }
cnt += print_int(pic, stream, (long)fabs(dint), 10); lval = (long)dval;
cnt += print_int(pic, stream, lval, 10);
xputc(pic, '.', stream); xputc(pic, '.', stream);
cnt++; cnt++;
if ((ival = fabs(fabs(dval) * 1e4) + 0.5) == 0) { dval -= lval;
if ((ival = fabs(dval) * 1e4 + 0.5) == 0) {
cnt += xfputs(pic, "0000", stream); cnt += xfputs(pic, "0000", stream);
} else { } else {
int i; if (ival < 1000) xputc(pic, '0', stream); cnt++;
for (i = 0; i < 3 - (int)log10(ival); ++i) { if (ival < 100) xputc(pic, '0', stream); cnt++;
xputc(pic, '0', stream); if (ival < 10) xputc(pic, '0', stream); cnt++;
cnt++;
}
cnt += print_int(pic, stream, ival, 10); cnt += print_int(pic, stream, ival, 10);
} }
break; break;

View File

@ -117,11 +117,6 @@ DEFINE_AOP(div, pic_div(pic, pic_int_value(1), argv[0]), do {
pic_errorf(pic, "/: at least one argument required"); pic_errorf(pic, "/: at least one argument required");
} while (0)) } while (0))
/**
* Returns the length of string representing val.
* radix is between 2 and 36 (inclusive).
* No error checks are performed in this function.
*/
static int static int
number_string_length(int val, int radix) number_string_length(int val, int radix)
{ {
@ -141,12 +136,6 @@ number_string_length(int val, int radix)
return count; return count;
} }
/**
* Returns the string representing val.
* radix is between 2 and 36 (inclusive).
* This function overwrites buffer and stores the result.
* No error checks are performed in this function. It is caller's responsibility to avoid buffer-overrun.
*/
static void static void
number_string(int val, int radix, int length, char *buffer) { number_string(int val, int radix, int length, char *buffer) {
const char digits[37] = "0123456789abcdefghijklmnopqrstuvwxyz"; const char digits[37] = "0123456789abcdefghijklmnopqrstuvwxyz";
@ -216,7 +205,7 @@ pic_number_string_to_number(pic_state *pic)
int radix = 10; int radix = 10;
long num; long num;
char *eptr; char *eptr;
double flo; pic_value flo;
pic_get_args(pic, "z|i", &str, &radix); pic_get_args(pic, "z|i", &str, &radix);
@ -227,9 +216,9 @@ pic_number_string_to_number(pic_state *pic)
: pic_float_value(num); : pic_float_value(num);
} }
flo = strtod(str, &eptr); flo = pic_read_cstr(pic, str);
if (*eptr == '\0') { if (pic_int_p(flo) || pic_float_p(flo)) {
return pic_float_value(flo); return flo;
} }
pic_errorf(pic, "invalid string given: %s", str); pic_errorf(pic, "invalid string given: %s", str);

View File

@ -282,14 +282,18 @@ read_unsigned(pic_state *pic, struct pic_port *port, int c)
} }
#else #else
case '.': { case '.': {
double f, g; double f, g, h;
next(pic, port); next(pic, port);
g = 0, e = 0; g = 0, e = 0;
while (isdigit(c = peek(pic, port))) { while (isdigit(c = peek(pic, port))) {
g = g * 10 + (next(pic, port) - '0'); g = g * 10 + (next(pic, port) - '0');
e++; e++;
} }
f = u + g * pow(10, -e); h = 1.0;
while (e-- > 0) {
h /= 10;
}
f = u + g * h;
exp = read_suffix(pic, port); exp = read_suffix(pic, port);
if (exp >= 0) { if (exp >= 0) {