Logo

Programming-Idioms

History of Idiom 66 > diff from v7 to v8

Edit summary for version 8 by :

Version 7

2015-08-22, 10:12:24

Version 8

2015-08-22, 15:51:20

Idiom #66 Big integer exponentiation

Calculate the result z of x power n, where x is a big integer and n is a positive integer.

Idiom #66 Big integer exponentiation

Calculate the result z of x power n, where x is a big integer and n is a positive integer.

Imports
extern crate num;
Code
let z = num::pow(x, n);
Doc URL
http://doc.rust-lang.org/num/num/fn.pow.html
Demo URL
https://play.rust-lang.org/?code=extern%20crate%20num%3B%0A%0Ause%20num%3A%3Abigint%3A%3ABigInt%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20x%20%3D%20BigInt%3A%3Aparse_bytes(b%22600000000000%22%2C%2010).unwrap()%3B%0A%20%20%20%20let%20n%20%3D%2042%3B%0A%20%20%20%20let%20z%20%3D%20num%3A%3Apow(x%2C%20n)%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20z)%3B%0A%7D%0A&version=stable