Arithmetic/Rational: Difference between revisions

m
(New post without using external libraries, in addition to an existing post which uses the external library "Boost".)
m (→‎{{header|Wren}}: Minor tidy)
 
(4 intermediate revisions by 2 users not shown)
Line 19:
 
 
;Related tasktasks:
*   [[Perfect Numbers]]
*   [[Check Machin-like formulas]]
<br><br>
 
Line 559 ⟶ 560:
}</syntaxhighlight>
 
===Without using external libraries===
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <cmath>
Line 623:
return *this;
}
 
Rational operator*(const Rational& other) const { return Rational(*this) *= other; };
 
Line 667:
 
int64_t hash() const { return std::hash<int64_t>{}(numer) ^ std::hash<int64_t>{}(denom); }
 
private:
int64_t numer;
Line 5,128:
{{libheader|Wren-rat}}
The latter module already contains support for rational number arithmetic.
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./rat" for Rat
 
System.print("The following numbers (less than 2^19) are perfect:")
9,479

edits