test-031.vala 2.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
using GLib;

class Maman.Foo {
	const float[] FLOAT_TESTS = { 
		float.EPSILON, 0.0, 1.0, 
		-float.INFINITY,
		float.INFINITY,
		float.NAN
	};

	const double[] DOUBLE_TESTS = { 
		double.EPSILON, 0.0, 1.0, 
		-double.INFINITY,
		double.INFINITY,
		double.NAN
	};

	static void main (string[] args) {
		stdout.printf (
			"float: range=%s...%s\n" +
			"       digits=%s(%s), exp=%s..%s(%s..%s)\n" +
			"       epsilon=%s, infinity=%s/%s, nan=%s\n",

		      	float.MIN.to_string (), 
		      	float.MAX.to_string (),

		      	float.MANT_DIG.to_string (),
		      	float.DIG.to_string (),
		      	float.MIN_EXP.to_string (), 
		      	float.MAX_EXP.to_string (),
		      	float.MIN_10_EXP.to_string (), 
		      	float.MAX_10_EXP.to_string (),

		      	float.EPSILON.to_string (),
			float.INFINITY.to_string (),
			(-float.INFINITY).to_string (),
			float.NAN.to_string ());

		for (int i = 0; i < 6; i++) { // XXX use foreach
			float value = FLOAT_TESTS[i];
			int infinity = value.is_infinity ();

			stdout.printf (
				"float(%g): nan=%s, finite=%s, normal=%s, infinity=%s\n", 
				
				value,
				value.is_nan () ? "true" : "false", 
				value.is_finite () ? "true" : "false",
				value.is_normal () ? "true" : "false", 

				infinity > 0 ? "positive" : 
				infinity < 0 ? "negative" : "none");
		}

		stdout.printf (
			"double: range=%s...%s\n" +
			"        digits=%s(%s), exp=%s..%s(%s..%s)\n" +
			"        epsilon=%s, infinity=%s/%s, nan=%s\n",

		      	double.MIN.to_string (), 
		      	double.MAX.to_string (),

		      	double.MANT_DIG.to_string (),
		      	double.DIG.to_string (),
		      	double.MIN_EXP.to_string (), 
		      	double.MAX_EXP.to_string (),
		      	double.MIN_10_EXP.to_string (), 
		      	double.MAX_10_EXP.to_string (),

		      	double.EPSILON.to_string (),
			double.INFINITY.to_string (),
			(-double.INFINITY).to_string (),
			double.NAN.to_string ());

		for (int i = 0; i < 6; i++) { // XXX use foreach
			double value = DOUBLE_TESTS[i];
			int infinity = value.is_infinity ();

			stdout.printf(
				"double(%g): nan=%s, finite=%s, normal=%s, infinity=%s\n", 
				
				value,
				value.is_nan () ? "true" : "false", 
				value.is_finite () ? "true" : "false",
				value.is_normal () ? "true" : "false", 

				infinity > 0 ? "positive" : 
				infinity < 0 ? "negative" : "none");
		}
	}
}