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

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

Re: Floating Point computations in elisp


From: Christopher Dimech
Subject: Re: Floating Point computations in elisp
Date: Sun, 20 Dec 2020 04:43:25 +0100


> Sent: Sunday, December 20, 2020 at 6:15 AM
> From: "Emanuel Berg via Users list for the GNU Emacs text editor" 
> <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Floating Point computations in elisp
>
> Jean Louis wrote:
>
> > * Emanuel Berg via Users list for the GNU Emacs text editor
> > <help-gnu-emacs@gnu.org> [2020-12-18 20:09]:
> >
> >> (defun compute-space-distance (dist num-beams beam-width)
> >>   (let*((spaces         (1+ num-beams))
> >>         (dist-covered   (* num-beams beam-width))
> >>         (dist-uncovered (- dist dist-covered))
> >>         (space          (/ dist-uncovered spaces 1.0) ))
> >>     space ))
> >>
> >> ;; (insert (format "\n;; %.2f" (compute-space-distance 262 16 12)))
> >> ;; 4.12
> >
> > If I wish to arrive to Tau Ceti from Earth and it is maybe 11.8 light
> > years distant, how many years do I need to get there provided I trave
> > 5,000 km per hour?
>
> How about: 2 548 584 years

The ultimate question is then, how much will it cost.  :)

> (defun tau-ceti (speed)
>   (let*((dist       (* 11.8 9.46 (expt 10 12)))
>         (time       (/ dist speed) )
>         (days       (/ time 24))
>         (whole-days (round days)) )
>     (format-seconds "%y years"
>                     (- (float-time (encode-time 0 0 0 whole-days 0 0))
>                        (float-time (encode-time 0 0 0 0 0 0)) ))))
> ;; (tau-ceti 5000)
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>



reply via email to

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