* 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue