Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
Exact (LISP-ish) calculations in Ruby?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Florian Frank, post: 4653073"] I had to implement them for my bullshit library (which has grown to include half a math library by now, ugh): [URL]http://github.com/flori/bullshit/blob/master/lib/bullshit.rb#L20[/URL] require 'bullshit' # pardon my french include Bullshit # => 1.4142135623731 They are rather fascinating. They can be used to implement functions as well, here's the atan function: atan = ContinuedFraction.for_a do |n, x| n == 0 ? 0 : 2 * n - 1 end.for_b do |n, x| n <= 1 ? x : ((n - 1) * x) ** 2 end # => 0.785398163397448 Now, it's easy to approximate pi as well: pi = lambda { 4 * atan[1] } # => 3.14159265358979 As you can imagine I had a lot of fun playing with them. ;) [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Exact (LISP-ish) calculations in Ruby?
Top