comp.lang.ada
 help / color / mirror / Atom feed
* Bernoulli numbers at RosettaCode
@ 2017-02-10 16:51 Alejandro R. Mosteo
  2017-02-11  0:07 ` Paul Rubin
  0 siblings, 1 reply; 2+ messages in thread
From: Alejandro R. Mosteo @ 2017-02-10 16:51 UTC (permalink / raw)


While reading on the first algorithm attributed to our favorite lady, I 
saw that there's no Ada implementation at RosettaCode. Just in case 
someone has some time in their hands to fix this omission.

https://rosettacode.org/wiki/Bernoulli_numbers

Funnily enough, the Pascal impl is taken from an Ada one:

https://marquisdegeek.com/code_ada99

Cheers,
Álex.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Bernoulli numbers at RosettaCode
  2017-02-10 16:51 Bernoulli numbers at RosettaCode Alejandro R. Mosteo
@ 2017-02-11  0:07 ` Paul Rubin
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Rubin @ 2017-02-11  0:07 UTC (permalink / raw)


"Alejandro R. Mosteo" <alejandro@mosteo.com> writes:
> Funnily enough, the Pascal impl is taken from an Ada one:
> https://marquisdegeek.com/code_ada99

The point of the exercise seems to be to do it all with multi-precision
arithmetic, and it doesn't look to me like any of the Pascal solutions
attempted that.  Here's my C++11 solution which simply follows the
algorithm on the Rosetta site:

    #include <boost/multiprecision/gmp.hpp>
    #include <iostream>
    using rational = boost::multiprecision::mpq_rational;

    rational bernoulli(int);

    int main() {
      for (int i = 1; i <= 60; i++) {
        rational b = bernoulli(i);
        if (b != 0)
          std::cout << i << "\t" << b << "\n";
      }
    }

    rational bernoulli(int n) {
      std::vector<rational> a;
      for (int m = 0; m <= n; m++) {
        a.push_back(rational(1,m+1));
        for (int j = m; j >= 1; j--)
          a.at(j-1) = j * (a.at(j-1) - a.at(j));
      }
      return a.at(0);
    }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-02-11  0:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-10 16:51 Bernoulli numbers at RosettaCode Alejandro R. Mosteo
2017-02-11  0:07 ` Paul Rubin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox