From f5fafcaeb117ceee9627b69d46c1b2acf2dfa8e0 Mon Sep 17 00:00:00 2001 From: Robert Ramey Date: Sun, 21 Dec 2014 10:37:12 -0800 Subject: [PATCH] improvement of db2html stye sheet leads to better html presentation ... to be continued --- doc/boostbook/db2html.xsl | 35 ++- doc/boostbook/safe_compare.xml | 15 +- doc/boostbook/safe_introduction.xml | 6 +- doc/boostbook/safe_numerics.xml | 2 +- doc/html/acknowledgements.html | 4 +- doc/html/change_log.html | 4 +- doc/html/concepts.html | 340 +++++++++++++++++++++- doc/html/functions.html | 250 +++++++++++++++- doc/html/images/alert.png | Bin 603 -> 0 bytes doc/html/images/callouts/1.png | Bin 391 -> 0 bytes doc/html/images/callouts/10.png | Bin 485 -> 0 bytes doc/html/images/callouts/11.png | Bin 410 -> 0 bytes doc/html/images/callouts/12.png | Bin 488 -> 0 bytes doc/html/images/callouts/13.png | Bin 509 -> 0 bytes doc/html/images/callouts/14.png | Bin 499 -> 0 bytes doc/html/images/callouts/15.png | Bin 507 -> 0 bytes doc/html/images/callouts/2.png | Bin 446 -> 0 bytes doc/html/images/callouts/3.png | Bin 431 -> 0 bytes doc/html/images/callouts/4.png | Bin 441 -> 0 bytes doc/html/images/callouts/5.png | Bin 423 -> 0 bytes doc/html/images/callouts/6.png | Bin 431 -> 0 bytes doc/html/images/callouts/7.png | Bin 397 -> 0 bytes doc/html/images/callouts/8.png | Bin 434 -> 0 bytes doc/html/images/callouts/9.png | Bin 420 -> 0 bytes doc/html/images/next_disabled.png | Bin doc/html/images/prev_disabled.png | Bin doc/html/images/smiley.png | Bin 867 -> 0 bytes doc/html/images/up_disabled.png | Bin doc/html/index.html | 29 +- doc/html/introduction.html | 63 +++- doc/html/introduction/problem.html | 51 ---- doc/html/introduction/requirements.html | 52 ---- doc/html/introduction/solution.html | 49 ---- doc/html/notes.html | 10 +- doc/html/numeric.html | 363 ----------------------- doc/html/rationale.html | 24 +- doc/html/rationale/overflow.html | 90 ------ doc/html/references.html | 4 +- doc/html/safe.html | 198 ------------- doc/html/safe_cast.html | 120 -------- doc/html/safe_compare.html | 122 -------- doc/html/safe_signed_range.html | 126 -------- doc/html/safe_unsigned_range.html | 128 --------- doc/html/tutorial.html | 194 ++++++++++++- doc/html/tutorial/1.html | 102 ------- doc/html/tutorial/2.html | 81 ------ doc/html/tutorial/3.html | 98 ------- doc/html/types.html | 365 +++++++++++++++++++++++- 48 files changed, 1236 insertions(+), 1689 deletions(-) delete mode 100644 doc/html/images/alert.png delete mode 100644 doc/html/images/callouts/1.png delete mode 100644 doc/html/images/callouts/10.png delete mode 100644 doc/html/images/callouts/11.png delete mode 100644 doc/html/images/callouts/12.png delete mode 100644 doc/html/images/callouts/13.png delete mode 100644 doc/html/images/callouts/14.png delete mode 100644 doc/html/images/callouts/15.png delete mode 100644 doc/html/images/callouts/2.png delete mode 100644 doc/html/images/callouts/3.png delete mode 100644 doc/html/images/callouts/4.png delete mode 100644 doc/html/images/callouts/5.png delete mode 100644 doc/html/images/callouts/6.png delete mode 100644 doc/html/images/callouts/7.png delete mode 100644 doc/html/images/callouts/8.png delete mode 100644 doc/html/images/callouts/9.png mode change 100644 => 100755 doc/html/images/next_disabled.png mode change 100644 => 100755 doc/html/images/prev_disabled.png delete mode 100644 doc/html/images/smiley.png mode change 100644 => 100755 doc/html/images/up_disabled.png delete mode 100644 doc/html/introduction/problem.html delete mode 100644 doc/html/introduction/requirements.html delete mode 100644 doc/html/introduction/solution.html delete mode 100644 doc/html/numeric.html delete mode 100644 doc/html/rationale/overflow.html delete mode 100644 doc/html/safe.html delete mode 100644 doc/html/safe_cast.html delete mode 100644 doc/html/safe_compare.html delete mode 100644 doc/html/safe_signed_range.html delete mode 100644 doc/html/safe_unsigned_range.html delete mode 100644 doc/html/tutorial/1.html delete mode 100644 doc/html/tutorial/2.html delete mode 100644 doc/html/tutorial/3.html diff --git a/doc/boostbook/db2html.xsl b/doc/boostbook/db2html.xsl index c31de26..ef194dd 100644 --- a/doc/boostbook/db2html.xsl +++ b/doc/boostbook/db2html.xsl @@ -8,21 +8,36 @@ - - - - - -horizontal - + + + + + + + +horizontal + + + + + + + + + + + + + + - - - diff --git a/doc/boostbook/safe_compare.xml b/doc/boostbook/safe_compare.xml index 24eea5a..770b62a 100644 --- a/doc/boostbook/safe_compare.xml +++ b/doc/boostbook/safe_compare.xml @@ -88,12 +88,17 @@ bool safe_compare::not_equal(const T & lhs, const U & rhs);#include <boost/numeric/safe_compare.hpp> void f(){ - int i = -1; - unsigned char i = 0x129; + unsigned char i = 129; unsigned int j = 1; - bool result; - result = j < i; // incorrect result - result = safe_compare::less_than(j < i); // correct result + assert(j < i); // program traps because expression is false. But this is a surprise because 1 < 129 + assert( safe_compare::less_than(j,i)); // expression is true as we would expect +} + +// safe_compare is used to implement comparison operators for safe types. So we can do this: +void g(){ + safe<unsigned char> int i = 0x129; + safe<int> j = 1; + assert(j < i); // program works as expected } diff --git a/doc/boostbook/safe_introduction.xml b/doc/boostbook/safe_introduction.xml index 6a1c02a..37e109d 100644 --- a/doc/boostbook/safe_introduction.xml +++ b/doc/boostbook/safe_introduction.xml @@ -4,7 +4,7 @@
Introduction -
+
Problem Arithmetic operations in C++ are NOT guarenteed to yield a correct @@ -21,7 +21,7 @@ this code would introduce another source of errors.
-
+
Solution This library implements special versions of int, unsigned, etc. @@ -37,7 +37,7 @@ outside the closed range [MIN, MAX].
-
+
Requirements This library is is composed entirely of C++ Headers. I requires a diff --git a/doc/boostbook/safe_numerics.xml b/doc/boostbook/safe_numerics.xml index 461c61a..4cefda2 100644 --- a/doc/boostbook/safe_numerics.xml +++ b/doc/boostbook/safe_numerics.xml @@ -19,7 +19,7 @@ - Subject to Boost Software License + http://www.boost.org/LICENSE_1_0.txt">Subject to Boost Software License Safe integer operations diff --git a/doc/html/acknowledgements.html b/doc/html/acknowledgements.html index efa448d..cd25c88 100644 --- a/doc/html/acknowledgements.html +++ b/doc/html/acknowledgements.html @@ -13,7 +13,7 @@ - + @@ -31,7 +31,7 @@
pre-boost HomeLibrariesLibraries People FAQ More
-

diff --git a/doc/html/change_log.html b/doc/html/change_log.html index 6e8a1c5..8ac0cca 100644 --- a/doc/html/change_log.html +++ b/doc/html/change_log.html @@ -13,7 +13,7 @@ - + @@ -29,7 +29,7 @@
pre-boost HomeLibrariesLibraries People FAQ More
-

diff --git a/doc/html/concepts.html b/doc/html/concepts.html index 937c2ff..ca7e99b 100644 --- a/doc/html/concepts.html +++ b/doc/html/concepts.html @@ -7,34 +7,362 @@ - + - +
pre-boost HomeLibrariesLibraries People FAQ More

-PrevUpHomeNext +PrevUpHomeNext

Concepts

- + +
+

+Numeric<T>

+ +
+

+Description

+

A type is Numeric if it has the properties of a number.

+

More specifically, a type T is Numeric if there exists + specialization of std::numeric_limits<T>. See the + documentation for standard library class numeric_limits. The standard + library includes such specializations for all the primitive numeric types. + Note that this concept is distinct from the C++ standard library type + traits is_integral and is_arithmetic. These + latter fullfill the requirement of the concept Numeric. But there are + types T which fullfill this concept for which + is_arithmetic<T>::value == false. For example see + safe_signed_integer<int>.

+
+
+

+Notation

+
+

Table 1. Notation

+
++++ + + + + + + + + + + +
T, U, VA type that is a model of the Numeric
t, u, vAn object of type modeling Numeric
+
+
+
+
+

+Associated Types

+
+

Table 2. Associated Types

+
++++ + + + + +
std::numeric_limits<T>The numeric_limits class template provides a C++ program + with information about various properties of the implementation’s + representation of the arithmetic types. See C++ standard + 18.3.2.2.
+
+
+
+
+

+Valid Expressions

+

In addition to the expressions defined in Assignable the + following expressions must be valid.

+

Any operations which result in integers which cannot be represented + as some Numeric type will throw an exception.

+
+

Table 3. General

+
++++ + + + + + + + + + + + + + + + + + + +
ExpressionReturn Value
std::numeric_limits<T>.is_bounded + true
std::numeric_limits<T>.is_integertrue
std::numeric_limits<T>.is_specialized + true
+
+


+
+

Table 4. Unary Operators

+
+++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ExpressionReturn TypeSemantics
-tTInvert sign
+tTunary plus - a no op
t--Tpost decrement
t++Tpost increment
--tTpredecrement
++tTpreincrement
~Tcomplement
+
+
+

Table 5. Binary Operators

+
+++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ExpressionReturn TypeSemantics
t - uVsubtract u from t
t + uVadd u to t
t * uVmultiply t by u
t / uTdivide t by u
t % uTt modulus u
t << uTshift t left u bits
t >> uTshift t right by ubits
t < ubooltrue if t less than u, false otherwise
t <= ubooltrue if t less than or equal to u, false otherwise
t > ubooltrue if t greater than u, false otherwise
t >= ubooltrue if t greathan or equal to u, false otherwise
t == ubooltrue if t equal to u, false otherwise
t != ubooltrue if t not equal to u, false otherwise
t & uVand of t and u padded out max # bits in t, u
t | uVor of t and u padded out max # bits in t, u
t ^ uVexclusive or of t and u padded out max # bits in t, + u
t = uTassign value of u to t
t += uTadd u to t and assign to t
t -= uTsubtract u from t and assign to t
t *= uTmultiply t by u and assign to t
t /= uTdivide t by u and assign to t
t &= uTand t with u and assign to t
t <<= uTleft shift the value of t by u bits
t >>= uTright shift the value of t by u bits
t &= uTand the value of t with u and assign to t
t |= uTor the value of t with u and assign to t
t ^= uTexclusive or the value of t with u and assign to t
+
+
+
+ +
+

+Models

+

int, safe_signed_integer<int>, + safe_signed_range<int>, etc.

+
+
-

-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/functions.html b/doc/html/functions.html index 46373c1..ad1231f 100644 --- a/doc/html/functions.html +++ b/doc/html/functions.html @@ -6,39 +6,271 @@ - - + + - +
pre-boost HomeLibrariesLibraries People FAQ More

-PrevUpHomeNext +PrevUpHomeNext

Functions

+
+

+safe_cast<T, U>

+ +
+

+Synopsis

+
template<class T, class U>
+T safe_cast(const U & u);
+
+
+

+Description

+

Converts one Numeric + type to another. Throws an std::out_of_range exception if + such a conversion is not possible without changing the value.

+
+
+

+Type requirements

+
++++ + + + + + + + + + + + + + + +
TypeRequirements
TNumeric
U Numeric
+
+
+

+Preconditions

+

The value of u must be representabl by the type T. If + this is not true, an std::out_of_range exception will be + thrown.

+
+
+

+Complexity

+

Constant - O(0).

+
+ +
+

+Example of use

+
#include <boost/numeric/safe_cast.hpp> 
+#include <boost/numeric/safe_integer.hpp> 
+
+void f(){
+    safe_integer<char> i;
+    unsigned char j;
+    i = 1;
+    j = safe_cast<unsigned char>(i);  // ok
+    i = -1;
+    j = safe_cast<unsigned char>(i);  // throws std::out_of_range exception
+    i = 1024;
+    j = safe_cast<unsigned char>(i);  // throws std::out_of_range exception
+}
+
+
+
+

+safe_compare<T, U>

+ +
+

+Synopsis

+

safe_compare is several functions:.

+
template<class T, class U>
+bool safe_compare::less_than(const T & lhs, const U & rhs);
+
+template<class T, class U>
+bool safe_compare::less_than_equal(const T & lhs, const U & rhs);
+
+template<class T, class U>
+bool safe_compare::greater_than(const T & lhs, const U & rhs);
+
+template<class T, class U>
+bool safe_compare::greater_than_equal(const T & lhs, const U & rhs);
+
+template<class T, class U>
+bool safe_compare::equal(const T & lhs, const U & rhs);
+
+template<class T, class U>
+bool safe_compare::not_equal(const T & lhs, const U & rhs);
+
+
+

+Description

+

With normal comparison operators, comparison of unsigned types to + signed types will be done by converting the unsigned type to a signed type + before comparing. Unfortunately this is not always possible. Most C++ + compilers will emit an warning message when this is possible but won't + check that an error is made in the conversion. This function guarentees a + correct result regardless of the types of the arguments.

+
+
+

+Type requirements

+
++++ + + + + + + + + + + + + + + +
TypeRequirements
TNumeric
U Numeric
+
+ +
+

+Example of use

+
#include <boost/numeric/safe_compare.hpp>
+
+void f(){
+    unsigned char i = 129;
+    unsigned int j = 1;
+    assert(j < i); // program traps because expression is false. But this is a surprise because 1 < 129
+    assert( safe_compare::less_than(j,i)); // expression is true as we would expect
+}
+
+// safe_compare is used to implement comparison operators for safe types.  So we can do this:
+void g(){
+    safe<unsigned char> int i = 0x129;
+    safe<int> j = 1;
+    assert(j < i); // program works as expected
+}
+
+
+
+

+overflow

+ +
+

+Synopsis

+

This function is invoked by the library whenever it is not possible + to produce a result for an arithmetic operation.

+
void overflow(char const * const msg);
+
+
+

+Description

+

If evironment supports C++ exceptions, this function throws the + exception .

+

If the environment does not support C++ exceptions, the user should + implement this function and expect it to be called when appropriate. + Otherwise, function is implemented by the library so that it throws the + standard library exception std::out_of_range(msg).

+

boost/config.hpp defines BOOST_NO_EXCEPTIONS + when the environment doesn't support exceptions. It is by checking for the + definition of this macro that the system determines whether or not + exceptions are supported.

+
+ +
+

+Example of use

+
#include <cstdio>
+
+void overflow(char const * const msg){
+    std::fputs("safe_numerics overflow error:, std::stderr);
+    std::fputs(msg, std::stderr);
+    std::fputc('\n', std::stderr);
+}
+
+
+

+See Also

+

See rationale for more + information on this function

+
+
-

-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/images/alert.png b/doc/html/images/alert.png deleted file mode 100644 index b4645bc7e7cd81f2818bf22aa898e95f89f7b154..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 603 zcmeAS@N?(olHy`uVBq!ia0y~yV31^BU=ZVAW?*1oN<7}ez`(#Bl2vQw%VQUVy#($c(b7<_!Z&&*`7 zwYIFTuIA!kP?6(!`t<3^g$y0J3{Q73WQH(YSjJ#(AQj-}VXe>LZ_gkv$q?hiVP&Xj ztS4or%^)MjpsB?1|Nnp9pi5p13=F0vL4Lvi$p8#BTQ7jZgtNdSvY3H^>jMZgI;}C8 z!N9FSxfgB=H7N+NC77H_+N#nawR{=RqTMBX)(LXL|IjinhDSdCyWWZ3S$0kBOZbahGm>{cU3L4X z*xaKNrl+L*2&>`tT{GF}sK6TCoSy58@94C>csZ@3se0z)OD!J`ePg?KNk!eRu!nuZ zwIuy5g5`UyU*2!`JMiPV^UIVvmW1t{f1*^~1#9h_jDIZO*R6JmbN8&QBXd?)zY=(& z`HG+Mis#k2-hNM1nwI_8efYU@yAuCZhY42|Be;Juo!svFUA16}A_D^hgQu&X%Q~lo FCIA+53ZVc1 diff --git a/doc/html/images/callouts/1.png b/doc/html/images/callouts/1.png deleted file mode 100644 index 6003ad3af44ecde89a963d5af6a4180217319dfb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 391 zcmeAS@N?(olHy`uVBq!ia0y~yU=UznVBqFpV_;w?d&FzWz`*F|>EaktF{gKeVcsDJ z0oVU;*6~a;Smx2ZrsEQ?ZxM&ygvBnFE?nmtg94rky>!~x8m)3j$<^(USQPg)>&zq; zMi;kRX=V2=&tIr>`d!)XyUpL@9=UmHetuZ+!_#HmOU>-J$pS3-bN!ardIyAF-G1#? z>&)f7E`k#|4sWoP;JM|(l6I_WZ`%~1y>agujE%b%?TB9+mb}(fsxyPFgQGMy*=%;A z(aZyu>`GQPiY$*T-1gu1pAwY3_N%b5cB#xoiRPn8jf*q{Trb|_a%sui&dtzin6_r? zu}%d~p(mAmOGTO#c2u;xJ(}Y^?ex>t7XL(?7U+1p1hOa|ab;w%c)sCoo@_(^WX<=s zr#89B91nl^w~jx#=XQ?S<*?OXYm`>JmO9g8;`^U+STt2<{M7jt yFTo&UT%Db3I{*CoWB+`guig6oxB?on>HF_suX>mE-_|+p)}_VbyG%XWRxDs!Bbdb`rSkCf z_opQpQ)e&z9?Q3;X^2drllMU70&71c8CwuJm{abIp zeHPuYNTZJ3@x#oHxOW1*hRe1@t$mhYkYRMp!NudU$f{L`HtEbcpPpkT-Q%WwW82?% zC04fVjt$l>J1E5m&cv;Mo-ym249h`b!OT;yI|^kU z7g#)~+Iz@=rzNo?Z+rL2lqSFB&0ni{FPmfwyfr;gD5K)Z38R1FYejhuGSfQP|hTIvQJ?m5M8zE|_KJ2Ny0Fm1o>%kU%6J0MhalaBNL z`|XP~Ht29?&a!*3EqAew_mM&!z3HdD7hn7l!t9~x=u!|XzH8m#&o*bC7c(?GuT1E< zIxY74U)KBI?en(Zj`8vg@_IC9@{~!dRw-$!in=2h%i uo%h^T#Pz@K#3`Fjeg5EaktF{gFX#;)5A z0&V{%irr-ME}D3(<3UjG?A^;f=DTxNc8JvRJ?~omN$9208L_ft0gE{24F|>2&Q_(X zyZRk}S@Y!IJLwtuX$cuSW9kad-E9>}+B4ar@B8JKU&IA}ZdvzvdHazWz|5Z1g ze)`Eh`){a=Ty&?>q6`CxFY1#$=XWS5S;+8pJeF8|am8VmFNNE0pWSjTLp3m4UCF?B z)v7}^cJ1H)wSBfZUSXp*CCGT~*L1 z!O^woK;8cKATG~IcM5iAPD}l8PyF`VZ_(}ou7b0cInG+vv8ev~-ZX{}_a4{SRWsNx zp57$DG;5jTyyy8w3^D7&C6fPqtf+bOwJP3cC`GVy&NA$7e!FZ3*ZX_(gMKMn{jgqg*t>n5-mVwdc+LxmI|e9UlrZu5 zQ({_ROHtjRNV$1z%lk=bT+YJ`-QVnLY|jT_oBf)`qRPnx(gN%Xx|4tEMdaVwoi3 z8lgAcLau*<4)^ratatOor+TqI{wNVS?clathJwW!uZ)j$%&5q+Ew{P&-MZ_q|3(_ifRH$!b{%@XfPPgvO) wR!x~yId8sr_tEzopr0G&e8k^lez diff --git a/doc/html/images/callouts/13.png b/doc/html/images/callouts/13.png deleted file mode 100644 index 5b41e02a670f020ae62b7854482c4ba1980d73cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 509 zcmeAS@N?(olHy`uVBq!ia0y~yU=UznVBqFpV_;w?d&FzWz`%IK)5S5QVovKN`}4B` zMA$w&XL9s;aOlF(1%)YvneO4jm-o(&U;MKD#e?Mq8+>b)^R3G((>5$`ILflv=tsMT zqri^uWh?XJrteF)Ir(#L@uYSZ#}5m2PWL-;h`yh)YSr?%_21hCg6ylJ<~^TZ68k@M z*0PUs0U}2m4Zrz%{ru!$;?!{|$E-JRd$xd+!qOu@YuZ+=+K?-K{IOu7#Gy?(C029K zJuHwgKK8+3O1mEi<8zsP?~|?OE?SqZ;@R}Hh*OcJN#Q`=cIVYsi%fl`jgRf~&@_Gf zwzE(sdH3B%ReKL@(z)}#{LAm!8Ou74CNVNBn8MT`ef;AL!#4E;rLlAT)H7zW#a>U8 zU^AP|o3>d}=J>$`0|rHwDM43C-@g0)`~9hChd_}fnOvtgEzsbyc%HHSwnVR+$0Qaf z4hDzV>nAp?Vf*l#Q@}~VH~7Z3-c_p%=AWOKD!ECAd8tU(q6Mq8jughk>rJ2Tw)o@M zm#pV3mrVI!!@p|Pp+XrSHQ@j+Lm56tj!LO-Hu>!LzuT|B{(4Tap5^mRI^HKOr#o>( zhECmcH*b>$SLC#%J&RUEtqrq3WKa^{tg=+3a-Mjg$X|1pImHv7|6G6l?EhE#0)GDv Vq@B#jVqjok@O1TaS?83{1OO3{4iFg+V~@k_l_W_wBcH zWmp*BaqNHHW9Xsz@VDKv%bG0$2|bO5Z6>~kGkrGPetRKrdu;6W&)@+-S^-5e@qWpx=%~ppu-*HbtcU?B((KtQse2TO*ZEl8Jswt zRO&J4%x73CvPq};vBd=w-op^F6<=oH98=hD0fB5^~^0#Ht9-5wBo~e$L z1lS(@e{k6MP=#(Q)65P&Df1-{87Bltt+Mf&((ZAvc!Ef@>!Js&9H9b5iNOkrjBYL6 zJ*_!sB>iV?h@ACiit<@=<+J)R*K4P%cxw9w^X5-kmdSp5TRo@ZmA&eVHGWMv{dC`S zuce2g9b}I0mp%UT(3$h)E?kO6N0T-NtiR6f#9?6EcU;-Tw>eSb#{2IdZ1@=hR$sjr zzyA8Z#}+%3XYST(VGvBTnww-G;h@R7RHW^&qTY1wDM1E2%vZCnP73-ad;I5-GeP_8 zE`G0F6Q(`qeEN%Bd`m@QuDc4b82Acr%ROx3%dny5{(I}bX7&S{bY%G0Jv1kte!3xU z{l(W`FJx^snCW9M|9s%ekN~~u3#V){n|<~=yTas?3Ovp)cJVPNC~di&>!GEaktF{gFH!7eFB zfwuoy?SYP89?67Uc^u>7$ueKD;_TuU8yCKP?%y^nk6}6Q`Xb ztf|`>GH3mp6jYb?>^RdSfr%@^R!^go|6uIuQi$NDW>upBo%&=x}fma9VINW5Ly|Qkmm3JvHr(Hb1rr&)I%k zqW}1XsO0Up4@Uid#O=~jwU>`!u0>yZkk=jF7J(OKyBQi3I1HqEAMAR!+FC^5{Aa5( zf1b8B8nUgv%H`5>GKER;h_=JWcU60(815ha{H$oF%dBM*eC_{b&TZl;l$m|{>8A+2 z>GpSd7ik$I?GB%onzMHA^lP*F zk0)=tnX|7g@rLFCKI7=6AyTdvVl+z`(%Z>FVdQ I&MBb@0M`i8D*ylh diff --git a/doc/html/images/callouts/3.png b/doc/html/images/callouts/3.png deleted file mode 100644 index 3ff0a93931515bb97a045dfa61a8530d87e458fd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 431 zcmeAS@N?(olHy`uVBq!ia0y~yU=UznVBqFpV_;w?d&FzWz`$7M>EaktF{gFH*{(+p zB5wOOu6l7m)8 z=-oKUH}V^&iJyB|uo8LF()AHB5)-MfO`N3nt zvX}OXM~sd8*9*0GtV!A!kzpdmy4F;zn{|?kqeR<^5G@5I1_ong&q>Sg=9!B)JHv7pU)=hauMINB3;oaL&ye>}mU!H{id4Bxig=9%^>^=*s?64R8I`k2o? pd-p8Ef~{sjr?y8+Fx+F*x_2OD_kw447#J8BJYD@<);T3K0RY@Tw*mkF diff --git a/doc/html/images/callouts/4.png b/doc/html/images/callouts/4.png deleted file mode 100644 index 6aa29fc0b48c17aa6ce5540e1af5c00510c33ff7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 441 zcmeAS@N?(olHy`uVBq!ia0y~yU=UznVBqFpV_;w?d&FzWz`)qx>EaktF{gFH#x5mC zfwup%GG$o)=ergqP)_hu?Cbmc-FuV6=PTSkE z?z;W`K`XyJWKnY38^_LI-}iXo6rn{K^Ugm{NGsVLTQQIQc;ScrMIF~}*~{?xZ|}UC z)%voeOU2Vbu7Bb(%{5!g=daxAHc3V5z+>?E76HlSc>&q{{ zJgU5>EY^K=``x_dYqp*_vnNK+lE-=9auZ+6u0=XLho7HKd(8afJ98Qv1B>H_g?h*I z^7xt(_!*jJt_^x6<$Ce%iJd)$VVYl~OqdVEFZF#=7-s1t%fP_E;OXk;vd$@?2>|9n B#bp2h diff --git a/doc/html/images/callouts/5.png b/doc/html/images/callouts/5.png deleted file mode 100644 index 36e785867ad9b06bb5da296fee61b67cd8159ded..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 423 zcmeAS@N?(olHy`uVBq!ia0y~yU=UznVBqFpV_;w?d&FzWz`&U2>EaktF{gFn*{nkj zBCY4o9LZ47@QCRUnZAf+N!}-g*k62kUh<2$=N}3cU-wJsu7~Tf`D?j51GwEfg_G2_ zuV#t97&qf=>*tSit#h_USr*FJFU!>WaGpbPU+ne2DLtw;&jomW^|@TLId}ILd4;Y; z`kGI<1$&J<4oW?f4p9*ch$x|rP+;KqSwET0Ksa~vKtM(>J91HOJ>EhB>xN^tsw+8di7uv`rMqUeL zJtlGLsS$%o&3$<<&56<(YY$o;PcU%UfB(F1o@3V5sOFBi;${Vo2fOrSjvstkva9-x zil;zZBGUt9^BXy4GknxI4hvj-p!#HTV6S6ePsEk3N^VkheYYwwc>v z!48gj&!5^CXy3`&YF5dr$YOKedHr?gg#ir$OfFx%f9Fdu@F;mr4Z2vhci-*k?73P? f@97_A_`n?SY~RWh)zCHu1_lOCS3j3^P6EaktF{gFH{#8D;%7vjax1W#KXIAnv(J`n z&5VyM+63~m6_r{NIT!+`rAn_gmE-I&+!3QUA?T1q^ClfZ7RG!2%96cqg2wgyaq?lS zMX$X!U8LbO@45W6mvfv$L-`J@Z+FmS&DLGD$|-VMfY)E~efQs=*mUM;<-bcWOZM5Z zTz)B%D3P@Lt`d*4kJ{wr1(Q_jEaktF{gLJ{wyX( zf%f{%yMM5|1Qs>DxO#n#YtRpleGYL4%{eMNMC?4cR!{jhN$+gat*(bhBwQW8eR)?F zba$a+^0L_vzt^7O@l~6=`|-z${Iyee1O}bTzyIC7L&Goql*H!=r=P}oFAaJ)O@ZgI z{@Sm`#{5B@N=kt`V%+OqiyeDxcc)!#?*L7k5+eADVIg?*L>hpfK3x*)1hCVBt; z;|%wV8@Gym{wcFIjN7SWb%BU0N0Y+6yzR|3cK@fSPF7(wKKyx4{o#4fYt#Iv1TDJ# z*2#-AZQqV>`4S8w#?i?>7PHU(+hgr1l-*Nl-OBiY{af+c^=0Sh`7EaktF{kyy#=ct) z0&EZJryZ5xyvdOv(510`p{HDvlxC~E$|>iVgULHQ3PYvrom?h2P4(>+k=FEToVfLb z-1}ul4-dV}J2m&O{aGGazV^u2>+);2+U^P78~6Tv*4AI1E_e2NCZAD1|9M}poAQ6# z2UUCjU5lzOJ!f0qp`v6c!}s@T(aY_*-6p<)(^RJf%{ZH;pv2Hn%$FKjXEE0=dabFI zOUbTczTJ2ED(5xNoT$P%L(+vssY!q-Q6kB1zW$Oa(QCh^Kc6#2_JRrTx8JslG@1mM zBBvdU`kln8=_3m^%&og1Cq^RrH#tzmz{IfafeFfcH9y85}Sb4q9e0BP^KrT_o{ diff --git a/doc/html/images/callouts/9.png b/doc/html/images/callouts/9.png deleted file mode 100644 index abe636072b61306fbcd6157b95dfdf7e86a77e5d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 420 zcmeAS@N?(olHy`uVBq!ia0y~yU=UznVBqFpV_;w?d&FzWz`&U8>EaktF{gEcf7T%f znb!OIl8YM`EC?0g)MK6LySsR*bBW@-#a{$sD|jaA?Rq5|BVw*<(2>_Fw2;L_Ls+eT z*=m-pP5G8*zMrjje*N{AqvqEc&v$lO8~PeQnNu$u7&XUG^XcT&$oGAZue{@YWbseb zX;0Q#doE68rNi6aM(w}9J~guKY8ESl1YdhX&(saqqyj~D?!KF+)#9L-_*{J2Y1Ks< zObjyp?mceG5^anO3Q8tYyaIvx98EzeZXaKe_`Z|7b6wRX+{3FhZAn{V<2dEM9+du_kptYsE+ z{WKfa2W_~S^T2{nZ8E1=H*3uG*3`)V4^%t_SRAV?Wb9U5edYbrW%=bs0jAGCWzMDv z&-uLjLxRB%P3bLBx;@8}pH%jFEoHiFvT*CZ6}7y~440#x2c4?eefQp-XqD5OV!VD< d@-ZKf|NC_Jf+y*vd<+Z>44$rjF6*2UngH>Mv>N~b diff --git a/doc/html/images/next_disabled.png b/doc/html/images/next_disabled.png old mode 100644 new mode 100755 diff --git a/doc/html/images/prev_disabled.png b/doc/html/images/prev_disabled.png old mode 100644 new mode 100755 diff --git a/doc/html/images/smiley.png b/doc/html/images/smiley.png deleted file mode 100644 index 30a77f71ce16872d046a1a5d6fd698a2f65a3f62..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 867 zcmeAS@N?(olHy`uVBq!ia0y~yU=U|uV36QoW?*1YTQtp`fq{X!*vT`5gM;JtL;nX1 z42*&SJ|V8+B7&<|tz5IBw4@*~EXexT*H!m!O?Pp!sH>^CckiyDuKJ|Dl+(w%CQay1 zOYu8%=FGd73zHKgmoF}|u{3I~kKDVXVbQ_`9c`_Fz7{iQrl~4QMTGi1fByW=jcKLD z*?C#s*_rWAAIx@f)c16=+qAB-t1T`u&hzVsWjnTSn>lml<@5cSX&!B@jUfSci{|F_ z_w^KKXB!)+#6)_3`t<4gwQEt~&MzL%J+!ao-_JD<@64PzGws6Z-hv$8-Me=7btN{` zl~t96rKP3$c$&I9TcsogXQl?mL%y{W;-5&-92C)*?h!W?b)Wnj^{5*w_%-mE4Lj!$7BYguC zr{Y6*7#J8-K`Mgt(@M${i&7bU6O)Vbb5m0?6BXPti&D$;i?WLqd?OT$3=B-#%hsG{ zU|`huba4!+n3FrHHoVC|#v<-Y&ynX`2+ z)ci{*-@n^>-frGI_MA-9eHCQCFMs-NiTvCzJ8a&6h<9#D<(d3(^{E}JLTitR9GSK2 z$*O4*8tU!OHS*&Yg~mSMD)7~hd93j+u`cf5MM<4*zJ;yfFKhYEn9bv3Xeg3g;K-G= z;q?Q<5Qk-d*rznCncd{p+umG~t-YZ3L%_f9;YyrSd?k7nE}0j~xg-T!p1r_pXw_8J z^q9XtRP=q)pSk7_!?YePxacL!`8E4~v$oZii_iB4y^t?YSBana!LlH(Q{_whcc+EB z6^^opPM-68`QEg&=hc<^;brIeKBf1+k=uTZ@Aa)4^R8_EExPXM@|~g)-OB%bBP#i` ie0$=QHXfdLO8@!p%oni+1)dBH3=E#GelF{r5}E*N2(Kal diff --git a/doc/html/images/up_disabled.png b/doc/html/images/up_disabled.png old mode 100644 new mode 100755 diff --git a/doc/html/index.html b/doc/html/index.html index 888e63f..4439e39 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -11,7 +11,7 @@ - + @@ -27,41 +27,18 @@
pre-boost HomeLibrariesLibraries People FAQ More
- +

Last revised: ,

Last revised: $Date


diff --git a/doc/html/introduction.html b/doc/html/introduction.html index 51550f2..4057d12 100644 --- a/doc/html/introduction.html +++ b/doc/html/introduction.html @@ -7,38 +7,85 @@ - + - +
pre-boost HomeLibrariesLibraries People FAQ More

-PrevUpHomeNext +PrevUpHomeNext

Introduction

+
+

+Problem

+

Arithmetic operations in C++ are NOT guarenteed to yield a correct + mathematical result. This feature is inherited from the early days of C. + The behavior of int, unsigned int and others + were designed to map closely to the underlying hardware. Computer hardware + implements these types as a fixed number of bits. When the result of + arithmetic operations exceeds this number of bits, the result is undefined + and usually not what the programmer intended. It is incumbent up the C/C++ + programmer to guarentee that this behavior does not result in incorrect + behavior of the program. There are no language facilities which do this. + They have to be explicitly addressed in the program code. This is + exceeding tedious and laborious for a programmer to do. Besides, adding + this code would introduce another source of errors.

+
+
+

+Solution

+

This library implements special versions of int, unsigned, etc. + which behave exactly like the original ones EXCEPT that the results of + these operations are checked to be sure any possible errors resulting from + undefined arithmetic behavior are trapped at compile time (if possible) or + at runtime.

+

In addition to eliminating undefined behavior from primitive integer + types, we define new data types safe_signed_range<MIN, + MAX> and safe_unsigned_range<MIN, MAX> which + will throw an exception if an attempt is made to store a result which is + outside the closed range [MIN, MAX].

+
+
+

+Requirements

+

This library is is composed entirely of C++ Headers. I requires a + compiler compatible with the C++11 standard.

+

The following Boost Libraries must be installed in order to use this + library

+
    +
  • mpl

  • +
  • integer

  • +
  • limits

  • +
  • config

  • +
  • concept checking

  • +
  • type traits

  • +
  • integer traits

  • +
+
-

-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/introduction/problem.html b/doc/html/introduction/problem.html deleted file mode 100644 index 2239422..0000000 --- a/doc/html/introduction/problem.html +++ /dev/null @@ -1,51 +0,0 @@ - - - -Problem - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-Problem

-

Arithmetic operations in C++ are NOT guarenteed to yield a correct - mathematical result. This feature is inherited from the early days of C. - The behavior of int, unsigned int and others - were designed to map closely to the underlying hardware. Computer hardware - implements these types as a fixed number of bits. When the result of - arithmetic operations exceeds this number of bits, the result is undefined - and usually not what the programmer intended. It is incumbent up the C/C++ - programmer to guarentee that this behavior does not result in incorrect - behavior of the program. There are no language facilities which do this. - They have to be explicitly addressed in the program code. This is - exceeding tedious and laborious for a programmer to do. Besides, adding - this code would introduce another source of errors.

-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/introduction/requirements.html b/doc/html/introduction/requirements.html deleted file mode 100644 index 24899ff..0000000 --- a/doc/html/introduction/requirements.html +++ /dev/null @@ -1,52 +0,0 @@ - - - -Requirements - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-Requirements

-

This library is is composed entirely of C++ Headers. I requires a - compiler compatible with the C++11 standard.

-

The following Boost Libraries must be installed in order to use this - library

-
    -
  • mpl

  • -
  • integer

  • -
  • limits

  • -
  • config

  • -
  • concept checking

  • -
  • type traits

  • -
  • integer traits

  • -
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/introduction/solution.html b/doc/html/introduction/solution.html deleted file mode 100644 index 2f577d3..0000000 --- a/doc/html/introduction/solution.html +++ /dev/null @@ -1,49 +0,0 @@ - - - -Solution - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-Solution

-

This library implements special versions of int, unsigned, etc. - which behave exactly like the original ones EXCEPT that the results of - these operations are checked to be sure any possible errors resulting from - undefined arithmetic behavior are trapped at compile time (if possible) or - at runtime.

-

In addition to eliminating undefined behavior from primitive integer - types, we define new data types safe_signed_range<MIN, - MAX> and safe_unsigned_range<MIN, MAX> which - will throw an exception if an attempt is made to store a result which is - outside the closed range [MIN, MAX].

-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/notes.html b/doc/html/notes.html index 846824c..469eb92 100644 --- a/doc/html/notes.html +++ b/doc/html/notes.html @@ -6,21 +6,21 @@ - + - +
pre-boost HomeLibrariesLibraries People FAQ More

-PrevUpHomeNext +PrevUpHomeNext

@@ -55,12 +55,12 @@

-

-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/numeric.html b/doc/html/numeric.html deleted file mode 100644 index 968ba78..0000000 --- a/doc/html/numeric.html +++ /dev/null @@ -1,363 +0,0 @@ - - - -Numeric<T> - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-Numeric<T>

- -
-

-Description

-

A type is Numeric if it has the properties of a number.

-

More specifically, a type T is Numeric if there exists - specialization of std::numeric_limits<T>. See the - documentation for standard library class numeric_limits. The standard - library includes such specializations for all the primitive numeric types. - Note that this concept is distinct from the C++ standard library type - traits is_integral and is_arithmetic. These - latter fullfill the requirement of the concept Numeric. But there are - types T which fullfill this concept for which - is_arithmetic<T>::value == false. For example see - safe_signed_integer<int>.

-
-
-

-Notation

-
-

Table 1. Notation

-
---- - - - - - - - - - - -
T, U, VA type that is a model of the Numeric
t, u, vAn object of type modeling Numeric
-
-
-
-
-

-Associated Types

-
-

Table 2. Associated Types

-
---- - - - - -
std::numeric_limits<T>The numeric_limits class template provides a C++ program - with information about various properties of the implementation’s - representation of the arithmetic types. See C++ standard - 18.3.2.2.
-
-
-
-
-

-Valid Expressions

-

In addition to the expressions defined in Assignable the - following expressions must be valid.

-

Any operations which result in integers which cannot be represented - as some Numeric type will throw an exception.

-
-

Table 3. General

-
---- - - - - - - - - - - - - - - - - - - -
ExpressionReturn Value
std::numeric_limits<T>.is_bounded - true
std::numeric_limits<T>.is_integertrue
std::numeric_limits<T>.is_specialized - true
-
-


-
-

Table 4. Unary Operators

-
----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionReturn TypeSemantics
-tTInvert sign
+tTunary plus - a no op
t--Tpost decrement
t++Tpost increment
--tTpredecrement
++tTpreincrement
~Tcomplement
-
-
-

Table 5. Binary Operators

-
----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionReturn TypeSemantics
t - uVsubtract u from t
t + uVadd u to t
t * uVmultiply t by u
t / uTdivide t by u
t % uTt modulus u
t << uTshift t left u bits
t >> uTshift t right by ubits
t < ubooltrue if t less than u, false otherwise
t <= ubooltrue if t less than or equal to u, false otherwise
t > ubooltrue if t greater than u, false otherwise
t >= ubooltrue if t greathan or equal to u, false otherwise
t == ubooltrue if t equal to u, false otherwise
t != ubooltrue if t not equal to u, false otherwise
t & uVand of t and u padded out max # bits in t, u
t | uVor of t and u padded out max # bits in t, u
t ^ uVexclusive or of t and u padded out max # bits in t, - u
t = uTassign value of u to t
t += uTadd u to t and assign to t
t -= uTsubtract u from t and assign to t
t *= uTmultiply t by u and assign to t
t /= uTdivide t by u and assign to t
t &= uTand t with u and assign to t
t <<= uTleft shift the value of t by u bits
t >>= uTright shift the value of t by u bits
t &= uTand the value of t with u and assign to t
t |= uTor the value of t with u and assign to t
t ^= uTexclusive or the value of t with u and assign to t
-
-
-
- -
-

-Models

-

int, safe_signed_integer<int>, - safe_signed_range<int>, etc.

-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/rationale.html b/doc/html/rationale.html index 2df101d..94a8aef 100644 --- a/doc/html/rationale.html +++ b/doc/html/rationale.html @@ -6,35 +6,35 @@ - + - +
pre-boost HomeLibrariesLibraries People FAQ More

-PrevUpHomeNext +PrevUpHomeNext

Rationale

-
-
1. Why does a binary operation on two +
+
1. Why does a binary operation on two safe<int> values not return another safe type ?
-
2. Why is there no policy driven design for handling +
2. Why is there no policy driven design for handling overflows
-
3. Why is Boost.Convert not used. +
3. Why is Boost.Convert not used.
@@ -43,7 +43,7 @@
-

1.

+

1.

Why does a binary operation on two safe<int> values not return another @@ -64,7 +64,7 @@

-

2.

+

2.

Why is there no policy driven design for handling @@ -78,7 +78,7 @@ unsigned int x = t1 - t2; // which policy should be invoked?

-

3.

+

3.

Why is Boost.Convert not used.

@@ -92,12 +92,12 @@ unsigned int x = t1 - t2; // which policy should be invoked? -

-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/rationale/overflow.html b/doc/html/rationale/overflow.html deleted file mode 100644 index a67e450..0000000 --- a/doc/html/rationale/overflow.html +++ /dev/null @@ -1,90 +0,0 @@ - - - -overflow - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-overflow

- -
-

-Synopsis

-

This function is invoked by the library whenever it is not possible - to produce a result for an arithmetic operation.

-
void overflow(char const * const msg);
-
-
-

-Description

-

If evironment supports C++ exceptions, this function throws the - exception .

-

If the environment does not support C++ exceptions, the user should - implement this function and expect it to be called when appropriate. - Otherwise, function is implemented by the library so that it throws the - standard library exception std::out_of_range(msg).

-

boost/config.hpp defines BOOST_NO_EXCEPTIONS - when the environment doesn't support exceptions. It is by checking for the - definition of this macro that the system determines whether or not - exceptions are supported.

-
- -
-

-Example of use

-
#include <cstdio>
-
-void overflow(char const * const msg){
-    std::fputs("safe_numerics overflow error:, std::stderr);
-    std::fputs(msg, std::stderr);
-    std::fputc('\n', std::stderr);
-}
-
-
-

-See Also

-

See rationale for more - information on this function

-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/references.html b/doc/html/references.html index c68b6b6..8513dd3 100644 --- a/doc/html/references.html +++ b/doc/html/references.html @@ -12,7 +12,7 @@ - + @@ -40,7 +40,7 @@
pre-boost HomeLibrariesLibraries People FAQ More
-

diff --git a/doc/html/safe.html b/doc/html/safe.html deleted file mode 100644 index ebe7655..0000000 --- a/doc/html/safe.html +++ /dev/null @@ -1,198 +0,0 @@ - - - -safe<T> - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-safe<T>

- -
-

-Description

-

A safe<T> can be used anywhere a type T is used. - When T is used in operation which overflows, a exception is thrown

-
-
-

-Notation

-
---- - - - - - - - - - - - - - - - - - - -
SymbolDescription
T, U, VTypes which model the Numeric concept
t, u, vobjects of types T
stobject of type safe<T>
-
-
-

-Template Parameters

-
----- - - - - - - - - - - -
ParameterType RequirementsDescription
Tboost::is_integer<T>::value - == true

The underlying intrinsic integer type

-
-
-

-Model of

-

Numeric

-

If the resulting type of the operation t op u is V, the resulting - type of the operations st op su, t op su and st op u will be - safe<V>;

-
-
-

-Valid Expressions

-
----- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionResultDescription
st op usafe<decltype(t - op u)>

op is any valid binary operator for type - T

t op susafe<decltype(t - op u)>

op is any valid binary operator for type - T

st op susafe<decltype(t - op u)>

op is any valid binary operator for type - T

T * Utypeof(T * - U)

The underlying integer type

-
- -
-

-Example of use

-

The following program will emit an error message on a machine where - int is only 16 bits but run without problem on a machine where int is 32 - bits.

-
#include <boost/numeric/safe.hpp>
-#include <iostream>
-void f(){
-    safe<int> i = 400;
-    safe<int> j;
-    try {
-        j = i * i;
-    }
-    catch(...){
-       std::cout << "overflow error" << std::endl;
-    }
-}
-
-
-
-
-

-Notes

-

Footnotes (if any) that are referred to by other parts of the - page.

-
-
-

-See Also

-

Footnotes (if any) that are referred to by other parts of the - page.

-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/safe_cast.html b/doc/html/safe_cast.html deleted file mode 100644 index aaa874a..0000000 --- a/doc/html/safe_cast.html +++ /dev/null @@ -1,120 +0,0 @@ - - - -safe_cast<T, U> - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-safe_cast<T, U>

- -
-

-Synopsis

-
template<class T, class U>
-T safe_cast(const U & u);
-
-
-

-Description

-

Converts one Numeric type - to another. Throws an std::out_of_range exception if such a - conversion is not possible without changing the value.

-
-
-

-Type requirements

-
---- - - - - - - - - - - - - - - -
TypeRequirements
TNumeric
U Numeric
-
-
-

-Preconditions

-

The value of u must be representabl by the type T. If - this is not true, an std::out_of_range exception will be - thrown.

-
-
-

-Complexity

-

Constant - O(0).

-
- -
-

-Example of use

-
#include <boost/numeric/safe_cast.hpp> 
-#include <boost/numeric/safe_integer.hpp> 
-
-void f(){
-    safe_integer<char> i;
-    unsigned char j;
-    i = 1;
-    j = safe_cast<unsigned char>(i);  // ok
-    i = -1;
-    j = safe_cast<unsigned char>(i);  // throws std::out_of_range exception
-    i = 1024;
-    j = safe_cast<unsigned char>(i);  // throws std::out_of_range exception
-}
-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/safe_compare.html b/doc/html/safe_compare.html deleted file mode 100644 index 348c011..0000000 --- a/doc/html/safe_compare.html +++ /dev/null @@ -1,122 +0,0 @@ - - - -safe_compare<T, U> - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-safe_compare<T, U>

- -
-

-Synopsis

-

safe_compare is several functions:.

-
template<class T, class U>
-bool safe_compare::less_than(const T & lhs, const U & rhs);
-
-template<class T, class U>
-bool safe_compare::less_than_equal(const T & lhs, const U & rhs);
-
-template<class T, class U>
-bool safe_compare::greater_than(const T & lhs, const U & rhs);
-
-template<class T, class U>
-bool safe_compare::greater_than_equal(const T & lhs, const U & rhs);
-
-template<class T, class U>
-bool safe_compare::equal(const T & lhs, const U & rhs);
-
-template<class T, class U>
-bool safe_compare::not_equal(const T & lhs, const U & rhs);
-
-
-

-Description

-

With normal comparison operators, comparison of unsigned types to - signed types will be done by converting the unsigned type to a signed type - before comparing. Unfortunately this is not always possible. Most C++ - compilers will emit an warning message when this is possible but won't - check that an error is made in the conversion. This function guarentees a - correct result regardless of the types of the arguments.

-
-
-

-Type requirements

-
---- - - - - - - - - - - - - - - -
TypeRequirements
TNumeric
U Numeric
-
- -
-

-Example of use

-
#include <boost/numeric/safe_compare.hpp>
-
-void f(){
-    int i = -1;
-    unsigned char i = 0x129;
-    unsigned int j = 1;
-    bool result;
-    result = j < i; // incorrect result
-    result = safe_compare::less_than(j < i); // correct result
-}
-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/safe_signed_range.html b/doc/html/safe_signed_range.html deleted file mode 100644 index 3c9a45d..0000000 --- a/doc/html/safe_signed_range.html +++ /dev/null @@ -1,126 +0,0 @@ - - - -safe_signed_range<boost::intmax_t MIN, boost::intmax_tMAX> - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-safe_signed_range<boost::intmax_t MIN, - boost::intmax_tMAX>

- -
-

-Description

-

This type holds a integer in the range [MIN, MAX]. It will throw a - std::out_of_range exception for operation which would result - in assigning an integer value outside of this range.

-
-
-

-Template Parameters

-
----- - - - - - - - - - - - - - - - - - - - - - - -
ParameterRequirementsDescription
MINmust be an integer literalThe minimum integer value that this type may hold
MAXmust be an integer literalThe maximum integer value that this type may hold
MIN < MAX 
-
-
-

-Model of

-

Numeric

-

The usage of this type in an arithmetic expression will result in - another type fulfilling the Numeric concept.

-

Operations on safe_signed_range will result in the same

-
- -
-

-Example of use

-
#include <safe/numeric/safe_range.hpp>
-
-void f(){
-    boost::numeric::safe_signed_range<7, 24> i;
-    i = 0; // error
-    i = 9; // ok
-    i *= 9; // throws overflow exception
-
-    std::int8_t j = 4;
-    auto k = i + j;
-        // since i can vary between 7 and 24 and j can vary between 0 and 255
-        // the smallest unsigned integer which can hold the result std::int16_t
-        // j will be of type std::int16_t 
-}
-
-
-

-See Also

-

std::out_of_range

-

safe_unsigned_range

-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/safe_unsigned_range.html b/doc/html/safe_unsigned_range.html deleted file mode 100644 index caf3703..0000000 --- a/doc/html/safe_unsigned_range.html +++ /dev/null @@ -1,128 +0,0 @@ - - - -safe_unsigned_range<MIN, MAX> - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-safe_unsigned_range<MIN, MAX>

- -
-

-Description

-

This type holds a integer in the range [MIN, MAX]. It will throw a - std::out_of_range exception for any operation which would - result in assigning an integer value outside of this range.

-
-
-

-Template Parameters

-
----- - - - - - - - - - - - - - - - - - - - - - - -
ParameterRequirementsDescription
MINmust be a positive integer literalThe minimum integer value that this type may hold
MAXmust be a positive integer literalThe maximum integer value that this type may hold
MIN < MAX 
-
-
-

-Model of

-

Numeric

-

The usage of this type in an arithmetic expression with another - unsigned type will result in another unsigned type fulfilling the Numeric concept. This will be the - smallest unsigned integer type of sufficient size to hold the result of - the operation.

-
- -
-

-Example of use

-
#include <safe/numeric/safe_range.hpp>
-
-void f(){
-    boost::numeric::safe_unsigned_range<7, 24> i;
-    i = 0;  // throws out_of_range exception
-    i = 9;  // ok
-    i *= 9; // throws out_of_range exception
-    i = -1; // throws out_of_range exception
-
-    std::uint8_t j = 4;
-    auto k = i + j;
-        // since i can vary between 7 and 24 and j can vary between 0 and 255
-        // the smallest unsigned integer which can hold the result std::uint16_t
-        // j will be of type std::uint16_t 
-    
-}
-
-
-

-See Also

-

std::out_of_range

-

safe_signed_range

-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/tutorial.html b/doc/html/tutorial.html index b53fce3..4b0793a 100644 --- a/doc/html/tutorial.html +++ b/doc/html/tutorial.html @@ -6,40 +6,216 @@ - - + + - +
pre-boost HomeLibrariesLibraries People FAQ More

-PrevUpHomeNext +PrevUpHomeNext

Tutorial

+
+

+Problem: Arithmetic operations can yield in correct + results.

+

When some operation results in a result which exceeds the capacity + of a data variable to hold it, the result is undefined. This is called + "overflow". Since word size can differ between machines, code which + produces correct results in one set of circumstances may fail when + re-compiled on a machine with different hardware. When this occurs, Most + C++ compilers will continue to execute with no indication that the results + are wrong. It is the programmer's responsabiity to ensure such undefined + behavior is avoided.

+

This program demonstrates this problem. The solution is to replace + instances of char type with safe<char> + type.

+
#include <cassert>
+#include <stdexcept>
+#include <iostream>
+
+#include "../include/safe_integer.hpp"
+//#include "../include/safe_compare.hpp"
+
+void detected_msg(bool detected){
+    std::cout << (detected ? "error detected!" : "error NOT detected! ") << std::endl;
+}
+
+int main(int argc, const char * argv[]){
+    std::cout << "example 1:";
+    std::cout << "undetected erroneous expression evaluation" << std::endl;
+    std::cout << "Not using safe numerics" << std::endl;
+    try{
+        char x = 127;
+        char y = 2;
+        char z;
+        // this produces an invalid result !
+        z = x + y;
+        // it is the wrong result !!!
+        assert(z != 129);
+        // but assert fails to detect it since C++ implicitly
+        // converts variables to int before evaluating he expression!
+        assert(z != x + y);
+        std::cout << static_cast<int>(z) << " != " << x + y << std::endl;
+        detected_msg(false);
+    }
+    catch(...){
+        assert(false); // never arrive here
+    }
+    // solution: replace char with safe<char>
+    std::cout << "Using safe numerics" << std::endl;
+    try{
+        using namespace boost::numeric;
+        safe<char> x = 127;
+        safe<char> y = 2;
+        safe<char> z;
+        // rather than producing and invalid result an exception is thrown
+        z = x + y;
+        assert(false); // never arrive here
+    }
+    catch(std::range_error & e){
+        // which can catch here
+        std::cout << e.what() << std::endl;
+        detected_msg(true);
+    }
+    return 0;
+}
+
+
+
+

+Problem: Undetected overflow

+

A variation of the above is when a value is incremented/decremented + beyond it's domain. This is a common problem with for loops.

+
#include <cassert>
+#include <stdexcept>
+#include <iostream>
+
+#include "../include/safe_integer.hpp"
+//#include "../include/safe_compare.hpp"
+
+void detected_msg(bool detected){
+    std::cout << (detected ? "error detected!" : "error NOT detected! ") << std::endl;
+}
+
+int main(int argc, const char * argv[]){
+    std::cout << "example 3: ";
+    std::cout << "implicit conversions change data values" << std::endl;
+    std::cout << "Not using safe numerics" << std::endl;
+    try{
+        int x = -1000;
+        // the following silently produces an incorrect result
+        char y = x;
+        detected_msg(false);
+    }
+    catch(...){
+        assert(false); // never arrive here
+    }
+    // solution: replace int with safe<int> and char with safe<char>
+    std::cout << "Using safe numerics" << std::endl;
+    try{
+        using namespace boost::numeric;
+        safe<int> x = -1000;
+        // throws exception when conversion change data value
+        safe<char> y = x;
+        assert(false); // never arrive here
+    }
+    catch(std::range_error & e){
+        std::cout << e.what() << std::endl;
+        detected_msg(true);
+    }
+    return 0;
+}
+
+
+
+

+Problem: Implicit conversions change data values

+

A simple assign or arithment expression will generally convert all + the terms to the same type. Sometimes this can silently change values. For + example, when a signed data variable contains a negative type, assigning + to a unsigned type will be permitted by any C/C++ compiler but will be + treated as large unsigned value. Most modern compilers will emit a compile + time warning when this conversion is performed. The user may then decide + to change some data types or apply a static_cast. This is + less than satisfactory for two reasons:

+
    +
  • It may be unwield to change all the types to signed or + unsigned.

  • +
  • Litering one's program with static_cast + makes it more difficult to read.

  • +
  • We may believe that our signed type will never contain a + negative value. If we use a static_cast to suppress the + warning, we'll fail to detect a program error when it is commited. + This is aways a risk with casts.

  • +
+

This solution is the same as the above, Just replace instances of + the int with safe<int>.

+
#include <cassert>
+#include <stdexcept>
+#include <iostream>
+
+#include "../include/safe_integer.hpp"
+//#include "../include/safe_compare.hpp"
+
+void detected_msg(bool detected){
+    std::cout << (detected ? "error detected!" : "error NOT detected! ") << std::endl;
+}
+
+int main(int argc, const char * argv[]){
+    std::cout << "example 2:";
+    std::cout << "undetected overflow in data type" << std::endl;
+    try{
+        int x = INT_MAX;
+        // the following silently produces an incorrect result
+        ++x;
+        std::cout << x << " != " << INT_MAX << " + 1" << std::endl;
+        detected_msg(false);
+    }
+    catch(...){
+        assert(false); // never arrive here
+    }
+    // solution: replace int with safe<int>
+    try{
+        using namespace boost::numeric;
+        safe<int> x = INT_MAX;
+        // throws exception when result is past maximum possible 
+        ++x;
+        assert(false); // never arrive here
+    }
+    catch(std::range_error & e){
+        std::cout << e.what();
+        detected_msg(true);
+    }
+    return 0;
+}
+
+
-

-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/tutorial/1.html b/doc/html/tutorial/1.html deleted file mode 100644 index abad8a4..0000000 --- a/doc/html/tutorial/1.html +++ /dev/null @@ -1,102 +0,0 @@ - - - -Problem: Arithmetic operations can yield in correct results. - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-Problem: Arithmetic operations can yield in correct - results.

-

When some operation results in a result which exceeds the capacity - of a data variable to hold it, the result is undefined. This is called - "overflow". Since word size can differ between machines, code which - produces correct results in one set of circumstances may fail when - re-compiled on a machine with different hardware. When this occurs, Most - C++ compilers will continue to execute with no indication that the results - are wrong. It is the programmer's responsabiity to ensure such undefined - behavior is avoided.

-

This program demonstrates this problem. The solution is to replace - instances of char type with safe<char> - type.

-
#include <cassert>
-#include <stdexcept>
-#include <iostream>
-
-#include "../include/safe_integer.hpp"
-//#include "../include/safe_compare.hpp"
-
-void detected_msg(bool detected){
-    std::cout << (detected ? "error detected!" : "error NOT detected! ") << std::endl;
-}
-
-int main(int argc, const char * argv[]){
-    std::cout << "example 1:";
-    std::cout << "undetected erroneous expression evaluation" << std::endl;
-    std::cout << "Not using safe numerics" << std::endl;
-    try{
-        char x = 127;
-        char y = 2;
-        char z;
-        // this produces an invalid result !
-        z = x + y;
-        // it is the wrong result !!!
-        assert(z != 129);
-        // but assert fails to detect it since C++ implicitly
-        // converts variables to int before evaluating he expression!
-        assert(z != x + y);
-        std::cout << static_cast<int>(z) << " != " << x + y << std::endl;
-        detected_msg(false);
-    }
-    catch(...){
-        assert(false); // never arrive here
-    }
-    // solution: replace char with safe<char>
-    std::cout << "Using safe numerics" << std::endl;
-    try{
-        using namespace boost::numeric;
-        safe<char> x = 127;
-        safe<char> y = 2;
-        safe<char> z;
-        // rather than producing and invalid result an exception is thrown
-        z = x + y;
-        assert(false); // never arrive here
-    }
-    catch(std::range_error & e){
-        // which can catch here
-        std::cout << e.what() << std::endl;
-        detected_msg(true);
-    }
-    return 0;
-}
-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/tutorial/2.html b/doc/html/tutorial/2.html deleted file mode 100644 index a6a1e6b..0000000 --- a/doc/html/tutorial/2.html +++ /dev/null @@ -1,81 +0,0 @@ - - - -Problem: Undetected overflow - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-Problem: Undetected overflow

-

A variation of the above is when a value is incremented/decremented - beyond it's domain. This is a common problem with for loops.

-
#include <cassert>
-#include <stdexcept>
-#include <iostream>
-
-#include "../include/safe_integer.hpp"
-//#include "../include/safe_compare.hpp"
-
-void detected_msg(bool detected){
-    std::cout << (detected ? "error detected!" : "error NOT detected! ") << std::endl;
-}
-
-int main(int argc, const char * argv[]){
-    std::cout << "example 3: ";
-    std::cout << "implicit conversions change data values" << std::endl;
-    std::cout << "Not using safe numerics" << std::endl;
-    try{
-        int x = -1000;
-        // the following silently produces an incorrect result
-        char y = x;
-        detected_msg(false);
-    }
-    catch(...){
-        assert(false); // never arrive here
-    }
-    // solution: replace int with safe<int> and char with safe<char>
-    std::cout << "Using safe numerics" << std::endl;
-    try{
-        using namespace boost::numeric;
-        safe<int> x = -1000;
-        // throws exception when conversion change data value
-        safe<char> y = x;
-        assert(false); // never arrive here
-    }
-    catch(std::range_error & e){
-        std::cout << e.what() << std::endl;
-        detected_msg(true);
-    }
-    return 0;
-}
-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/tutorial/3.html b/doc/html/tutorial/3.html deleted file mode 100644 index 66fcba5..0000000 --- a/doc/html/tutorial/3.html +++ /dev/null @@ -1,98 +0,0 @@ - - - -Problem: Implicit conversions change data values - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-Problem: Implicit conversions change data values

-

A simple assign or arithment expression will generally convert all - the terms to the same type. Sometimes this can silently change values. For - example, when a signed data variable contains a negative type, assigning - to a unsigned type will be permitted by any C/C++ compiler but will be - treated as large unsigned value. Most modern compilers will emit a compile - time warning when this conversion is performed. The user may then decide - to change some data types or apply a static_cast. This is - less than satisfactory for two reasons:

-
    -
  • It may be unwield to change all the types to signed or - unsigned.

  • -
  • Litering one's program with static_cast - makes it more difficult to read.

  • -
  • We may believe that our signed type will never contain a - negative value. If we use a static_cast to suppress the - warning, we'll fail to detect a program error when it is commited. - This is aways a risk with casts.

  • -
-

This solution is the same as the above, Just replace instances of - the int with safe<int>.

-
#include <cassert>
-#include <stdexcept>
-#include <iostream>
-
-#include "../include/safe_integer.hpp"
-//#include "../include/safe_compare.hpp"
-
-void detected_msg(bool detected){
-    std::cout << (detected ? "error detected!" : "error NOT detected! ") << std::endl;
-}
-
-int main(int argc, const char * argv[]){
-    std::cout << "example 2:";
-    std::cout << "undetected overflow in data type" << std::endl;
-    try{
-        int x = INT_MAX;
-        // the following silently produces an incorrect result
-        ++x;
-        std::cout << x << " != " << INT_MAX << " + 1" << std::endl;
-        detected_msg(false);
-    }
-    catch(...){
-        assert(false); // never arrive here
-    }
-    // solution: replace int with safe<int>
-    try{
-        using namespace boost::numeric;
-        safe<int> x = INT_MAX;
-        // throws exception when result is past maximum possible 
-        ++x;
-        assert(false); // never arrive here
-    }
-    catch(std::range_error & e){
-        std::cout << e.what();
-        detected_msg(true);
-    }
-    return 0;
-}
-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/types.html b/doc/html/types.html index f9c4a82..a554b7e 100644 --- a/doc/html/types.html +++ b/doc/html/types.html @@ -6,40 +6,387 @@ - - + + - +
pre-boost HomeLibrariesLibraries People FAQ More

-PrevUpHomeNext +PrevUpHomeNext

Types

+
+

+safe_unsigned_range<MIN, MAX>

+ +
+

+Description

+

This type holds a integer in the range [MIN, MAX]. It will throw a + std::out_of_range exception for any operation which would + result in assigning an integer value outside of this range.

+
+
+

+Template Parameters

+
+++++ + + + + + + + + + + + + + + + + + + + + + + +
ParameterRequirementsDescription
MINmust be a positive integer literalThe minimum integer value that this type may hold
MAXmust be a positive integer literalThe maximum integer value that this type may hold
MIN < MAX 
+
+
+

+Model of

+

Numeric

+

The usage of this type in an arithmetic expression with another + unsigned type will result in another unsigned type fulfilling the Numeric concept. This will be the + smallest unsigned integer type of sufficient size to hold the result of + the operation.

+
+ +
+

+Example of use

+
#include <safe/numeric/safe_range.hpp>
+
+void f(){
+    boost::numeric::safe_unsigned_range<7, 24> i;
+    i = 0;  // throws out_of_range exception
+    i = 9;  // ok
+    i *= 9; // throws out_of_range exception
+    i = -1; // throws out_of_range exception
+
+    std::uint8_t j = 4;
+    auto k = i + j;
+        // since i can vary between 7 and 24 and j can vary between 0 and 255
+        // the smallest unsigned integer which can hold the result std::uint16_t
+        // j will be of type std::uint16_t 
+    
+}
+
+
+

+See Also

+

std::out_of_range

+

safe_signed_range

+
+
+
+

+safe_signed_range<boost::intmax_t MIN, + boost::intmax_tMAX>

+ +
+

+Description

+

This type holds a integer in the range [MIN, MAX]. It will throw a + std::out_of_range exception for operation which would result + in assigning an integer value outside of this range.

+
+
+

+Template Parameters

+
+++++ + + + + + + + + + + + + + + + + + + + + + + +
ParameterRequirementsDescription
MINmust be an integer literalThe minimum integer value that this type may hold
MAXmust be an integer literalThe maximum integer value that this type may hold
MIN < MAX 
+
+
+

+Model of

+

Numeric

+

The usage of this type in an arithmetic expression will result in + another type fulfilling the Numeric concept.

+

Operations on safe_signed_range will result in the same

+
+ +
+

+Example of use

+
#include <safe/numeric/safe_range.hpp>
+
+void f(){
+    boost::numeric::safe_signed_range<7, 24> i;
+    i = 0; // error
+    i = 9; // ok
+    i *= 9; // throws overflow exception
+
+    std::int8_t j = 4;
+    auto k = i + j;
+        // since i can vary between 7 and 24 and j can vary between 0 and 255
+        // the smallest unsigned integer which can hold the result std::int16_t
+        // j will be of type std::int16_t 
+}
+
+
+

+See Also

+

std::out_of_range

+

safe_unsigned_range

+
+
+
+

+safe<T>

+ +
+

+Description

+

A safe<T> can be used anywhere a type T is used. + When T is used in operation which overflows, a exception is thrown

+
+
+

+Notation

+
++++ + + + + + + + + + + + + + + + + + + +
SymbolDescription
T, U, VTypes which model the Numeric concept
t, u, vobjects of types T
stobject of type safe<T>
+
+
+

+Template Parameters

+
+++++ + + + + + + + + + + +
ParameterType RequirementsDescription
Tboost::is_integer<T>::value + == true

The underlying intrinsic integer type

+
+
+

+Model of

+

Numeric

+

If the resulting type of the operation t op u is V, the resulting + type of the operations st op su, t op su and st op u will be + safe<V>;

+
+
+

+Valid Expressions

+
+++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ExpressionResultDescription
st op usafe<decltype(t + op u)>

op is any valid binary operator for type + T

t op susafe<decltype(t + op u)>

op is any valid binary operator for type + T

st op susafe<decltype(t + op u)>

op is any valid binary operator for type + T

T * Utypeof(T * + U)

The underlying integer type

+
+ +
+

+Example of use

+

The following program will emit an error message on a machine where + int is only 16 bits but run without problem on a machine where int is 32 + bits.

+
#include <boost/numeric/safe.hpp>
+#include <iostream>
+void f(){
+    safe<int> i = 400;
+    safe<int> j;
+    try {
+        j = i * i;
+    }
+    catch(...){
+       std::cout << "overflow error" << std::endl;
+    }
+}
+
+
+
+
+

+Notes

+

Footnotes (if any) that are referred to by other parts of the + page.

+
+
+

+See Also

+

Footnotes (if any) that are referred to by other parts of the + page.

+
+
-

-PrevUpHomeNext +PrevUpHomeNext