Add limited pi generator#33
Conversation
3012678 to
7543b02
Compare
|
|
||
| def next_chunk | ||
| @i +=1 | ||
| x = bbp(@i).to_s.chars[0] |
There was a problem hiding this comment.
Using to_s.chars[0] here will only work in Ruby 2.0 or later. Instead, you can do the following, which is also compatible with older stable versions of Ruby:
to_s[0]
|
@telser - there are a couple of implementation issues in this PR. The first, as you note, is that the algorithm fails after just a few hundred digits. After reading more about the BBP formula from the link you provided, it appears that one of the main benefits to that algorithm is that large, custom data types are not required when implemented properly, so the float range should not be an issue. The second issue is that the actual calculation doesn't appear correct - the hex representation of the output doesn't match what I've found for hex representations of pi. Further, the output is decimal-encoded hex, and it should be binary, so there are only 4 bits of variability in every byte of output. These issues would need to be corrected before this PR could be accepted and merged. |
|
@warmer I fixed the float overflow issue, checked the first 10ish digits and another 10ish starting around 1k and 10k digits in (calling the bbp fn with 1000 and 10000). Two further notes:
|
Some notes: