Church numerals: Difference between revisions
m
→{{header|C++}}
(→{{header|C++}}: tweeks; clean-up) |
m (→{{header|C++}}) |
||
Line 373:
int main() {
// show some examples
auto
auto four = Successor(three);
auto six = ToChurch<6>();
Line 384 ⟶ 383:
std::cout << "\n 3^4 = " << ToInt(Exp(three, four));
std::cout << "\n 4^3 = " << ToInt(Exp(four, three));
std::cout << "\n 0^0 = " << ToInt(Exp(
std::cout << "\n 4 - 3 = " << ToInt(Subtract(four, three));
std::cout << "\n 3 - 4 = " << ToInt(Subtract(three, four));
Line 394 ⟶ 393:
// calculate the golden ratio by using a Church numeral to
// apply the funtion 'f(x) = 1 + 1/x' a thousand times
std::cout << "\n golden ratio = " <<
thousand([](double x){ return 1.0 + 1.0 / x; })(1.0) << "\n";
}
{{out}}
<pre>
|