Skip to content

Instantly share code, notes, and snippets.

View Arlen's full-sized avatar

Arlen Avakian Arlen

  • Austin Texas
View GitHub Profile
#include <iostream>
#include <random>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <array>
#include <chrono>
#include <string>
#include <typeinfo>
@Arlen
Arlen / gist:4947368
Created February 13, 2013 19:29
Comparison between std.rational and http://rosettacode.org/wiki/Arithmetic/Rational#D
// source: http://rosettacode.org/wiki/Arithmetic/Rational#D
import std.bigint, std.traits, std.conv;
T gcd(T)(/*in*/ T a, /*in*/ T b) /*pure nothrow*/ {
// std.numeric.gcd doesn't work with BigInt.
return (b != 0) ? gcd(b, a % b) : (a < 0) ? -a : a;
}
T lcm(T)(/*in*/ T a, /*in*/ T b) {
return a / gcd(a, b) * b;