Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #52948
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | :Re: Question about a numerical computation |
| Date | 2016-11-29 09:31 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <o1jhtt$kgc$1@gioia.aioe.org> (permalink) |
Paul Foley wrote:
> Forget epsilon; just look to see whether tmp changed at all. When you
> run out of bits, it won't change:
>
> (defun heron-sqrt (x)
> (let ((val 1l0))
> (loop
> (let ((next (* 0.5l0 (+ val (/ x val)))))
> (if (= next val)
> (return val)
> (setq val next))))))
Ruby:
def heron_sqrt x
Enumerator.new{|y| guess = 1
loop{y.yield guess; guess = (x.fdiv(guess) + guess) * 0.5}
}.each_cons(2).find{|a,b| a==b}.first
end
(2..22).each{|n| p [n, heron_sqrt(n)]}
[2, 1.414213562373095]
[3, 1.7320508075688772]
[4, 2.0]
[5, 2.23606797749979]
[6, 2.449489742783178]
[7, 2.6457513110645907]
[8, 2.82842712474619]
[9, 3.0]
[10, 3.162277660168379]
[11, 3.3166247903554]
[12, 3.4641016151377544]
[13, 3.6055512754639896]
[14, 3.7416573867739413]
[15, 3.872983346207417]
[16, 4.0]
[17, 4.123105625617661]
[18, 4.242640687119286]
[19, 4.358898943540673]
[20, 4.47213595499958]
[21, 4.58257569495584]
[22, 4.69041575982343]
In Forth?
--
In Sweden one liberal newspaper editor responded to the latest polling triumphs
by the ... Sweden Democrats party by saying that he would be happy to flood
Sweden with Islamic State fighters to punish the ... electorate.... [M]ost
media in Sweden is Jewish-owned....
theoccidentalobserver.net/2015/11/douglas-murrays-warning-to-the-jewish-community
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
:Re: Question about a numerical computation "Robert L." <No_spamming@noWhere_7073.org> - 2016-11-29 09:31 +0000
csiph-web