Mercurial > projects > decimal
view src/decimal/test.d @ 4:b37c218c1442
Initial development of BCD integers
author | Paul (paul.d.anderson@comcast.net) |
---|---|
date | Thu, 18 Mar 2010 18:10:25 -0700 |
parents | |
children |
line wrap: on
line source
/** * A D programming language implementation of the * General Decimal Arithmetic Specification, * Version 1.70, (25 March 2009). * * by Paul D. Anderson * * Boost Software License - Version 1.0 - August 17th, 2003 * * Permission is hereby granted, free of charge, to any person or organization * obtaining a copy of the software and accompanying documentation covered by * this license (the "Software") to use, reproduce, display, distribute, * execute, and transmit the Software, and to prepare derivative works of the * Software, and to permit third-parties to whom the Software is furnished to * do so, all subject to the following: * * The copyright notices in the Software and this entire statement, including * the above license grant, this restriction and the following disclaimer, * must be included in all copies of the Software, in whole or in part, and * all derivative works of the Software, unless such copies or derivative * works are solely in the form of machine-executable object code generated by * a source language processor. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. **/ module decimal.test; import decimal.decimal; import decimal.math; public void main2() { Decimal ONE = Decimal(1); writeln("1 = ", ONE); Decimal TWO = Decimal(2); writeln("2 = ", TWO); Decimal HALF = Decimal(0.5); writeln("0.5 = ", HALF); Decimal x = sqrt(TWO); writeln("x = ", x); Decimal y = sqrt(x); writeln("y = ", y); Decimal p = TWO + x; writeln("p = ", p); x = y; int i = 0; while (true) { writeln("i = ", i); x = x + ONE/x; writeln("step 0"); // x = HALF (x + ONE/x); x *= HALF; writeln("step 1"); Decimal np = p * ((x + ONE)/(y + ONE)); writeln("step 2"); writeln("np = ", np); if (p == np) return p; writeln("step 3"); p = np; writeln("step 4"); x = sqrt(x); writeln("step 5"); // writeln("x = ", x); Decimal oox = ONE/x; // writeln("ONE/x = ", oox); // writeln ("x + ONE/x = ", x + oox); // Decimal t1 = oox + x; // writeln("t1 = ", t1); // Decimal t1 = x + oox; // ONE + oox; //x + x; // + ONE/x; writeln("step 6"); // Decimal t2 = (y * x) + ONE; ///x; //ONE / (y + ONE); // y = ONE/x + y * x; writeln("step 7"); y = (ONE/x + y * x) / (y + ONE); //t1 / t2; writeln("step 8"); i++; // break; writeln("i = ", i); } return p; } public void main() { writeln("Hello, world!"); /+ writeln("eTiny = ", context.eTiny); writeln("tiny min = ", Decimal(1, context.eTiny)); writeln("tiny min = ", Decimal(1, context.eTiny - 1)); writeln("max = ", context.max()); writeln("max1 = ", Decimal(999999999, 99)); writeln("dig = ", context.dig()); writeln("eps = ", context.epsilon()); writeln("smallest = ", context.min_normal()*context.epsilon()); writeln("1/epsilon = ", Decimal(1)/context.epsilon()); writeln("max * min = ", context.max * context.min_normal); writeln("mant_dig = ", context.mant_dig); writeln("min_exp = ", context.min_exp); writeln("max_exp = ", context.max_exp);+/ // TODO: this next one goes crazy -- shows need for checks on construction // TODO: turns out this is being converted to a double (or real) and // then it's really weird. // writeln("bigger = ", Decimal(999999999999)); // float f = float.max; // TODO: convert these to assserts /+ writeln("f.max = ", f); writeln("f.min = ", float.min); writeln("f = ", 2 * float.min); writeln("d.max = ", Decimal.max()); writeln("d.min = ", Decimal.min_normal()); writeln("2 * d.min = ", 2 * Decimal.min_normal()); writeln("0.1 * d.min = ", 0.1 * Decimal.min_normal());+/ // TODO: move this to unittesting /+ Decimal dec = Decimal(PI); writeln("pi = ", dec ); dec = Decimal(PI, 19); writeln("pi = ", dec ); dec = Decimal(1.3, 25); writeln("pi = ", dec ); dec = Decimal(0.1, 25); writeln("pi = ", dec ); dec = Decimal(2.0, 25); writeln("pi = ", dec ); dec = Decimal(200.5, 25); writeln("pi = ", dec ); writeln(double.dig); writeln(real.dig);+/ }