Metallic ratios: Difference between revisions

→‎{{header|C++}}: improvements
(→‎{{header|C++}}: improvements)
Line 235:
#include <iostream>
 
std::stringconst char* names[] = { "Platinum", "Golden", "Silver", "Bronze", "Copper", "Nickel", "Aluminium", "Iron", "Tin", "Lead" };
 
template<const uint N>
void lucas(ulong Bb) {
std::cout << "Lucas sequence for " << names[Bb] << " ratio, where b = " << Bb << ":\nFirst " << N << " elements: ";
auto x0 = 1L, x1 = 1L;
std::cout << x0 << ", " << x1;
for (auto i = 1u; i <= N - 1 - 1; i++) {
auto x2 = Bb * x1 + x0;
std::cout << ", " << x2;
x0 = x1;
Line 251:
}
 
template<const uintushort P>
void metallic(ulong b) {
using namespace boost::multiprecision;
using big_floatbfloat = number<cpp_dec_float<P+1>>;
big_floatbfloat x0(1), x1(1);
big_floatauto ratioprev = bfloat(1).str(P+1);
auto prev = ratio.str(P+1);
for (auto i = 0u;;) {
i++;
big_floatbfloat x2(b * x1 + x0);
auto thiz = big_floatbfloat(x2 / x1).str(P+1);
if (prev == thiz) {
std::cout << "Value after " << i << " iteration" << (i == 1 ? ": " : "s: ") << thiz << std::endl << std::endl;
Anonymous user