Re: (parse-decimal-fraction <string>) --> <rational> ?
- From: Barry Margolin <barmar@xxxxxxxxxxxx>
- Date: Wed, 02 Apr 2008 20:02:39 -0400
In article <47f3b04d$0$90267$14726298@xxxxxxxxxxxxxxx>,
"Alex Mizrahi" <udodenko@xxxxxxxxxxxxxxxxxxxxx> wrote:
??>> (defun parse-decimal-fraction (str)
??>> (let* ((dotpos (position #\. str))
??>> (left (subseq str 0 dotpos))
??>> (right (subseq str (1+ dotpos))))
??>> (+ (parse-integer left)
??>> (/ (parse-integer right)
??>> (expt 10 (length right))))))
LB> (defun parse-decimal-fraction (str &key (start 0) end (radix 10))
LB> (let ((dotpos (position #\. str :start start :end end)))
LB> (+ (parse-integer str :start start :end dotpos :radix radix)
LB> (/ (parse-integer str :start (1+ dotpos) :end end :radix radix)
LB> (expt 10 (- (or end (length str)) (1+ dotpos)))))))
(expt radix .. ), i guess.
Isn't it an oxymoron to have the word "decimal" in the name, but then
make the radix a parameter? Doesn't "decimal" mean "base 10"?
I guess in this context it's just intended to refer to the use of "." as
the separator between the integer and fraction component. Is there a
generic term for this delimiter? "Radix point"?
--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***
.
- References:
- Re: (parse-decimal-fraction <string>) --> <rational> ?
- From: kodifik
- Re: (parse-decimal-fraction <string>) --> <rational> ?
- From: Alex Mizrahi
- Re: (parse-decimal-fraction <string>) --> <rational> ?
- From: Lars Brinkhoff
- Re: (parse-decimal-fraction <string>) --> <rational> ?
- From: Alex Mizrahi
- Re: (parse-decimal-fraction <string>) --> <rational> ?
- Prev by Date: Re: Newbie FAQ #2: Where's the GUI?
- Next by Date: Re: Newbie FAQ #2: Where's the GUI?
- Previous by thread: Re: (parse-decimal-fraction <string>) --> <rational> ?
- Next by thread: Re: (parse-decimal-fraction <string>) --> <rational> ?
- Index(es):
Relevant Pages
|