* 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; 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;
} }
} }
} }

Binary file not shown.

View File

@ -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