Skip to content

Commit 12e6a15

Browse files
committed
fixing isssues with documentation
1 parent 4109b7e commit 12e6a15

1 file changed

Lines changed: 49 additions & 33 deletions

File tree

docs/Math/math.md

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -207,39 +207,55 @@ When using `Overflow::Promote`, types are promoted in the following order:
207207
## Examples
208208
209209
```cpp
210-
#include "pythonic/pythonicMath.hpp"
211-
using namespace pythonic::math;
212-
213-
var a = 10, b = 3;
214-
print(add(a, b)); // 13
215-
print(sub(a, b)); // 7
216-
print(mul(a, b)); // 30
217-
print(div(a, b)); // 3
218-
print(mod(a, b)); // 1
219-
print(pow(a, b)); // 1000
220-
print(sqrt(16)); // 4
221-
print(round(3.1415)); // 3
222-
print(floor(3.7)); // 3
223-
print(ceil(3.1)); // 4
224-
print(trunc(-3.7)); // -3
225-
print(fabs(-5)); // 5
226-
print(hypot(3, 4)); // 5
227-
print(exp(1)); // 2.718...
228-
print(log(e())); // 1
229-
print(log10(100)); // 2
230-
print(log2(8)); // 3
231-
print(sin(pi())); // 0
232-
print(cos(0)); // 1
233-
print(tan(pi()/4)); // 1
234-
print(gcd(12, 18)); // 6
235-
print(lcm(6, 8)); // 24
236-
print(factorial(5)); // 120
237-
print(random_int(1, 6)); // random int 1-6
238-
print(random_float(0, 1)); // random float 0-1
239-
print(random_choice(list(1,2,3)));
240-
print(product(list(1,2,3,4)));// 24
241-
print(radians(180)); // 3.1415...
242-
print(degrees(pi())); // 180
210+
#include <pythonic/pythonic.hpp>
211+
using namespace py;
212+
213+
int main()
214+
{
215+
216+
var a = 10, b = 3, c = std::numeric_limits<int>::max();
217+
print(add(a, b)); // 13
218+
try
219+
{
220+
print(add(a, c)); // overflow
221+
}
222+
catch (const pythonic::error::PythonicOverflowError& e)
223+
{
224+
print("Overflow error: ", e.what());
225+
}
226+
print(a,"+",c,"=",add(a,c,Overflow::Wrap)); // wrap -2147483639
227+
print(a,"+",c,"=",add(a,c,Overflow::Promote)); // promote 2147483657
228+
print(sub(a, b)); // 7
229+
print(mul(a, b)); // 30
230+
print(div(a, b)); // 3
231+
print(mod(a, b)); // 1
232+
print(pow(a, b)); // 1000
233+
print(sqrt(16)); // 4
234+
print(round(3.1415)); // 3
235+
print(floor(3.7)); // 3
236+
print(ceil(3.1)); // 4
237+
print(trunc(-3.7)); // -3
238+
print(fabs(-5)); // 5
239+
print(hypot(3, 4)); // 5
240+
print(exp(1)); // 2.718...
241+
print(log(e())); // 1
242+
print(log10(100)); // 2
243+
print(log2(8)); // 3
244+
print(sin(pi())); // 0
245+
print(cos(0)); // 1
246+
print(tan(pi()/4)); // 1
247+
print(gcd(12, 18)); // 6
248+
print(lcm(6, 8)); // 24
249+
print(factorial(5)); // 120
250+
print(random_int(1, 6)); // random int 1-6
251+
print(random_float(0, 1)); // random float 0-1
252+
print(random_choice(list(1,2,3)));
253+
print(product(list(1,2,3,4)));// 24
254+
print(radians(180)); // 3.1415...
255+
print(degrees(pi())); // 180
256+
return 0;
257+
}
258+
243259
```
244260

245261
---

0 commit comments

Comments
 (0)