Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define get-sign
- (lambda(b)
- (if(char=? (string-ref b 0) #\-) -1 1)
- )
- )
- (define find-point
- (lambda(s)
- (let((n (- (string-length s) 1)))
- (if(char=? (string-ref s n) #\.) n
- (if (= n 0)
- -1
- (find-point(substring s 0 n))
- )
- )
- )
- )
- )
- (define rep->whole
- (lambda(s1 s2 b)
- (let((k (- (string-length s2) 1)))
- (let((pre (substring s2 0 k)) (lsb (string-ref s2 k)))
- (if (= k 0)
- (rep->get-v s1 lsb)
- (+ (* b (rep->whole s1 pre b)) (rep->get-v s1 lsb))
- )
- )
- )
- )
- )
- (define rep->frac
- (lambda (s1 s2 b)
- (let((k (- (string-length s2) 1)))
- (let((pre (substring s2 0 k)) (lsb (string-ref s2 k)))
- (if (= k 0)
- (*(rep->get-v s1 lsb) (expt b (* -1 (+ k 1))))
- (+ (* (rep->get-v s1 lsb) (expt b (* -1 (+ k 1)))) (rep->frac s1 pre b))
- )
- )
- )
- )
- )
- (define rep->get-v
- (lambda(s c)
- (let((k (- (string-length s) 1)))
- (if(= k -1)
- 0
- (if(char=? (string-ref s k) c)
- k
- (rep->get-v (substring s 0 k) c)
- )
- )
- )
- )
- )
- (define rep->number
- (lambda (s1 s2)
- (let((base (string-length s1)))
- (let((p (find-point s2)))
- (if(= p -1)
- (* (get-sign s2) (rep->whole s1 s2 base))
- (* (get-sign s2) (+ (rep->whole s1 (substring s2 0 p) base) (rep->frac s1 (substring s2 (+ p 1 )) base)))
- )
- )
- )
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement