From d07695e815eac9d2e5efebc69c8f593e06cf916f Mon Sep 17 00:00:00 2001 From: koldo Date: Tue, 25 Feb 2020 07:00:13 +0000 Subject: [PATCH] STEM4U: Added doc git-svn-id: svn://ultimatepp.org/upp/trunk@14078 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/STEM4U/IntInf.h | 30 +++++++++---------- bazaar/STEM4U/STEM4U.upp | 1 + bazaar/STEM4U/src.tpp/Rational_en-us.tpp | 12 ++++++-- bazaar/STEM4U/src.tpp/intInf_en-us.tpp | 4 ++- bazaar/STEM4U/srcdoc.tpp/STEM4U_en-us.tpp | 9 +++--- .../srcimp.tpp/ArbitraryPrecision_en-us.tpp | 23 ++++++++++++++ .../srcimp.tpp/ArbitraryPrecision_en-us.tppi | 5 ++++ bazaar/STEM4U/srcimp.tpp/all.i | 4 +++ 8 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 bazaar/STEM4U/srcimp.tpp/ArbitraryPrecision_en-us.tpp create mode 100644 bazaar/STEM4U/srcimp.tpp/ArbitraryPrecision_en-us.tppi create mode 100644 bazaar/STEM4U/srcimp.tpp/all.i diff --git a/bazaar/STEM4U/IntInf.h b/bazaar/STEM4U/IntInf.h index f1f71a0b8..1a60c43e8 100644 --- a/bazaar/STEM4U/IntInf.h +++ b/bazaar/STEM4U/IntInf.h @@ -73,8 +73,8 @@ public: const intInf& operator+=(const intInf& right); const intInf& operator-=(const intInf& right); const intInf& operator*=(const intInf& right); - const intInf& operator/=(const intInf& right); // throw - const intInf& operator%=(const intInf& right); // throw + const intInf& operator/=(const intInf& right); + const intInf& operator%=(const intInf& right); const intInf& operator*=(ELEM_TYPE right); /* operations */ @@ -82,8 +82,8 @@ public: intInf operator+(const intInf& right) const; intInf operator-(const intInf& right) const; intInf operator*(const intInf& right) const; - intInf operator/(const intInf& right) const; // throw - intInf operator%(const intInf& right) const; // throw + intInf operator/(const intInf& right) const; + intInf operator%(const intInf& right) const; intInf operator*(ELEM_TYPE right) const; template @@ -115,10 +115,10 @@ public: } /* integer square root */ - intInf intSqrt() const; // throw + intInf intSqrt() const; /* digit operations */ - char digitAt(int i) const; // throw + char digitAt(int i) const; int numberOfDigits() const; /* size in bytes */ @@ -128,12 +128,12 @@ public: String ToString() const; /* conversion to primitive types */ - int toInt() const; // throw - long toLong() const; // throw - long long toLongLong() const; // throw - unsigned int toUnsignedInt() const; // throw - unsigned long toUnsignedLong() const; // throw - unsigned long long toUnsignedLongLong() const; // throw + int toInt() const; + long toLong() const; + long long toLongLong() const; + unsigned int toUnsignedInt() const; + unsigned long toUnsignedLong() const; + unsigned long long toUnsignedLongLong() const; operator int() {return toInt();} operator long() {return toLong();} @@ -366,7 +366,7 @@ inline const intInf& intInf::operator*=(const intInf& right) { inline const intInf& intInf::operator/=(const intInf& right) { if (right == 0) - throw std::domain_error("division by zero"); + throw Exc("division by zero"); intInf R, D = (right.pos ? right : -right), N = (pos ? *this : -*this); bool oldpos = pos; @@ -458,7 +458,7 @@ inline intInf intInf::operator*(const intInf& right) const { inline intInf intInf::operator/(const intInf& right) const { if (right == 0) - throw std::domain_error("division by zero"); + throw Exc("division by zero"); intInf Q, R, D = (right.pos ? right : -right), N = (pos ? *this : -*this); Q.val.SetCount(N.val.GetCount(), 0); @@ -476,7 +476,7 @@ inline intInf intInf::operator/(const intInf& right) const { inline intInf intInf::operator%(const intInf& right) const { if (right == 0) - throw std::domain_error("division by zero"); + throw Exc("division by zero"); intInf R, D = (right.pos ? right : -right), N = (pos ? *this : -*this); for (int i = (int) N.val.GetCount() - 1; i >= 0; --i) { diff --git a/bazaar/STEM4U/STEM4U.upp b/bazaar/STEM4U/STEM4U.upp index 4a5a3c286..de6a38a4f 100644 --- a/bazaar/STEM4U/STEM4U.upp +++ b/bazaar/STEM4U/STEM4U.upp @@ -9,6 +9,7 @@ file Rational.h, IntInf.h, Polynomial.h, + srcimp.tpp, src.tpp, srcdoc.tpp, Copying; diff --git a/bazaar/STEM4U/src.tpp/Rational_en-us.tpp b/bazaar/STEM4U/src.tpp/Rational_en-us.tpp index 37026019e..fd64edf30 100644 --- a/bazaar/STEM4U/src.tpp/Rational_en-us.tpp +++ b/bazaar/STEM4U/src.tpp/Rational_en-us.tpp @@ -11,9 +11,15 @@ topic "class Rational : public Moveable "; [s1;:Upp`:`:Rational`:`:class:%- [@(0.0.255) class]_[* Rational]_:_[@(0.0.255) public]_[*@3 Mo veable]<[* Rational]>_&] [s2; &] -[s0; [2 An arbitrary integer precision ][^https`:`/`/en`.wikipedia`.org`/wiki`/Rational`_number^2 r -ational number][2 type based on intInf]&] -[s0;2 &] +[s0; [^topic`:`/`/STEM4U`/srcimp`/ArbitraryPrecision`_en`-us^2 An arbitrary +integer precision][2 ][^https`:`/`/en`.wikipedia`.org`/wiki`/Rational`_number^2 rati +onal number][2 type based on intInf.]&] +[s0; [2 Arbitrary precision means that the type is never out of bounds.]&] +[s0; [2 A rational number means that it is a fraction of a numerator +and denominator.]&] +[s0; [2 The goal of this focus is to allow ][*2 to handle almost infinite +precision lossless floating numbers]&] +[s0; [2 This feature comes with a huge performance penalty.]&] [s3; &] [ {{10000F(128)G(128)@1 [s0; [*2 Constructor Detail]]}}&] [s4;%- &] diff --git a/bazaar/STEM4U/src.tpp/intInf_en-us.tpp b/bazaar/STEM4U/src.tpp/intInf_en-us.tpp index 3d05eda58..31c8e1262 100644 --- a/bazaar/STEM4U/src.tpp/intInf_en-us.tpp +++ b/bazaar/STEM4U/src.tpp/intInf_en-us.tpp @@ -10,8 +10,10 @@ topic "class intInf"; [s1;@(0.0.255)0%- &] [s1;:Upp`:`:intInf`:`:class:%- [@(0.0.255) class]_[* intInf]&] [s2; &] -[s3; [2 An integer type with ][^https`:`/`/en`.wikipedia`.org`/wiki`/Arbitrary`-precision`_arithmetic^2 a +[s3; [2 A signed integer type with ][^https`:`/`/en`.wikipedia`.org`/wiki`/Arbitrary`-precision`_arithmetic^2 a rbitrary`-precision][2 including the usual arithmetic.]&] +[s0; [2 Arbitrary precision means that the type is never out of bounds.]&] +[s0; [2 This feature comes with a huge performance penalty.]&] [s0;2 &] [s3;%- &] [ {{10000F(128)G(128)@1 [s0; [*2 Constructor Detail]]}}&] diff --git a/bazaar/STEM4U/srcdoc.tpp/STEM4U_en-us.tpp b/bazaar/STEM4U/srcdoc.tpp/STEM4U_en-us.tpp index 41a35bb7b..f741c51ab 100644 --- a/bazaar/STEM4U/srcdoc.tpp/STEM4U_en-us.tpp +++ b/bazaar/STEM4U/srcdoc.tpp/STEM4U_en-us.tpp @@ -15,8 +15,9 @@ who want to make a better world through science and technology.]&] :: [s0; [2 A templated polynomial type able to handle coefficients of any type including arbitrary precision rational numbers]] :: [s0;#i150;O0; [^topic`:`/`/STEM4U`/src`/Rational`_en`-us^2 Rational]] -:: [s0; [2 An arbitrary integer precision ][^https`:`/`/en`.wikipedia`.org`/wiki`/Rational`_number^2 r -ational number][2 type based on intInf]] +:: [s0; [^topic`:`/`/STEM4U`/srcimp`/ArbitraryPrecision`_en`-us^2 An arbitrary +integer precision][2 ][^https`:`/`/en`.wikipedia`.org`/wiki`/Rational`_number^2 rati +onal number][2 type based on intInf]] :: [s0;#i150;O0; [^topic`:`/`/STEM4U`/src`/intInf`_en`-us^2 intInf]] :: [s0; [2 An integer type with ][^https`:`/`/en`.wikipedia`.org`/wiki`/Arbitrary`-precision`_arithmetic^2 a rbitrary`-precision][2 including the usual arithmetic.]]}}&] @@ -24,5 +25,5 @@ rbitrary`-precision][2 including the usual arithmetic.]]}}&] [s0; [2 STEM4U`_DemoTest allows to demonstrate some libraries features. When TEST flag is set, it allows to test libraries.]&] [s0;2 &] -[s0; [2 To know about used libraries, you can read ][^topic`:`/`/STEM4U`/srcdoc`/Credits`_en`-us^2 c -redits][2 .]]] \ No newline at end of file +[s0; [2 To know about the libraries internally used, you can read the +][^topic`:`/`/STEM4U`/srcdoc`/Credits`_en`-us^2 credits][2 .]]] \ No newline at end of file diff --git a/bazaar/STEM4U/srcimp.tpp/ArbitraryPrecision_en-us.tpp b/bazaar/STEM4U/srcimp.tpp/ArbitraryPrecision_en-us.tpp new file mode 100644 index 000000000..cfa7e7716 --- /dev/null +++ b/bazaar/STEM4U/srcimp.tpp/ArbitraryPrecision_en-us.tpp @@ -0,0 +1,23 @@ +topic "Rational. An arbitrary precision rational number"; +[ $$0,0#00000000000000000000000000000000:Default] +[{_}%EN-US +[s0; [*R+184 Rational. An arbitrary precision rational number]&] +[s0; We use computers for doing floating point calculations. However +even using 64 bit types, lack of precision in calculations produce +inaccuracies that go accumulating over time, thus increasing +the error.&] +[s0; &] +[s0; For example, lets compute y `= 2/1 `* 3/2 `* 4/3 `* ... If done +n times, result has to be n.&] +[s0; &] +[s0; However, the code implementing this will fail:&] +[s0; &] +[s0; [C+92 double val `= 1;]&] +[s0; [C+92 for (double d `= 1; d < 100; `+`+d) ]&] +[s0; [C+92 -|val `*`= (d`+1)/d;]&] +[s0; [C+92 Cout() << `"double `=`= 100: `" << ((dval `=`= 100) ? `"true`" +: `"false`") << `"`\n`";-|// It returns false!?!?]&] +[s0; &] +[s0; [^topic`:`/`/STEM4U`/src`/Rational`_en`-us^ Rational class] solves +this drawback implementing an arbitrary precision integer rational +number.]] \ No newline at end of file diff --git a/bazaar/STEM4U/srcimp.tpp/ArbitraryPrecision_en-us.tppi b/bazaar/STEM4U/srcimp.tpp/ArbitraryPrecision_en-us.tppi new file mode 100644 index 000000000..60784d31b --- /dev/null +++ b/bazaar/STEM4U/srcimp.tpp/ArbitraryPrecision_en-us.tppi @@ -0,0 +1,5 @@ +TITLE("Rational. An arbitrary precision rational number") +COMPRESSED +120,156,133,83,219,110,211,64,16,253,149,211,82,80,174,118,146,70,8,146,84,17,42,69,244,1,30,90,42,30,130,219,221,172,199,137,197,218,27,237,165,33,162,252,59,99,199,69,36,66,194,15,30,123,206,153,51,151,157,93,224,236,108,208,27,188,24,252,231,153,188,167,76,6,237,147,197,207,135,95,47,175,62,247,239,110,177,112,131,41,22,157,155,238,240,205,24,55,210,231,166,148,58,194,187,18,210,46,115,111,165,221,97,99,73,229,142,17,216,134,128,50,20,75,178,201,171,164,142,255,74,8,142,160,76,177,9,158,172,67,102,44,82,147,151,43,100,218,112,12,127,108,248,215,67,73,173,130,174,85,92,132,143,102,75,143,100,193,175,146,21,42,218,235,49,56,45,252,110,67,174,7,45,213,119,152,236,175,10,242,242,64,131,17,147,6,69,236,151,74,5,43,85,78,14,126,45,61,86,6,149,171,168,169,172,108,170,76,62,47,168,199,120,112,28,161,44,201,58,169,95,19,200,90,99,163,166,161,198,124,224,54,232,135,44,54,154,131,52,121,247,220,34,118,16,23, +24,197,67,136,14,206,227,81,101,198,241,121,101,162,40,194,117,198,221,151,132,178,206,199,125,88,114,60,119,172,37,215,102,176,100,228,40,83,51,137,94,93,138,50,41,55,84,101,45,168,244,251,2,115,135,109,174,53,50,153,235,201,97,236,226,178,251,118,196,9,195,82,19,30,249,112,184,180,225,52,57,64,171,3,105,53,148,116,79,96,59,195,112,192,20,209,21,221,180,141,195,136,254,83,45,213,97,110,43,21,221,97,59,78,143,52,47,77,240,173,54,102,51,136,211,70,90,92,84,210,188,105,236,170,128,86,43,221,23,180,119,183,49,103,192,219,64,12,87,156,76,106,199,223,141,136,248,86,138,211,105,255,41,142,113,237,121,102,62,88,62,225,154,115,50,63,153,39,71,109,223,123,179,201,149,152,136,88,196,183,95,174,62,141,239,68,236,172,18,241,243,26,139,7,42,69,63,184,251,63,139,13,165,165,115,9,156,209,143,245,158,240,88,83,43,183,203,106,207,14,38,46,255,125,1,120,135,105,197,123,116,116,17,162,36,249,13,3,221,33,148, + diff --git a/bazaar/STEM4U/srcimp.tpp/all.i b/bazaar/STEM4U/srcimp.tpp/all.i new file mode 100644 index 000000000..2ca8bba81 --- /dev/null +++ b/bazaar/STEM4U/srcimp.tpp/all.i @@ -0,0 +1,4 @@ +TOPIC("ArbitraryPrecision_en-us") +#include "ArbitraryPrecision_en-us.tppi" +END_TOPIC +