* flonum->string now uses a bytevector as the intermediate buffer.
This commit is contained in:
parent
179063c117
commit
7ca0ddfa81
BIN
bin/ikarus
BIN
bin/ikarus
Binary file not shown.
|
@ -127,33 +127,26 @@ ikrt_fx_atan(ikp x, ikpcb* pcb){
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ikp
|
ikp
|
||||||
ikrt_flonum_to_string(ikp x, ikpcb* pcb){
|
ikrt_flonum_to_bytevector(ikp x, ikp bv, ikpcb* pcb){
|
||||||
if(tagof(x) == vector_tag){
|
if(tagof(x) == vector_tag){
|
||||||
if(ref(x,-vector_tag) == flonum_tag){
|
if(ref(x,-vector_tag) == flonum_tag){
|
||||||
char buff[80];
|
char* buff = (char*) bv + off_bytevector_data;
|
||||||
int n = snprintf(buff, sizeof(buff)-2, "%.12G", flonum_data(x));
|
int len = unfix(ref(bv, off_bytevector_data));
|
||||||
|
int n = snprintf(buff, len-2, "%.12G", flonum_data(x));
|
||||||
if(n >= 0){
|
if(n >= 0){
|
||||||
int i=0;
|
int i=0;
|
||||||
while ((i<n) && (buff[i] != '.')){ i++; }
|
while ((i<n) && (buff[i] != '.')){ i++; }
|
||||||
if(i == n){
|
if(i == n){
|
||||||
buff[i] = '.';
|
buff[i] = '.';
|
||||||
buff[i+1] = '0';
|
buff[i+1] = '0';
|
||||||
n += 2;;
|
buff[i+2] = 0;
|
||||||
|
n += 2;
|
||||||
|
} else {
|
||||||
|
buff[n] = 0;
|
||||||
}
|
}
|
||||||
ikp str = ik_alloc(pcb, align(n+disp_string_data+1)) +
|
ref(bv, off_bytevector_length) = fix(n);
|
||||||
string_tag;
|
return bv;
|
||||||
ref(str, -string_tag) = fix(n);
|
|
||||||
memcpy(string_data(str), buff, n);
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -7,11 +7,14 @@
|
||||||
(library (ikarus flonums)
|
(library (ikarus flonums)
|
||||||
(export string->flonum flonum->string)
|
(export string->flonum flonum->string)
|
||||||
(import
|
(import
|
||||||
|
(ikarus system $bytevectors)
|
||||||
(except (ikarus) flonum->string string->flonum))
|
(except (ikarus) flonum->string string->flonum))
|
||||||
|
|
||||||
(define (flonum->string x)
|
(define (flonum->string x)
|
||||||
(or (foreign-call "ikrt_flonum_to_string" x)
|
(utf8-bytevector->string
|
||||||
(error 'flonum->string "~s is not a flonum" x)))
|
(or (foreign-call "ikrt_flonum_to_bytevector" x
|
||||||
|
(make-bytevector 80 0))
|
||||||
|
(error 'flonum->string "~s is not a flonum" x))))
|
||||||
|
|
||||||
(define (string->flonum x)
|
(define (string->flonum x)
|
||||||
(cond
|
(cond
|
||||||
|
@ -376,7 +379,7 @@
|
||||||
(cond
|
(cond
|
||||||
[(fixnum? x) (fixnum->string x)]
|
[(fixnum? x) (fixnum->string x)]
|
||||||
[(bignum? x) (foreign-call "ikrt_bntostring" x)]
|
[(bignum? x) (foreign-call "ikrt_bntostring" x)]
|
||||||
[(flonum? x) (foreign-call "ikrt_flonum_to_string" x)]
|
[(flonum? x) (flonum->string x)]
|
||||||
[else (error 'number->string "~s is not a number" x)])))
|
[else (error 'number->string "~s is not a number" x)])))
|
||||||
|
|
||||||
(define modulo
|
(define modulo
|
||||||
|
|
Loading…
Reference in New Issue