* flonum->string now uses a bytevector as the intermediate buffer.

This commit is contained in:
Abdulaziz Ghuloum 2007-05-18 21:52:04 -04:00
parent 179063c117
commit 7ca0ddfa81
4 changed files with 16 additions and 20 deletions

Binary file not shown.

View File

@ -127,33 +127,26 @@ ikrt_fx_atan(ikp x, ikpcb* pcb){
return r;
}
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(ref(x,-vector_tag) == flonum_tag){
char buff[80];
int n = snprintf(buff, sizeof(buff)-2, "%.12G", flonum_data(x));
char* buff = (char*) bv + off_bytevector_data;
int len = unfix(ref(bv, off_bytevector_data));
int n = snprintf(buff, len-2, "%.12G", flonum_data(x));
if(n >= 0){
int i=0;
while ((i<n) && (buff[i] != '.')){ i++; }
if(i == n){
buff[i] = '.';
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)) +
string_tag;
ref(str, -string_tag) = fix(n);
memcpy(string_data(str), buff, n);
return str;
ref(bv, off_bytevector_length) = fix(n);
return bv;
}
}
}

Binary file not shown.

View File

@ -7,11 +7,14 @@
(library (ikarus flonums)
(export string->flonum flonum->string)
(import
(ikarus system $bytevectors)
(except (ikarus) flonum->string string->flonum))
(define (flonum->string x)
(or (foreign-call "ikrt_flonum_to_string" x)
(error 'flonum->string "~s is not a flonum" x)))
(utf8-bytevector->string
(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)
(cond
@ -376,7 +379,7 @@
(cond
[(fixnum? x) (fixnum->string 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)])))
(define modulo