help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 1.75 -> 1-3/4


From: tomas
Subject: Re: 1.75 -> 1-3/4
Date: Tue, 5 Jun 2018 15:39:10 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, Jun 05, 2018 at 04:18:23PM +0300, Teemu Likonen wrote:
> Emanuel Berg [2018-06-05 15:01:33+02] wrote:
> 
> > Did anyone do the equivalent of this ("ths" zsh below) in Elisp or any
> > other Lisp?
> 
> Common Lisp has RATIONAL and RATIONALIZE functions which convert real
> numbers to rational numbers. See the specification:
> 
>     http://www.lispworks.com/documentation/HyperSpec/Body/f_ration.htm
> 
> "Decimals" library for Common Lisp can parse a decimal number string and
> convert it to a rational number. See function PARSE-DECIMAL-NUMBER:
> 
>     https://github.com/tlikonen/cl-decimals

GNU Guile can do this too:

  scheme@(guile-user)> (inexact->exact 1.3333)
  $7 = 3002324691586541/2251799813685248

(yikes ;-) but...

  scheme@(guile-user)> (rationalize (inexact->exact 1.3333) 1/1000)
  $10 = 4/3

(ah, better). Note that the second argument to rationalize *has* to
be a fraction, otherwise the result will be inexact (i.e. a float).

As to Emacs lisp... natively not. But there seems to be a package [1],
and good ol' calc can deal with rationals too.

Now if we had Guile Emacs (I know, I know).

Cheers

[1] https://www.emacswiki.org/emacs/RationalNumber
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlsWkn4ACgkQBcgs9XrR2kYFcACfd5vldWofHzr3AvmZbeQqE+9r
1E0An0xTK5IRXElTyHWNwWQ4mzsQfRG2
=mbKJ
-----END PGP SIGNATURE-----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]