나는 지금까지 이것을 수행 할만한 좋은 라이브러리를 찾지 못했지만 작동하는 것을 함께 해킹했습니다. 입력 작업으로 read-byte
및 read-string
만 사용할 수 있습니다.
;;
;; These are some unfun C routines to convert 4 int-promoted bytes to a float
;; by manually assembling the float using bitwise operators
;;
;; Caveat! These will only work on platforms in which floats are 32-bit Big
;; Endian IEEE754-2008 numbers and doubles are 64-bit Big Endian IEEE754-2008
;; numbers! Also, stdint.h.
;;
(define (readFloat)
(let ([c-read-float
(foreign-lambda* float
((int i1)
(int i2)
(int i3)
(int i4))
"uint8_t b1 = (uint8_t) i1;
uint8_t b2 = (uint8_t) i2;
uint8_t b3 = (uint8_t) i3;
uint8_t b4 = (uint8_t) i4;
uint32_t i = 0;
i = b1;
i = (i << 8) | b2;
i = (i << 8) | b3;
i = (i << 8) | b4;
float f = *(float*)&i;
C_return(f);")])
(let* ([i1 (read-byte)]
[i2 (read-byte)]
[i3 (read-byte)]
[i4 (read-byte)])
(c-read-float i1 i2 i3 i4))))
[bitstring egg] (http://wiki.call-cc.org/eggref/4/bitstring)가 제공되므로 훨씬 간단 해집니다. – sjamaan