Merge lp:~zorba-coders/zorba/bug-966355 into lp:zorba
- bug-966355
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Markos Zaharioudakis |
Approved revision: | 10745 |
Merged at revision: | 10767 |
Proposed branch: | lp:~zorba-coders/zorba/bug-966355 |
Merge into: | lp:zorba |
Diff against target: |
3429 lines (+1151/-1018) 27 files modified
src/annotations/annotations.h (+1/-1) src/compiler/rewriter/rules/flwor_rules.cpp (+1/-1) src/compiler/rewriter/rules/fold_rules.cpp (+3/-3) src/compiler/translator/translator.cpp (+2/-2) src/runtime/collections/collections_impl.cpp (+6/-7) src/runtime/core/gflwor/window_iterator.cpp (+21/-15) src/runtime/core/trycatch.cpp (+13/-7) src/runtime/maths/maths_impl.cpp (+1/-1) src/runtime/numerics/format_integer_impl.cpp (+9/-9) src/runtime/random/random_impl.cpp (+2/-2) src/runtime/sequences/sequences_impl.cpp (+3/-3) src/runtime/store/maps_impl.cpp (+1/-1) src/store/naive/atomic_items.cpp (+2/-2) src/store/naive/collection.h (+1/-1) src/store/naive/node_items.cpp (+1/-1) src/store/naive/pul_primitives.cpp (+17/-13) src/store/naive/simple_collection.cpp (+11/-11) src/store/naive/simple_collection.h (+2/-2) src/store/naive/simple_index_general.cpp (+9/-9) src/store/naive/simple_lazy_temp_seq.cpp (+4/-4) src/store/naive/simple_temp_seq.cpp (+1/-1) src/zorbatypes/decimal.cpp (+7/-7) src/zorbatypes/decimal.h (+108/-154) src/zorbatypes/floatimpl.cpp (+54/-12) src/zorbatypes/floatimpl.h (+468/-460) src/zorbatypes/integer.cpp (+2/-2) src/zorbatypes/integer.h (+401/-287) |
To merge this branch: | bzr merge lp:~zorba-coders/zorba/bug-966355 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Markos Zaharioudakis | Approve | ||
Matthias Brantner | Approve | ||
Paul J. Lucas | Approve | ||
Review via email: mp+102128@code.launchpad.net |
Commit message
Added operators for built-in types (when ZORBA_WITH_
Description of the change
Added operators for built-in types (when ZORBA_WITH_
It turns out that the problem is harder to solve than I thought. The problem with injecting operators like:
bool operator==( IntegerImpl const&, int );
bool operator==( int, IntegerImpl const& );
// ...
into the global namespace is that a lot of ambiguity arises. According to the C++11 rules, it becomes ambiguous the compiler doesn't know whether it should convert the int to an IntegerImpl via constructor or not. (To me, it seems silly and the "obviously correct" answer *should* be not to do the conversion, but there's probably a good reason for the C++11 behavior that just not obvious to me at the moment.)
One way to fix this is to make all the constructors for IntegerImpl( T ), where T is any arithmetic type, explicit, e.g.:
explicit IntegerImpl( int = 0 );
explicit IntegerImpl( long );
// ...
However, that broke some existing code (which I've since fixed on the branch) that relied upon the implicit conversion. Despite the breakage, I think making the constructors explicit is a Good Thing because it highlights places in the code where you're actually constructing an expensive-
For example, the Collection class has member functions that take "integers" like addNode(), nodeAt(), removeNodes(), etc., as xs_integer rather than something like int. In some cases, the arguments were cast to uint64_t despite the reality that the arguments were implicitly being converted to xs_integer. It's not clear why the uint64_t cast was there.
I've changed the owner of the branch to zorba-coders so you can make any necessary changes. In particular, look at the changes in files that are NOT in the zorbatypes sub-directory.
Paul J. Lucas (paul-lucas) : | # |
Matthias Brantner (matthias-brantner) : | # |
Markos Zaharioudakis (markos-za) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job bug-966355-2012-04-
All tests succeeded!
Preview Diff
1 | === modified file 'src/annotations/annotations.h' | |||
2 | --- src/annotations/annotations.h 2012-03-30 19:03:09 +0000 | |||
3 | +++ src/annotations/annotations.h 2012-04-16 15:38:09 +0000 | |||
4 | @@ -83,7 +83,7 @@ | |||
5 | 83 | }; | 83 | }; |
6 | 84 | 84 | ||
7 | 85 | protected: | 85 | protected: |
9 | 86 | typedef std::bitset<zann_end + 1> RuleBitSet; | 86 | typedef std::bitset<static_cast<int>(zann_end) + 1> RuleBitSet; |
10 | 87 | 87 | ||
11 | 88 | protected: | 88 | protected: |
12 | 89 | static std::vector<store::Item_t> theAnnotId2NameMap; | 89 | static std::vector<store::Item_t> theAnnotId2NameMap; |
13 | 90 | 90 | ||
14 | === modified file 'src/compiler/rewriter/rules/flwor_rules.cpp' | |||
15 | --- src/compiler/rewriter/rules/flwor_rules.cpp 2012-04-05 18:06:01 +0000 | |||
16 | +++ src/compiler/rewriter/rules/flwor_rules.cpp 2012-04-16 15:38:09 +0000 | |||
17 | @@ -1037,7 +1037,7 @@ | |||
18 | 1037 | err::XPTY0004); | 1037 | err::XPTY0004); |
19 | 1038 | 1038 | ||
20 | 1039 | if (TypeOps::is_subtype(tm, *valType, *rtm.INTEGER_TYPE_ONE, posLoc) && | 1039 | if (TypeOps::is_subtype(tm, *valType, *rtm.INTEGER_TYPE_ONE, posLoc) && |
22 | 1040 | val->getIntegerValue() >= xs_integer::one()) | 1040 | val->getIntegerValue() >= 1) |
23 | 1041 | { | 1041 | { |
24 | 1042 | return true; | 1042 | return true; |
25 | 1043 | } | 1043 | } |
26 | 1044 | 1044 | ||
27 | === modified file 'src/compiler/rewriter/rules/fold_rules.cpp' | |||
28 | --- src/compiler/rewriter/rules/fold_rules.cpp 2012-03-30 19:03:09 +0000 | |||
29 | +++ src/compiler/rewriter/rules/fold_rules.cpp 2012-04-16 15:38:09 +0000 | |||
30 | @@ -928,19 +928,19 @@ | |||
31 | 928 | { | 928 | { |
32 | 929 | xs_integer ival = val->getIntegerValue(); | 929 | xs_integer ival = val->getIntegerValue(); |
33 | 930 | 930 | ||
35 | 931 | if (ival < xs_integer::zero()) | 931 | if (ival < 0) |
36 | 932 | { | 932 | { |
37 | 933 | if (!count_expr->isNonDiscardable()) | 933 | if (!count_expr->isNonDiscardable()) |
38 | 934 | return new const_expr(val_expr->get_sctx(), LOC(val_expr), false); | 934 | return new const_expr(val_expr->get_sctx(), LOC(val_expr), false); |
39 | 935 | } | 935 | } |
41 | 936 | else if (ival == xs_integer::zero()) | 936 | else if (ival == 0) |
42 | 937 | { | 937 | { |
43 | 938 | return expr_tools::fix_annotations( | 938 | return expr_tools::fix_annotations( |
44 | 939 | new fo_expr(fo.get_sctx(), fo.get_loc(), | 939 | new fo_expr(fo.get_sctx(), fo.get_loc(), |
45 | 940 | GET_BUILTIN_FUNCTION(FN_EMPTY_1), | 940 | GET_BUILTIN_FUNCTION(FN_EMPTY_1), |
46 | 941 | count_expr->get_arg(0))); | 941 | count_expr->get_arg(0))); |
47 | 942 | } | 942 | } |
49 | 943 | else if (ival == xs_integer::one()) | 943 | else if (ival == 1) |
50 | 944 | { | 944 | { |
51 | 945 | return expr_tools::fix_annotations( | 945 | return expr_tools::fix_annotations( |
52 | 946 | new fo_expr(fo.get_sctx(), | 946 | new fo_expr(fo.get_sctx(), |
53 | 947 | 947 | ||
54 | === modified file 'src/compiler/translator/translator.cpp' | |||
55 | --- src/compiler/translator/translator.cpp 2012-04-12 02:08:10 +0000 | |||
56 | +++ src/compiler/translator/translator.cpp 2012-04-16 15:38:09 +0000 | |||
57 | @@ -9754,8 +9754,8 @@ | |||
58 | 9754 | { | 9754 | { |
59 | 9755 | case FunctionConsts::FN_HEAD_1: | 9755 | case FunctionConsts::FN_HEAD_1: |
60 | 9756 | { | 9756 | { |
63 | 9757 | arguments.push_back(new const_expr(theRootSctx, loc, xs_integer(1))); | 9757 | arguments.push_back(new const_expr(theRootSctx, loc, xs_integer::one())); |
64 | 9758 | arguments.push_back(new const_expr(theRootSctx, loc, xs_integer(1))); | 9758 | arguments.push_back(new const_expr(theRootSctx, loc, xs_integer::one())); |
65 | 9759 | function* f = GET_BUILTIN_FUNCTION(OP_ZORBA_SUBSEQUENCE_INT_3); | 9759 | function* f = GET_BUILTIN_FUNCTION(OP_ZORBA_SUBSEQUENCE_INT_3); |
66 | 9760 | fo_expr_t foExpr = new fo_expr(theRootSctx, loc, f, arguments); | 9760 | fo_expr_t foExpr = new fo_expr(theRootSctx, loc, f, arguments); |
67 | 9761 | normalize_fo(foExpr); | 9761 | normalize_fo(foExpr); |
68 | 9762 | 9762 | ||
69 | === modified file 'src/runtime/collections/collections_impl.cpp' | |||
70 | --- src/runtime/collections/collections_impl.cpp 2012-04-14 06:12:29 +0000 | |||
71 | +++ src/runtime/collections/collections_impl.cpp 2012-04-16 15:38:09 +0000 | |||
72 | @@ -451,7 +451,7 @@ | |||
73 | 451 | { | 451 | { |
74 | 452 | store::Collection_t collection; | 452 | store::Collection_t collection; |
75 | 453 | store::Item_t node; | 453 | store::Item_t node; |
77 | 454 | xs_integer pos = 1; | 454 | xs_integer pos( 1 ); |
78 | 455 | bool found; | 455 | bool found; |
79 | 456 | 456 | ||
80 | 457 | PlanIteratorState* state; | 457 | PlanIteratorState* state; |
81 | @@ -466,8 +466,7 @@ | |||
82 | 466 | 466 | ||
83 | 467 | found = collection->findNode(node, pos); | 467 | found = collection->findNode(node, pos); |
84 | 468 | ZORBA_ASSERT(found); | 468 | ZORBA_ASSERT(found); |
87 | 469 | STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, pos+xs_integer(1)), | 469 | STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, pos+1), state); |
86 | 470 | state); | ||
88 | 471 | } | 470 | } |
89 | 472 | 471 | ||
90 | 473 | STACK_END (state); | 472 | STACK_END (state); |
91 | @@ -1638,7 +1637,7 @@ | |||
92 | 1638 | const StaticallyKnownCollection* collectionDecl; | 1637 | const StaticallyKnownCollection* collectionDecl; |
93 | 1639 | store::Item_t collectionName; | 1638 | store::Item_t collectionName; |
94 | 1640 | store::Item_t numNodesItem; | 1639 | store::Item_t numNodesItem; |
96 | 1641 | xs_integer numNodes = 1; | 1640 | xs_integer numNodes( 1 ); |
97 | 1642 | std::vector<store::Item_t> nodes; | 1641 | std::vector<store::Item_t> nodes; |
98 | 1643 | std::auto_ptr<store::PUL> pul; | 1642 | std::auto_ptr<store::PUL> pul; |
99 | 1644 | 1643 | ||
100 | @@ -1674,7 +1673,7 @@ | |||
101 | 1674 | // create the pul and add the primitive | 1673 | // create the pul and add the primitive |
102 | 1675 | pul.reset(GENV_ITEMFACTORY->createPendingUpdateList()); | 1674 | pul.reset(GENV_ITEMFACTORY->createPendingUpdateList()); |
103 | 1676 | 1675 | ||
105 | 1677 | for (xs_integer i = 0; i < numNodes; ++i) | 1676 | for (xs_integer i( 0 ); i < numNodes; ++i) |
106 | 1678 | nodes.push_back(collection->nodeAt(i)); | 1677 | nodes.push_back(collection->nodeAt(i)); |
107 | 1679 | 1678 | ||
108 | 1680 | pul->addDeleteFromCollection(&loc, collectionName, nodes, false, theDynamicCollection); | 1679 | pul->addDeleteFromCollection(&loc, collectionName, nodes, false, theDynamicCollection); |
109 | @@ -1762,7 +1761,7 @@ | |||
110 | 1762 | const StaticallyKnownCollection* collectionDecl; | 1761 | const StaticallyKnownCollection* collectionDecl; |
111 | 1763 | store::Item_t collectionName; | 1762 | store::Item_t collectionName; |
112 | 1764 | store::Item_t numNodesItem; | 1763 | store::Item_t numNodesItem; |
114 | 1765 | xs_integer numNodes = 1; | 1764 | xs_integer numNodes( 1 ); |
115 | 1766 | std::vector<store::Item_t> nodes; | 1765 | std::vector<store::Item_t> nodes; |
116 | 1767 | std::auto_ptr<store::PUL> pul; | 1766 | std::auto_ptr<store::PUL> pul; |
117 | 1768 | 1767 | ||
118 | @@ -1796,7 +1795,7 @@ | |||
119 | 1796 | // create the pul and add the primitive | 1795 | // create the pul and add the primitive |
120 | 1797 | pul.reset(GENV_ITEMFACTORY->createPendingUpdateList()); | 1796 | pul.reset(GENV_ITEMFACTORY->createPendingUpdateList()); |
121 | 1798 | 1797 | ||
123 | 1799 | for (xs_integer i = numNodes; i > xs_integer(0); --i) | 1798 | for (xs_integer i = numNodes; i > 0; --i) |
124 | 1800 | nodes.push_back(collection->nodeAt(collection->size() - i)); | 1799 | nodes.push_back(collection->nodeAt(collection->size() - i)); |
125 | 1801 | 1800 | ||
126 | 1802 | pul->addDeleteFromCollection(&loc, collectionName, nodes, true, theDynamicCollection); | 1801 | pul->addDeleteFromCollection(&loc, collectionName, nodes, true, theDynamicCollection); |
127 | 1803 | 1802 | ||
128 | === modified file 'src/runtime/core/gflwor/window_iterator.cpp' | |||
129 | --- src/runtime/core/gflwor/window_iterator.cpp 2012-04-09 23:08:06 +0000 | |||
130 | +++ src/runtime/core/gflwor/window_iterator.cpp 2012-04-16 15:38:09 +0000 | |||
131 | @@ -150,7 +150,7 @@ | |||
132 | 150 | 150 | ||
133 | 151 | if (!theCurVars.empty()) | 151 | if (!theCurVars.empty()) |
134 | 152 | { | 152 | { |
136 | 153 | aInputSeq->getItem(aPosition, lItem); | 153 | aInputSeq->getItem(xs_integer(aPosition), lItem); |
137 | 154 | bindVariables(lItem, theCurVars, aPlanState); | 154 | bindVariables(lItem, theCurVars, aPlanState); |
138 | 155 | } | 155 | } |
139 | 156 | 156 | ||
140 | @@ -158,7 +158,7 @@ | |||
141 | 158 | { | 158 | { |
142 | 159 | if (aPosition > 1) | 159 | if (aPosition > 1) |
143 | 160 | { | 160 | { |
145 | 161 | aInputSeq->getItem(aPosition - 1, lItem); | 161 | aInputSeq->getItem(xs_integer(aPosition - 1), lItem); |
146 | 162 | } | 162 | } |
147 | 163 | else | 163 | else |
148 | 164 | { | 164 | { |
149 | @@ -170,9 +170,9 @@ | |||
150 | 170 | 170 | ||
151 | 171 | if (!theNextVars.empty()) | 171 | if (!theNextVars.empty()) |
152 | 172 | { | 172 | { |
154 | 173 | if (aInputSeq->containsItem(aPosition + 1)) | 173 | if (aInputSeq->containsItem(xs_integer(aPosition + 1))) |
155 | 174 | { | 174 | { |
157 | 175 | aInputSeq->getItem(aPosition + 1, lItem); | 175 | aInputSeq->getItem(xs_integer(aPosition + 1), lItem); |
158 | 176 | } | 176 | } |
159 | 177 | else | 177 | else |
160 | 178 | { | 178 | { |
161 | @@ -185,7 +185,7 @@ | |||
162 | 185 | if (!thePosVars.empty()) | 185 | if (!thePosVars.empty()) |
163 | 186 | { | 186 | { |
164 | 187 | store::Item_t lPosItem; | 187 | store::Item_t lPosItem; |
166 | 188 | GENV_ITEMFACTORY->createInteger(lPosItem, Integer(aPosition)); | 188 | GENV_ITEMFACTORY->createInteger(lPosItem, xs_integer(aPosition)); |
167 | 189 | bindVariables(lPosItem, thePosVars, aPlanState); | 189 | bindVariables(lPosItem, thePosVars, aPlanState); |
168 | 190 | } | 190 | } |
169 | 191 | } | 191 | } |
170 | @@ -208,7 +208,7 @@ | |||
171 | 208 | 208 | ||
172 | 209 | if (!theCurOuterVars.empty()) | 209 | if (!theCurOuterVars.empty()) |
173 | 210 | { | 210 | { |
175 | 211 | aInputSeq->getItem(aPosition, lItem); | 211 | aInputSeq->getItem(xs_integer(aPosition), lItem); |
176 | 212 | bindVariables(lItem, theCurOuterVars, aPlanState); | 212 | bindVariables(lItem, theCurOuterVars, aPlanState); |
177 | 213 | } | 213 | } |
178 | 214 | 214 | ||
179 | @@ -216,7 +216,7 @@ | |||
180 | 216 | { | 216 | { |
181 | 217 | if (aPosition > 1) | 217 | if (aPosition > 1) |
182 | 218 | { | 218 | { |
184 | 219 | aInputSeq->getItem(aPosition - 1, lItem); | 219 | aInputSeq->getItem(xs_integer(aPosition - 1), lItem); |
185 | 220 | } | 220 | } |
186 | 221 | else | 221 | else |
187 | 222 | { | 222 | { |
188 | @@ -228,9 +228,9 @@ | |||
189 | 228 | 228 | ||
190 | 229 | if (!theNextOuterVars.empty()) | 229 | if (!theNextOuterVars.empty()) |
191 | 230 | { | 230 | { |
193 | 231 | if (aInputSeq->containsItem(aPosition + 1)) | 231 | if (aInputSeq->containsItem(xs_integer(aPosition + 1))) |
194 | 232 | { | 232 | { |
196 | 233 | aInputSeq->getItem(aPosition + 1, lItem); | 233 | aInputSeq->getItem(xs_integer(aPosition + 1), lItem); |
197 | 234 | } | 234 | } |
198 | 235 | else | 235 | else |
199 | 236 | { | 236 | { |
200 | @@ -716,11 +716,14 @@ | |||
201 | 716 | ulong aStartPos, | 716 | ulong aStartPos, |
202 | 717 | ulong aEndPos) const | 717 | ulong aEndPos) const |
203 | 718 | { | 718 | { |
204 | 719 | xs_integer const lStartPos( aStartPos ); | ||
205 | 720 | xs_integer const lEndPos( aEndPos ); | ||
206 | 721 | |||
207 | 719 | for (std::vector<LetVarIter_t>::const_iterator lVarIter = theVarRefs.begin(); | 722 | for (std::vector<LetVarIter_t>::const_iterator lVarIter = theVarRefs.begin(); |
208 | 720 | lVarIter != theVarRefs.end(); | 723 | lVarIter != theVarRefs.end(); |
209 | 721 | ++lVarIter) | 724 | ++lVarIter) |
210 | 722 | { | 725 | { |
212 | 723 | (*lVarIter)->bind(aInputSeq, aPlanState, aStartPos, aEndPos); | 726 | (*lVarIter)->bind(aInputSeq, aPlanState, lStartPos, lEndPos); |
213 | 724 | } | 727 | } |
214 | 725 | } | 728 | } |
215 | 726 | 729 | ||
216 | @@ -736,13 +739,13 @@ | |||
217 | 736 | if (lState->theOpenWindows.empty()) | 739 | if (lState->theOpenWindows.empty()) |
218 | 737 | { | 740 | { |
219 | 738 | if (lState->theCurInputPos > theMaxNeededHistory) | 741 | if (lState->theCurInputPos > theMaxNeededHistory) |
221 | 739 | lState->theDomainSeq->purgeUpTo(lState->theCurInputPos - theMaxNeededHistory); | 742 | lState->theDomainSeq->purgeUpTo(xs_integer(lState->theCurInputPos - theMaxNeededHistory)); |
222 | 740 | } | 743 | } |
223 | 741 | else | 744 | else |
224 | 742 | { | 745 | { |
225 | 743 | int32_t lPurgeTo = lState->theOpenWindows.front().theStartPos - theMaxNeededHistory; | 746 | int32_t lPurgeTo = lState->theOpenWindows.front().theStartPos - theMaxNeededHistory; |
226 | 744 | if (lPurgeTo > 0) | 747 | if (lPurgeTo > 0) |
228 | 745 | lState->theDomainSeq->purgeUpTo(lPurgeTo); | 748 | lState->theDomainSeq->purgeUpTo(xs_integer(lPurgeTo)); |
229 | 746 | } | 749 | } |
230 | 747 | } | 750 | } |
231 | 748 | } | 751 | } |
232 | @@ -769,7 +772,8 @@ | |||
233 | 769 | if (theWindowType == WindowIterator::SLIDING) | 772 | if (theWindowType == WindowIterator::SLIDING) |
234 | 770 | { | 773 | { |
235 | 771 | // Get the next item from the domain sequence | 774 | // Get the next item from the domain sequence |
237 | 772 | while (lState->theDomainSeq->containsItem(lState->theCurInputPos)) | 775 | // TODO: can the xs_integer be hoisted? |
238 | 776 | while (lState->theDomainSeq->containsItem(xs_integer(lState->theCurInputPos))) | ||
239 | 773 | { | 777 | { |
240 | 774 | // If the current item satisfies the start condition, create a candidate | 778 | // If the current item satisfies the start condition, create a candidate |
241 | 775 | // window starting at the current domain item. | 779 | // window starting at the current domain item. |
242 | @@ -857,7 +861,8 @@ | |||
243 | 857 | // Doing this switch now also avoids further overhad | 861 | // Doing this switch now also avoids further overhad |
244 | 858 | if (theEndClause.theHasEndClause) | 862 | if (theEndClause.theHasEndClause) |
245 | 859 | { | 863 | { |
247 | 860 | while (lState->theDomainSeq->containsItem(lState->theCurInputPos)) | 864 | // TODO: can the xs_integer be hoisted? |
248 | 865 | while (lState->theDomainSeq->containsItem(xs_integer(lState->theCurInputPos))) | ||
249 | 861 | { | 866 | { |
250 | 862 | if (lState->theOpenWindows.empty() && | 867 | if (lState->theOpenWindows.empty() && |
251 | 863 | theStartClause.evaluate(aPlanState, | 868 | theStartClause.evaluate(aPlanState, |
252 | @@ -898,7 +903,8 @@ | |||
253 | 898 | } | 903 | } |
254 | 899 | else | 904 | else |
255 | 900 | { | 905 | { |
257 | 901 | while (lState->theDomainSeq->containsItem(lState->theCurInputPos)) | 906 | // TODO: can the xs_integer be hoisted? |
258 | 907 | while (lState->theDomainSeq->containsItem(xs_integer(lState->theCurInputPos))) | ||
259 | 902 | { | 908 | { |
260 | 903 | if (theStartClause.evaluate(aPlanState, | 909 | if (theStartClause.evaluate(aPlanState, |
261 | 904 | lState->theDomainSeq, | 910 | lState->theDomainSeq, |
262 | 905 | 911 | ||
263 | === modified file 'src/runtime/core/trycatch.cpp' | |||
264 | --- src/runtime/core/trycatch.cpp 2012-04-09 23:08:06 +0000 | |||
265 | +++ src/runtime/core/trycatch.cpp 2012-04-16 15:38:09 +0000 | |||
266 | @@ -274,7 +274,8 @@ | |||
267 | 274 | 274 | ||
268 | 275 | // function arity | 275 | // function arity |
269 | 276 | lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME; | 276 | lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME; |
271 | 277 | GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getFnArity() ); | 277 | GENV_ITEMFACTORY->createInteger( |
272 | 278 | lTmpValue, xs_integer(lIter->getFnArity())); | ||
273 | 278 | GENV_ITEMFACTORY->createAttributeNode( | 279 | GENV_ITEMFACTORY->createAttributeNode( |
274 | 279 | lTmpAttr, lFunction.getp(), lArityQName, lTypeName, | 280 | lTmpAttr, lFunction.getp(), lArityQName, lTypeName, |
275 | 280 | lTmpValue); | 281 | lTmpValue); |
276 | @@ -289,28 +290,31 @@ | |||
277 | 289 | 290 | ||
278 | 290 | // location line begin | 291 | // location line begin |
279 | 291 | lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME; | 292 | lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME; |
281 | 292 | GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getLine() ); | 293 | GENV_ITEMFACTORY->createInteger( lTmpValue, xs_integer(lIter->getLine()) ); |
282 | 293 | GENV_ITEMFACTORY->createAttributeNode( | 294 | GENV_ITEMFACTORY->createAttributeNode( |
283 | 294 | lTmpAttr, lLocation.getp(), lLineBeginQName, lTypeName, | 295 | lTmpAttr, lLocation.getp(), lLineBeginQName, lTypeName, |
284 | 295 | lTmpValue); | 296 | lTmpValue); |
285 | 296 | 297 | ||
286 | 297 | // location line end | 298 | // location line end |
287 | 298 | lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME; | 299 | lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME; |
289 | 299 | GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getLineEnd() ); | 300 | GENV_ITEMFACTORY->createInteger( |
290 | 301 | lTmpValue, xs_integer(lIter->getLineEnd())); | ||
291 | 300 | GENV_ITEMFACTORY->createAttributeNode( | 302 | GENV_ITEMFACTORY->createAttributeNode( |
292 | 301 | lTmpAttr, lLocation.getp(), lLineEndQName, lTypeName, | 303 | lTmpAttr, lLocation.getp(), lLineEndQName, lTypeName, |
293 | 302 | lTmpValue); | 304 | lTmpValue); |
294 | 303 | 305 | ||
295 | 304 | // location column begin | 306 | // location column begin |
296 | 305 | lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME; | 307 | lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME; |
298 | 306 | GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getColumn() ); | 308 | GENV_ITEMFACTORY->createInteger( |
299 | 309 | lTmpValue, xs_integer(lIter->getColumn())); | ||
300 | 307 | GENV_ITEMFACTORY->createAttributeNode( | 310 | GENV_ITEMFACTORY->createAttributeNode( |
301 | 308 | lTmpAttr, lLocation.getp(), lColumnBeginQName, lTypeName, | 311 | lTmpAttr, lLocation.getp(), lColumnBeginQName, lTypeName, |
302 | 309 | lTmpValue); | 312 | lTmpValue); |
303 | 310 | 313 | ||
304 | 311 | // location column end | 314 | // location column end |
305 | 312 | lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME; | 315 | lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME; |
307 | 313 | GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getColumnEnd() ); | 316 | GENV_ITEMFACTORY->createInteger( |
308 | 317 | lTmpValue, xs_integer(lIter->getColumnEnd())); | ||
309 | 314 | GENV_ITEMFACTORY->createAttributeNode( | 318 | GENV_ITEMFACTORY->createAttributeNode( |
310 | 315 | lTmpAttr, lLocation.getp(), lColumnEndQName, lTypeName, | 319 | lTmpAttr, lLocation.getp(), lColumnEndQName, lTypeName, |
311 | 316 | lTmpValue); | 320 | lTmpValue); |
312 | @@ -446,7 +450,8 @@ | |||
313 | 446 | if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) && | 450 | if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) && |
314 | 447 | ue->has_source() ) { | 451 | ue->has_source() ) { |
315 | 448 | store::Item_t lErrorLineItem; | 452 | store::Item_t lErrorLineItem; |
317 | 449 | GENV_ITEMFACTORY->createInteger(lErrorLineItem, ue->source_line()); | 453 | GENV_ITEMFACTORY->createInteger( |
318 | 454 | lErrorLineItem, xs_integer(ue->source_line())); | ||
319 | 450 | lErrorLineIter = new ItemIterator(lErrorLineItem); | 455 | lErrorLineIter = new ItemIterator(lErrorLineItem); |
320 | 451 | } | 456 | } |
321 | 452 | else | 457 | else |
322 | @@ -472,7 +477,8 @@ | |||
323 | 472 | if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) && | 477 | if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) && |
324 | 473 | ue->has_source() ) { | 478 | ue->has_source() ) { |
325 | 474 | store::Item_t lErrorColumnItem; | 479 | store::Item_t lErrorColumnItem; |
327 | 475 | GENV_ITEMFACTORY->createInteger(lErrorColumnItem, ue->source_column()); | 480 | GENV_ITEMFACTORY->createInteger( |
328 | 481 | lErrorColumnItem, xs_integer(ue->source_column())); | ||
329 | 476 | lErrorColumnIter = new ItemIterator(lErrorColumnItem); | 482 | lErrorColumnIter = new ItemIterator(lErrorColumnItem); |
330 | 477 | } | 483 | } |
331 | 478 | else | 484 | else |
332 | 479 | 485 | ||
333 | === modified file 'src/runtime/maths/maths_impl.cpp' | |||
334 | --- src/runtime/maths/maths_impl.cpp 2012-03-30 19:03:09 +0000 | |||
335 | +++ src/runtime/maths/maths_impl.cpp 2012-04-16 15:38:09 +0000 | |||
336 | @@ -500,7 +500,7 @@ | |||
337 | 500 | PlanIteratorState* state; | 500 | PlanIteratorState* state; |
338 | 501 | DEFAULT_STACK_INIT ( PlanIteratorState, state, planState ); | 501 | DEFAULT_STACK_INIT ( PlanIteratorState, state, planState ); |
339 | 502 | 502 | ||
341 | 503 | GENV_ITEMFACTORY->createDouble(result, 3.141592653589793e0); | 503 | GENV_ITEMFACTORY->createDouble(result, xs_double(3.141592653589793e0)); |
342 | 504 | STACK_PUSH (true, state); | 504 | STACK_PUSH (true, state); |
343 | 505 | 505 | ||
344 | 506 | STACK_END (state); | 506 | STACK_END (state); |
345 | 507 | 507 | ||
346 | === modified file 'src/runtime/numerics/format_integer_impl.cpp' | |||
347 | --- src/runtime/numerics/format_integer_impl.cpp 2012-03-30 19:03:09 +0000 | |||
348 | +++ src/runtime/numerics/format_integer_impl.cpp 2012-04-16 15:38:09 +0000 | |||
349 | @@ -164,8 +164,8 @@ | |||
350 | 164 | static const unsigned int letter_range = 'Z' - 'A' + 1; | 164 | static const unsigned int letter_range = 'Z' - 'A' + 1; |
351 | 165 | static xs_integer integer_digit(letter_range); | 165 | static xs_integer integer_digit(letter_range); |
352 | 166 | xs_integer upper_int = valueInteger/integer_digit; | 166 | xs_integer upper_int = valueInteger/integer_digit; |
355 | 167 | if(upper_int > xs_integer::zero()) | 167 | if(upper_int > 0) |
356 | 168 | formatIntegerAZ(upper_int - xs_integer::one(), c0, resultString); | 168 | formatIntegerAZ(upper_int - 1, c0, resultString); |
357 | 169 | xs_integer mod_integer = valueInteger % integer_digit; | 169 | xs_integer mod_integer = valueInteger % integer_digit; |
358 | 170 | xs_int mod_int = to_xs_int(mod_integer); | 170 | xs_int mod_int = to_xs_int(mod_integer); |
359 | 171 | resultString += (c0 + mod_int); | 171 | resultString += (c0 + mod_int); |
360 | @@ -426,7 +426,7 @@ | |||
361 | 426 | formatIntegerEnglish(valueInteger/integer_##big_number_name, false, resultString); \ | 426 | formatIntegerEnglish(valueInteger/integer_##big_number_name, false, resultString); \ |
362 | 427 | resultString += " " #big_number_name; \ | 427 | resultString += " " #big_number_name; \ |
363 | 428 | value_mod = valueInteger % integer_##big_number_name; \ | 428 | value_mod = valueInteger % integer_##big_number_name; \ |
365 | 429 | if(value_mod > xs_integer::zero()) \ | 429 | if(value_mod > 0) \ |
366 | 430 | { \ | 430 | { \ |
367 | 431 | resultString += " "; \ | 431 | resultString += " "; \ |
368 | 432 | formatIntegerEnglish(value_mod, is_ordinal, resultString); \ | 432 | formatIntegerEnglish(value_mod, is_ordinal, resultString); \ |
369 | @@ -439,7 +439,7 @@ | |||
370 | 439 | else if (valueInteger >= integer_##decim) \ | 439 | else if (valueInteger >= integer_##decim) \ |
371 | 440 | { \ | 440 | { \ |
372 | 441 | value_mod = valueInteger % integer_##decim; \ | 441 | value_mod = valueInteger % integer_##decim; \ |
374 | 442 | if(value_mod > xs_integer::zero()) \ | 442 | if(value_mod > 0) \ |
375 | 443 | { \ | 443 | { \ |
376 | 444 | resultString += decim_cardinal; \ | 444 | resultString += decim_cardinal; \ |
377 | 445 | resultString += "-"; \ | 445 | resultString += "-"; \ |
378 | @@ -504,7 +504,7 @@ | |||
379 | 504 | IF_GE_DECIM(3, "three", "third") | 504 | IF_GE_DECIM(3, "three", "third") |
380 | 505 | IF_GE_DECIM(2, "two", "second") | 505 | IF_GE_DECIM(2, "two", "second") |
381 | 506 | IF_GE_DECIM(1, "one", "first") | 506 | IF_GE_DECIM(1, "one", "first") |
383 | 507 | else if (valueInteger == xs_integer::zero()) | 507 | else if (valueInteger == 0) |
384 | 508 | { | 508 | { |
385 | 509 | if(!is_ordinal) | 509 | if(!is_ordinal) |
386 | 510 | resultString += "zero"; | 510 | resultString += "zero"; |
387 | @@ -771,7 +771,7 @@ | |||
388 | 771 | if (consumeNext(value_item, theChildren[0].getp(), planState)) | 771 | if (consumeNext(value_item, theChildren[0].getp(), planState)) |
389 | 772 | { | 772 | { |
390 | 773 | valueInteger = value_item->getIntegerValue(); | 773 | valueInteger = value_item->getIntegerValue(); |
392 | 774 | if(valueInteger < xs_integer::zero()) | 774 | if(valueInteger < 0) |
393 | 775 | { | 775 | { |
394 | 776 | valueInteger = -valueInteger; | 776 | valueInteger = -valueInteger; |
395 | 777 | is_neg = true; | 777 | is_neg = true; |
396 | @@ -811,17 +811,17 @@ | |||
397 | 811 | if((c0 == 'a') || (c0 == 'A')) | 811 | if((c0 == 'a') || (c0 == 'A')) |
398 | 812 | { | 812 | { |
399 | 813 | checkOptionalModifier(utf8_picture, 1, &is_ordinal, &is_traditional, utf8_word_terminal); | 813 | checkOptionalModifier(utf8_picture, 1, &is_ordinal, &is_traditional, utf8_word_terminal); |
401 | 814 | if(valueInteger > xs_integer::zero()) | 814 | if(valueInteger > 0) |
402 | 815 | { | 815 | { |
403 | 816 | if(is_neg) | 816 | if(is_neg) |
404 | 817 | resultString += '-'; | 817 | resultString += '-'; |
406 | 818 | formatIntegerAZ(valueInteger-xs_integer::one(), c0, resultString); | 818 | formatIntegerAZ(valueInteger-1, c0, resultString); |
407 | 819 | } | 819 | } |
408 | 820 | } | 820 | } |
409 | 821 | else if((c0 == 'i') || (c0 == 'I')) | 821 | else if((c0 == 'i') || (c0 == 'I')) |
410 | 822 | { | 822 | { |
411 | 823 | checkOptionalModifier(utf8_picture, 1, &is_ordinal, &is_traditional, utf8_word_terminal); | 823 | checkOptionalModifier(utf8_picture, 1, &is_ordinal, &is_traditional, utf8_word_terminal); |
413 | 824 | if(valueInteger > xs_integer::zero()) | 824 | if(valueInteger > 0) |
414 | 825 | { | 825 | { |
415 | 826 | if(is_neg) | 826 | if(is_neg) |
416 | 827 | resultString += ("-"); | 827 | resultString += ("-"); |
417 | 828 | 828 | ||
418 | === modified file 'src/runtime/random/random_impl.cpp' | |||
419 | --- src/runtime/random/random_impl.cpp 2012-03-30 19:03:09 +0000 | |||
420 | +++ src/runtime/random/random_impl.cpp 2012-04-16 15:38:09 +0000 | |||
421 | @@ -45,7 +45,7 @@ | |||
422 | 45 | 45 | ||
423 | 46 | consumeNext(seed, theChildren[0].getp(), planState); | 46 | consumeNext(seed, theChildren[0].getp(), planState); |
424 | 47 | consumeNext(num, theChildren[1].getp(), planState); | 47 | consumeNext(num, theChildren[1].getp(), planState); |
426 | 48 | if ( num->getIntegerValue() < xs_integer( 0 ) ) | 48 | if ( num->getIntegerValue() < 0 ) |
427 | 49 | { | 49 | { |
428 | 50 | STACK_PUSH(false, state); | 50 | STACK_PUSH(false, state); |
429 | 51 | } | 51 | } |
430 | @@ -110,7 +110,7 @@ | |||
431 | 110 | DEFAULT_STACK_INIT(RandomIteratorState, state, planState); | 110 | DEFAULT_STACK_INIT(RandomIteratorState, state, planState); |
432 | 111 | 111 | ||
433 | 112 | consumeNext(num, theChildren[0].getp(), planState); | 112 | consumeNext(num, theChildren[0].getp(), planState); |
435 | 113 | if ( num->getIntegerValue() < xs_integer( 0 ) ) | 113 | if ( num->getIntegerValue() < 0 ) |
436 | 114 | { | 114 | { |
437 | 115 | STACK_PUSH(false, state); | 115 | STACK_PUSH(false, state); |
438 | 116 | } | 116 | } |
439 | 117 | 117 | ||
440 | === modified file 'src/runtime/sequences/sequences_impl.cpp' | |||
441 | --- src/runtime/sequences/sequences_impl.cpp 2012-03-30 19:03:09 +0000 | |||
442 | +++ src/runtime/sequences/sequences_impl.cpp 2012-04-16 15:38:09 +0000 | |||
443 | @@ -322,12 +322,12 @@ | |||
444 | 322 | } | 322 | } |
445 | 323 | 323 | ||
446 | 324 | state->thePosition = lPositionItem->getIntegerValue(); | 324 | state->thePosition = lPositionItem->getIntegerValue(); |
449 | 325 | if (state->thePosition < xs_integer::one()) | 325 | if (state->thePosition < 1) |
450 | 326 | state->thePosition = xs_integer::one(); | 326 | state->thePosition = 1; |
451 | 327 | 327 | ||
452 | 328 | while (consumeNext(result, theChildren[0].getp(), planState)) | 328 | while (consumeNext(result, theChildren[0].getp(), planState)) |
453 | 329 | { | 329 | { |
455 | 330 | if ( state->theCurrentPos == state->thePosition-xs_integer::one() ) // position found => insert sequence | 330 | if ( state->theCurrentPos == state->thePosition-1 ) // position found => insert sequence |
456 | 331 | { | 331 | { |
457 | 332 | state->theTargetItem = result; | 332 | state->theTargetItem = result; |
458 | 333 | while ( consumeNext(result, theChildren[2].getp(), planState)) | 333 | while ( consumeNext(result, theChildren[2].getp(), planState)) |
459 | 334 | 334 | ||
460 | === modified file 'src/runtime/store/maps_impl.cpp' | |||
461 | --- src/runtime/store/maps_impl.cpp 2012-03-30 19:03:09 +0000 | |||
462 | +++ src/runtime/store/maps_impl.cpp 2012-04-16 15:38:09 +0000 | |||
463 | @@ -540,7 +540,7 @@ | |||
464 | 540 | ); | 540 | ); |
465 | 541 | } | 541 | } |
466 | 542 | 542 | ||
468 | 543 | GENV_ITEMFACTORY->createInteger(result, lIndex->size()); | 543 | GENV_ITEMFACTORY->createInteger(result, xs_integer(lIndex->size())); |
469 | 544 | 544 | ||
470 | 545 | STACK_PUSH(true, state); | 545 | STACK_PUSH(true, state); |
471 | 546 | 546 | ||
472 | 547 | 547 | ||
473 | === modified file 'src/store/naive/atomic_items.cpp' | |||
474 | --- src/store/naive/atomic_items.cpp 2012-03-30 19:03:09 +0000 | |||
475 | +++ src/store/naive/atomic_items.cpp 2012-04-16 15:38:09 +0000 | |||
476 | @@ -1472,7 +1472,7 @@ | |||
477 | 1472 | store::Item_t StructuralAnyUriItem::getLevel() const | 1472 | store::Item_t StructuralAnyUriItem::getLevel() const |
478 | 1473 | { | 1473 | { |
479 | 1474 | store::Item_t lResult; | 1474 | store::Item_t lResult; |
481 | 1475 | GET_FACTORY().createInteger(lResult, theOrdPath.getLevel()); | 1475 | GET_FACTORY().createInteger(lResult, xs_integer(theOrdPath.getLevel())); |
482 | 1476 | return lResult; | 1476 | return lResult; |
483 | 1477 | } | 1477 | } |
484 | 1478 | 1478 | ||
485 | @@ -2747,7 +2747,7 @@ | |||
486 | 2747 | } | 2747 | } |
487 | 2748 | 2748 | ||
488 | 2749 | xs_nonNegativeInteger LongItem::getUnsignedIntegerValue() const { | 2749 | xs_nonNegativeInteger LongItem::getUnsignedIntegerValue() const { |
490 | 2750 | return theValue >= 0 ? theValue : -theValue; | 2750 | return xs_nonNegativeInteger( theValue >= 0 ? theValue : -theValue ); |
491 | 2751 | } | 2751 | } |
492 | 2752 | 2752 | ||
493 | 2753 | store::Item* LongItem::getType() const | 2753 | store::Item* LongItem::getType() const |
494 | 2754 | 2754 | ||
495 | === modified file 'src/store/naive/collection.h' | |||
496 | --- src/store/naive/collection.h 2012-03-28 23:58:23 +0000 | |||
497 | +++ src/store/naive/collection.h 2012-04-16 15:38:09 +0000 | |||
498 | @@ -65,7 +65,7 @@ | |||
499 | 65 | 65 | ||
500 | 66 | /************************* Updates on collection ****************************/ | 66 | /************************* Updates on collection ****************************/ |
501 | 67 | 67 | ||
503 | 68 | virtual void addNode(store::Item* node, xs_integer position = -1) = 0; | 68 | virtual void addNode(store::Item* node, xs_integer position = xs_integer(-1)) = 0; |
504 | 69 | 69 | ||
505 | 70 | virtual zorba::xs_integer addNodes( | 70 | virtual zorba::xs_integer addNodes( |
506 | 71 | std::vector<store::Item_t>& nodes, | 71 | std::vector<store::Item_t>& nodes, |
507 | 72 | 72 | ||
508 | === modified file 'src/store/naive/node_items.cpp' | |||
509 | --- src/store/naive/node_items.cpp 2012-04-12 02:08:10 +0000 | |||
510 | +++ src/store/naive/node_items.cpp 2012-04-16 15:38:09 +0000 | |||
511 | @@ -1294,7 +1294,7 @@ | |||
512 | 1294 | lCurrent = lCurrent->getParent(); | 1294 | lCurrent = lCurrent->getParent(); |
513 | 1295 | } | 1295 | } |
514 | 1296 | store::Item_t lRes; | 1296 | store::Item_t lRes; |
516 | 1297 | GET_FACTORY().createInteger(lRes, lNumLevels); | 1297 | GET_FACTORY().createInteger(lRes, xs_integer(lNumLevels)); |
517 | 1298 | return lRes; | 1298 | return lRes; |
518 | 1299 | } | 1299 | } |
519 | 1300 | 1300 | ||
520 | 1301 | 1301 | ||
521 | === modified file 'src/store/naive/pul_primitives.cpp' | |||
522 | --- src/store/naive/pul_primitives.cpp 2012-03-30 19:03:09 +0000 | |||
523 | +++ src/store/naive/pul_primitives.cpp 2012-04-16 15:38:09 +0000 | |||
524 | @@ -986,7 +986,7 @@ | |||
525 | 986 | 986 | ||
526 | 987 | for (uint64_t i = 0; i < size; ++i) | 987 | for (uint64_t i = 0; i < size; ++i) |
527 | 988 | { | 988 | { |
529 | 989 | XmlNode* root = static_cast<XmlNode*>(collection->nodeAt(i).getp()); | 989 | XmlNode* root = static_cast<XmlNode*>(collection->nodeAt(xs_integer(i)).getp()); |
530 | 990 | XmlTree* tree = root->getTree(); | 990 | XmlTree* tree = root->getTree(); |
531 | 991 | if (tree->getRefCount() > 1) | 991 | if (tree->getRefCount() > 1) |
532 | 992 | throw XQUERY_EXCEPTION( | 992 | throw XQUERY_EXCEPTION( |
533 | @@ -1021,7 +1021,7 @@ | |||
534 | 1021 | std::size_t numNodes = theNodes.size(); | 1021 | std::size_t numNodes = theNodes.size(); |
535 | 1022 | for (std::size_t i = 0; i < numNodes; ++i) | 1022 | for (std::size_t i = 0; i < numNodes; ++i) |
536 | 1023 | { | 1023 | { |
538 | 1024 | lColl->addNode(theNodes[i], -1); | 1024 | lColl->addNode(theNodes[i], xs_integer(-1)); |
539 | 1025 | ++theNumApplied; | 1025 | ++theNumApplied; |
540 | 1026 | } | 1026 | } |
541 | 1027 | } | 1027 | } |
542 | @@ -1051,9 +1051,10 @@ | |||
543 | 1051 | 1051 | ||
544 | 1052 | for (long i = theNumApplied-1; i >= 0; --i) | 1052 | for (long i = theNumApplied-1; i >= 0; --i) |
545 | 1053 | { | 1053 | { |
547 | 1054 | ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(lastPos)); | 1054 | xs_integer xs_lastPos( lastPos ); |
548 | 1055 | ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(xs_lastPos)); | ||
549 | 1055 | 1056 | ||
551 | 1056 | lColl->removeNode(lastPos); | 1057 | lColl->removeNode(xs_lastPos); |
552 | 1057 | --lastPos; | 1058 | --lastPos; |
553 | 1058 | } | 1059 | } |
554 | 1059 | } | 1060 | } |
555 | @@ -1075,7 +1076,7 @@ | |||
556 | 1075 | std::size_t numNodes = theNodes.size(); | 1076 | std::size_t numNodes = theNodes.size(); |
557 | 1076 | for (std::size_t i = 0; i < numNodes; ++i) | 1077 | for (std::size_t i = 0; i < numNodes; ++i) |
558 | 1077 | { | 1078 | { |
560 | 1078 | lColl->addNode(theNodes[i], i); | 1079 | lColl->addNode(theNodes[i], xs_integer(i)); |
561 | 1079 | ++theNumApplied; | 1080 | ++theNumApplied; |
562 | 1080 | } | 1081 | } |
563 | 1081 | } | 1082 | } |
564 | @@ -1087,11 +1088,12 @@ | |||
565 | 1087 | (GET_STORE().getCollection(theName, theDynamicCollection).getp()); | 1088 | (GET_STORE().getCollection(theName, theDynamicCollection).getp()); |
566 | 1088 | assert(lColl); | 1089 | assert(lColl); |
567 | 1089 | 1090 | ||
568 | 1091 | xs_integer const zero( xs_integer::zero() ); | ||
569 | 1090 | for (std::size_t i = 0; i < theNumApplied; ++i) | 1092 | for (std::size_t i = 0; i < theNumApplied; ++i) |
570 | 1091 | { | 1093 | { |
572 | 1092 | ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(0)); | 1094 | ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(zero)); |
573 | 1093 | 1095 | ||
575 | 1094 | lColl->removeNode((uint64_t)0); | 1096 | lColl->removeNode(zero); |
576 | 1095 | } | 1097 | } |
577 | 1096 | } | 1098 | } |
578 | 1097 | 1099 | ||
579 | @@ -1108,9 +1110,10 @@ | |||
580 | 1108 | theIsApplied = true; | 1110 | theIsApplied = true; |
581 | 1109 | 1111 | ||
582 | 1110 | std::size_t numNodes = theNodes.size(); | 1112 | std::size_t numNodes = theNodes.size(); |
583 | 1113 | xs_integer const neg_1( -1 ); | ||
584 | 1111 | for (std::size_t i = 0; i < numNodes; ++i) | 1114 | for (std::size_t i = 0; i < numNodes; ++i) |
585 | 1112 | { | 1115 | { |
587 | 1113 | lColl->addNode(theNodes[i], -1); | 1116 | lColl->addNode(theNodes[i], neg_1); |
588 | 1114 | } | 1117 | } |
589 | 1115 | } | 1118 | } |
590 | 1116 | 1119 | ||
591 | @@ -1135,11 +1138,12 @@ | |||
592 | 1135 | ); | 1138 | ); |
593 | 1136 | } | 1139 | } |
594 | 1137 | 1140 | ||
595 | 1141 | xs_integer const xs_lastPos( lastPos ); | ||
596 | 1138 | for (long i = theNumApplied-1; i >= 0; --i) | 1142 | for (long i = theNumApplied-1; i >= 0; --i) |
597 | 1139 | { | 1143 | { |
599 | 1140 | ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(lastPos)); | 1144 | ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(xs_lastPos)); |
600 | 1141 | 1145 | ||
602 | 1142 | lColl->removeNode(lastPos); | 1146 | lColl->removeNode(xs_lastPos); |
603 | 1143 | } | 1147 | } |
604 | 1144 | } | 1148 | } |
605 | 1145 | 1149 | ||
606 | @@ -1170,7 +1174,7 @@ | |||
607 | 1170 | assert(lColl); | 1174 | assert(lColl); |
608 | 1171 | ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos)); | 1175 | ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos)); |
609 | 1172 | 1176 | ||
611 | 1173 | lColl->removeNodes(theFirstPos, (uint64_t)theNodes.size()); | 1177 | lColl->removeNodes(theFirstPos, xs_integer(theNodes.size())); |
612 | 1174 | } | 1178 | } |
613 | 1175 | 1179 | ||
614 | 1176 | 1180 | ||
615 | @@ -1201,7 +1205,7 @@ | |||
616 | 1201 | assert(lColl); | 1205 | assert(lColl); |
617 | 1202 | ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos)); | 1206 | ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos)); |
618 | 1203 | 1207 | ||
620 | 1204 | lColl->removeNodes(theFirstPos, (uint64_t)theNodes.size()); | 1208 | lColl->removeNodes(theFirstPos, xs_integer(theNodes.size())); |
621 | 1205 | } | 1209 | } |
622 | 1206 | 1210 | ||
623 | 1207 | 1211 | ||
624 | @@ -1240,7 +1244,7 @@ | |||
625 | 1240 | { | 1244 | { |
626 | 1241 | for (std::size_t i = numNodes; i > 0; --i) | 1245 | for (std::size_t i = numNodes; i > 0; --i) |
627 | 1242 | { | 1246 | { |
629 | 1243 | if (theNodes[i-1] != lColl->nodeAt(size - i)) | 1247 | if (theNodes[i-1] != lColl->nodeAt(xs_integer(size - i))) |
630 | 1244 | { | 1248 | { |
631 | 1245 | isLast = false; | 1249 | isLast = false; |
632 | 1246 | break; | 1250 | break; |
633 | 1247 | 1251 | ||
634 | === modified file 'src/store/naive/simple_collection.cpp' | |||
635 | --- src/store/naive/simple_collection.cpp 2012-03-30 19:03:09 +0000 | |||
636 | +++ src/store/naive/simple_collection.cpp 2012-04-16 15:38:09 +0000 | |||
637 | @@ -124,16 +124,16 @@ | |||
638 | 124 | 124 | ||
639 | 125 | SYNC_CODE(AutoLatch lock(theLatch, Latch::WRITE);); | 125 | SYNC_CODE(AutoLatch lock(theLatch, Latch::WRITE);); |
640 | 126 | 126 | ||
642 | 127 | if (lPosition < 0 || to_xs_unsignedLong(lPosition) >= theXmlTrees.size()) | 127 | if (lPosition < 0 || lPosition >= theXmlTrees.size()) |
643 | 128 | { | 128 | { |
644 | 129 | theXmlTrees.push_back(nodeItem); | 129 | theXmlTrees.push_back(nodeItem); |
646 | 130 | node->setCollection(this, (uint64_t)theXmlTrees.size() - 1); | 130 | node->setCollection(this, xs_integer(theXmlTrees.size() - 1)); |
647 | 131 | } | 131 | } |
648 | 132 | else | 132 | else |
649 | 133 | { | 133 | { |
650 | 134 | 134 | ||
651 | 135 | theXmlTrees.insert(theXmlTrees.begin() + (std::size_t)lPosition, nodeItem); | 135 | theXmlTrees.insert(theXmlTrees.begin() + (std::size_t)lPosition, nodeItem); |
653 | 136 | node->setCollection(this, to_xs_unsignedInt(lPosition)); | 136 | node->setCollection(this, xs_integer(lPosition)); |
654 | 137 | } | 137 | } |
655 | 138 | } | 138 | } |
656 | 139 | 139 | ||
657 | @@ -203,7 +203,7 @@ | |||
658 | 203 | ); | 203 | ); |
659 | 204 | } | 204 | } |
660 | 205 | 205 | ||
662 | 206 | node->setCollection(this, lTargetPos + i); | 206 | node->setCollection(this, xs_integer(lTargetPos + i)); |
663 | 207 | } | 207 | } |
664 | 208 | 208 | ||
665 | 209 | theXmlTrees.resize(numNodes + numNewNodes); | 209 | theXmlTrees.resize(numNodes + numNewNodes); |
666 | @@ -232,7 +232,7 @@ | |||
667 | 232 | theXmlTrees[lTargetPos + i].transfer(nodes[i]); | 232 | theXmlTrees[lTargetPos + i].transfer(nodes[i]); |
668 | 233 | } | 233 | } |
669 | 234 | 234 | ||
671 | 235 | return lTargetPos; | 235 | return xs_integer( lTargetPos ); |
672 | 236 | } | 236 | } |
673 | 237 | 237 | ||
674 | 238 | 238 | ||
675 | @@ -261,7 +261,7 @@ | |||
676 | 261 | { | 261 | { |
677 | 262 | ZORBA_ASSERT(node->getCollection() == this); | 262 | ZORBA_ASSERT(node->getCollection() == this); |
678 | 263 | 263 | ||
680 | 264 | node->setCollection(NULL, 0); | 264 | node->setCollection(NULL, xs_integer(0)); |
681 | 265 | std::size_t lPosition = to_xs_unsignedInt(position); | 265 | std::size_t lPosition = to_xs_unsignedInt(position); |
682 | 266 | theXmlTrees.erase(theXmlTrees.begin() + lPosition); | 266 | theXmlTrees.erase(theXmlTrees.begin() + lPosition); |
683 | 267 | return true; | 267 | return true; |
684 | @@ -292,7 +292,7 @@ | |||
685 | 292 | XmlNode* node = static_cast<XmlNode*>(theXmlTrees[lPosition].getp()); | 292 | XmlNode* node = static_cast<XmlNode*>(theXmlTrees[lPosition].getp()); |
686 | 293 | ZORBA_ASSERT(node->getCollection() == this); | 293 | ZORBA_ASSERT(node->getCollection() == this); |
687 | 294 | 294 | ||
689 | 295 | node->setCollection(NULL, 0); | 295 | node->setCollection(NULL, xs_integer(0)); |
690 | 296 | theXmlTrees.erase(theXmlTrees.begin() + lPosition); | 296 | theXmlTrees.erase(theXmlTrees.begin() + lPosition); |
691 | 297 | return true; | 297 | return true; |
692 | 298 | } | 298 | } |
693 | @@ -314,7 +314,7 @@ | |||
694 | 314 | 314 | ||
695 | 315 | if (lNum == 0 || lPosition >= theXmlTrees.size()) | 315 | if (lNum == 0 || lPosition >= theXmlTrees.size()) |
696 | 316 | { | 316 | { |
698 | 317 | return 0; | 317 | return xs_integer(0); |
699 | 318 | } | 318 | } |
700 | 319 | else | 319 | else |
701 | 320 | { | 320 | { |
702 | @@ -328,12 +328,12 @@ | |||
703 | 328 | { | 328 | { |
704 | 329 | XmlNode* node = static_cast<XmlNode*>(theXmlTrees[lPosition].getp()); | 329 | XmlNode* node = static_cast<XmlNode*>(theXmlTrees[lPosition].getp()); |
705 | 330 | ZORBA_ASSERT(node->getCollection() == this); | 330 | ZORBA_ASSERT(node->getCollection() == this); |
707 | 331 | node->setCollection(NULL, 0); | 331 | node->setCollection(NULL, xs_integer(0)); |
708 | 332 | 332 | ||
709 | 333 | theXmlTrees.erase(theXmlTrees.begin() + lPosition); | 333 | theXmlTrees.erase(theXmlTrees.begin() + lPosition); |
710 | 334 | } | 334 | } |
711 | 335 | 335 | ||
713 | 336 | return last-lPosition; | 336 | return xs_integer(last-lPosition); |
714 | 337 | } | 337 | } |
715 | 338 | } | 338 | } |
716 | 339 | 339 | ||
717 | @@ -434,7 +434,7 @@ | |||
718 | 434 | 434 | ||
719 | 435 | for (std::size_t i = 0; i < numTrees; ++i) | 435 | for (std::size_t i = 0; i < numTrees; ++i) |
720 | 436 | { | 436 | { |
722 | 437 | BASE_NODE(theXmlTrees[i])->getTree()->setPosition(i); | 437 | BASE_NODE(theXmlTrees[i])->getTree()->setPosition(xs_integer(i)); |
723 | 438 | } | 438 | } |
724 | 439 | } | 439 | } |
725 | 440 | 440 | ||
726 | 441 | 441 | ||
727 | === modified file 'src/store/naive/simple_collection.h' | |||
728 | --- src/store/naive/simple_collection.h 2012-03-30 19:03:09 +0000 | |||
729 | +++ src/store/naive/simple_collection.h 2012-04-16 15:38:09 +0000 | |||
730 | @@ -100,7 +100,7 @@ | |||
731 | 100 | 100 | ||
732 | 101 | const store::Item* getName() const { return theName.getp(); } | 101 | const store::Item* getName() const { return theName.getp(); } |
733 | 102 | 102 | ||
735 | 103 | xs_integer size() const { return theXmlTrees.size(); } | 103 | xs_integer size() const { return xs_integer( theXmlTrees.size() ); } |
736 | 104 | 104 | ||
737 | 105 | bool isDynamic() const { return theIsDynamic; } | 105 | bool isDynamic() const { return theIsDynamic; } |
738 | 106 | 106 | ||
739 | @@ -110,7 +110,7 @@ | |||
740 | 110 | 110 | ||
741 | 111 | store::Iterator_t getIterator(); | 111 | store::Iterator_t getIterator(); |
742 | 112 | 112 | ||
744 | 113 | void addNode(store::Item* node, xs_integer position = -1); | 113 | void addNode(store::Item* node, xs_integer position = xs_integer(-1)); |
745 | 114 | 114 | ||
746 | 115 | xs_integer addNodes( | 115 | xs_integer addNodes( |
747 | 116 | std::vector<store::Item_t>& nodes, | 116 | std::vector<store::Item_t>& nodes, |
748 | 117 | 117 | ||
749 | === modified file 'src/store/naive/simple_index_general.cpp' | |||
750 | --- src/store/naive/simple_index_general.cpp 2012-03-30 19:03:09 +0000 | |||
751 | +++ src/store/naive/simple_index_general.cpp 2012-04-16 15:38:09 +0000 | |||
752 | @@ -1667,13 +1667,13 @@ | |||
753 | 1667 | { | 1667 | { |
754 | 1668 | if (haveLower) | 1668 | if (haveLower) |
755 | 1669 | { | 1669 | { |
757 | 1670 | xs_double doubleValue = lowerKey->getDecimalValue(); | 1670 | xs_double const doubleValue( lowerKey->getDecimalValue() ); |
758 | 1671 | GET_FACTORY().createDouble(lowerAltKey, doubleValue); | 1671 | GET_FACTORY().createDouble(lowerAltKey, doubleValue); |
759 | 1672 | } | 1672 | } |
760 | 1673 | 1673 | ||
761 | 1674 | if (haveUpper) | 1674 | if (haveUpper) |
762 | 1675 | { | 1675 | { |
764 | 1676 | xs_double doubleValue = upperKey->getDecimalValue(); | 1676 | xs_double const doubleValue( upperKey->getDecimalValue() ); |
765 | 1677 | GET_FACTORY().createDouble(upperAltKey, doubleValue); | 1677 | GET_FACTORY().createDouble(upperAltKey, doubleValue); |
766 | 1678 | } | 1678 | } |
767 | 1679 | 1679 | ||
768 | @@ -1697,13 +1697,13 @@ | |||
769 | 1697 | { | 1697 | { |
770 | 1698 | if (haveLower) | 1698 | if (haveLower) |
771 | 1699 | { | 1699 | { |
773 | 1700 | xs_decimal decimalValue = lowerKey->getLongValue(); | 1700 | xs_decimal const decimalValue( lowerKey->getLongValue() ); |
774 | 1701 | GET_FACTORY().createDecimal(lowerAltKey, decimalValue); | 1701 | GET_FACTORY().createDecimal(lowerAltKey, decimalValue); |
775 | 1702 | } | 1702 | } |
776 | 1703 | 1703 | ||
777 | 1704 | if (haveUpper) | 1704 | if (haveUpper) |
778 | 1705 | { | 1705 | { |
780 | 1706 | xs_decimal decimalValue = upperKey->getLongValue(); | 1706 | xs_decimal const decimalValue( upperKey->getLongValue() ); |
781 | 1707 | GET_FACTORY().createDecimal(upperAltKey, decimalValue); | 1707 | GET_FACTORY().createDecimal(upperAltKey, decimalValue); |
782 | 1708 | } | 1708 | } |
783 | 1709 | 1709 | ||
784 | @@ -1714,13 +1714,13 @@ | |||
785 | 1714 | { | 1714 | { |
786 | 1715 | if (haveLower) | 1715 | if (haveLower) |
787 | 1716 | { | 1716 | { |
789 | 1717 | xs_double doubleValue = lowerKey->getLongValue(); | 1717 | xs_double doubleValue( lowerKey->getLongValue() ); |
790 | 1718 | GET_FACTORY().createDouble(lowerAltKey, doubleValue); | 1718 | GET_FACTORY().createDouble(lowerAltKey, doubleValue); |
791 | 1719 | } | 1719 | } |
792 | 1720 | 1720 | ||
793 | 1721 | if (haveUpper) | 1721 | if (haveUpper) |
794 | 1722 | { | 1722 | { |
796 | 1723 | xs_double doubleValue = upperKey->getLongValue(); | 1723 | xs_double const doubleValue( upperKey->getLongValue() ); |
797 | 1724 | GET_FACTORY().createDouble(upperAltKey, doubleValue); | 1724 | GET_FACTORY().createDouble(upperAltKey, doubleValue); |
798 | 1725 | } | 1725 | } |
799 | 1726 | 1726 | ||
800 | @@ -1772,14 +1772,14 @@ | |||
801 | 1772 | 1772 | ||
802 | 1773 | if (idx->theMaps[store::XS_DOUBLE]) | 1773 | if (idx->theMaps[store::XS_DOUBLE]) |
803 | 1774 | { | 1774 | { |
805 | 1775 | xs_double doubleValue = longItem->getLongValue(); | 1775 | xs_double const doubleValue( longItem->getLongValue() ); |
806 | 1776 | GET_FACTORY().createDouble(altKey, doubleValue); | 1776 | GET_FACTORY().createDouble(altKey, doubleValue); |
807 | 1777 | probeMap(store::XS_DOUBLE, altKey, altKey); | 1777 | probeMap(store::XS_DOUBLE, altKey, altKey); |
808 | 1778 | } | 1778 | } |
809 | 1779 | 1779 | ||
810 | 1780 | if (idx->theMaps[store::XS_DECIMAL]) | 1780 | if (idx->theMaps[store::XS_DECIMAL]) |
811 | 1781 | { | 1781 | { |
813 | 1782 | xs_decimal decimalValue = longItem->getLongValue(); | 1782 | xs_decimal const decimalValue( longItem->getLongValue() ); |
814 | 1783 | GET_FACTORY().createDecimal(altKey, decimalValue); | 1783 | GET_FACTORY().createDecimal(altKey, decimalValue); |
815 | 1784 | probeMap(store::XS_DECIMAL, altKey, altKey); | 1784 | probeMap(store::XS_DECIMAL, altKey, altKey); |
816 | 1785 | } | 1785 | } |
817 | @@ -1806,7 +1806,7 @@ | |||
818 | 1806 | 1806 | ||
819 | 1807 | if (idx->theMaps[store::XS_DOUBLE]) | 1807 | if (idx->theMaps[store::XS_DOUBLE]) |
820 | 1808 | { | 1808 | { |
822 | 1809 | xs_double doubleValue = decimalItem->getDecimalValue(); | 1809 | xs_double const doubleValue( decimalItem->getDecimalValue() ); |
823 | 1810 | GET_FACTORY().createDouble(altKey, doubleValue); | 1810 | GET_FACTORY().createDouble(altKey, doubleValue); |
824 | 1811 | probeMap(store::XS_DOUBLE, altKey, altKey); | 1811 | probeMap(store::XS_DOUBLE, altKey, altKey); |
825 | 1812 | } | 1812 | } |
826 | 1813 | 1813 | ||
827 | === modified file 'src/store/naive/simple_lazy_temp_seq.cpp' | |||
828 | --- src/store/naive/simple_lazy_temp_seq.cpp 2012-03-30 19:03:09 +0000 | |||
829 | +++ src/store/naive/simple_lazy_temp_seq.cpp 2012-04-16 15:38:09 +0000 | |||
830 | @@ -238,7 +238,7 @@ | |||
831 | 238 | xs_integer SimpleLazyTempSeq::getSize() const | 238 | xs_integer SimpleLazyTempSeq::getSize() const |
832 | 239 | { | 239 | { |
833 | 240 | ZORBA_ASSERT(false); | 240 | ZORBA_ASSERT(false); |
835 | 241 | return 0; | 241 | return xs_integer(0); |
836 | 242 | } | 242 | } |
837 | 243 | 243 | ||
838 | 244 | 244 | ||
839 | @@ -250,7 +250,7 @@ | |||
840 | 250 | ********************************************************************************/ | 250 | ********************************************************************************/ |
841 | 251 | store::Iterator_t SimpleLazyTempSeq::getIterator() const | 251 | store::Iterator_t SimpleLazyTempSeq::getIterator() const |
842 | 252 | { | 252 | { |
844 | 253 | return new SimpleLazyTempSeqIter(this, 1, std::numeric_limits<long>::max()); | 253 | return new SimpleLazyTempSeqIter(this, xs_integer(1), xs_integer(std::numeric_limits<long>::max())); |
845 | 254 | } | 254 | } |
846 | 255 | 255 | ||
847 | 256 | 256 | ||
848 | @@ -307,9 +307,9 @@ | |||
849 | 307 | 307 | ||
850 | 308 | bool SimpleLazyTempSeqIter::next(store::Item_t& result) | 308 | bool SimpleLazyTempSeqIter::next(store::Item_t& result) |
851 | 309 | { | 309 | { |
853 | 310 | if (theCurPos < theEndPos && theTempSeq->containsItem(theCurPos+1)) | 310 | if (theCurPos < theEndPos && theTempSeq->containsItem(xs_integer(theCurPos+1))) |
854 | 311 | { | 311 | { |
856 | 312 | theTempSeq->getItem(++theCurPos, result); | 312 | theTempSeq->getItem(xs_integer(++theCurPos), result); |
857 | 313 | return true; | 313 | return true; |
858 | 314 | } | 314 | } |
859 | 315 | else | 315 | else |
860 | 316 | 316 | ||
861 | === modified file 'src/store/naive/simple_temp_seq.cpp' | |||
862 | --- src/store/naive/simple_temp_seq.cpp 2012-03-30 19:03:09 +0000 | |||
863 | +++ src/store/naive/simple_temp_seq.cpp 2012-04-16 15:38:09 +0000 | |||
864 | @@ -133,7 +133,7 @@ | |||
865 | 133 | ********************************************************************************/ | 133 | ********************************************************************************/ |
866 | 134 | xs_integer SimpleTempSeq::getSize() const | 134 | xs_integer SimpleTempSeq::getSize() const |
867 | 135 | { | 135 | { |
869 | 136 | return theItems.size(); | 136 | return xs_integer( theItems.size() ); |
870 | 137 | } | 137 | } |
871 | 138 | 138 | ||
872 | 139 | 139 | ||
873 | 140 | 140 | ||
874 | === modified file 'src/zorbatypes/decimal.cpp' | |||
875 | --- src/zorbatypes/decimal.cpp 2012-04-12 02:08:10 +0000 | |||
876 | +++ src/zorbatypes/decimal.cpp 2012-04-16 15:38:09 +0000 | |||
877 | @@ -334,15 +334,15 @@ | |||
878 | 334 | 334 | ||
879 | 335 | TEMPLATE_DECL(T) | 335 | TEMPLATE_DECL(T) |
880 | 336 | Decimal Decimal::round( INTEGER_IMPL(T) const &precision ) const { | 336 | Decimal Decimal::round( INTEGER_IMPL(T) const &precision ) const { |
882 | 337 | return round( value_, precision.itod() ); | 337 | return round2( value_, precision.itod() ); |
883 | 338 | } | 338 | } |
884 | 339 | #ifndef ZORBA_WITH_BIG_INTEGER | 339 | #ifndef ZORBA_WITH_BIG_INTEGER |
885 | 340 | template Decimal Decimal::round( INTEGER_IMPL_LL const& ) const; | 340 | template Decimal Decimal::round( INTEGER_IMPL_LL const& ) const; |
886 | 341 | template Decimal Decimal::round( INTEGER_IMPL_ULL const& ) const; | 341 | template Decimal Decimal::round( INTEGER_IMPL_ULL const& ) const; |
887 | 342 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 342 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
888 | 343 | 343 | ||
891 | 344 | Decimal::value_type Decimal::round( value_type const &v, | 344 | Decimal::value_type Decimal::round2( value_type const &v, |
892 | 345 | value_type const &precision ) { | 345 | value_type const &precision ) { |
893 | 346 | value_type const exp( value_type(10).pow( precision ) ); | 346 | value_type const exp( value_type(10).pow( precision ) ); |
894 | 347 | value_type result( v * exp ); | 347 | value_type result( v * exp ); |
895 | 348 | result += MAPM::get0_5(); | 348 | result += MAPM::get0_5(); |
896 | @@ -353,22 +353,22 @@ | |||
897 | 353 | 353 | ||
898 | 354 | TEMPLATE_DECL(T) | 354 | TEMPLATE_DECL(T) |
899 | 355 | Decimal Decimal::roundHalfToEven( INTEGER_IMPL(T) const &precision ) const { | 355 | Decimal Decimal::roundHalfToEven( INTEGER_IMPL(T) const &precision ) const { |
901 | 356 | return roundHalfToEven( value_, precision.itod() ); | 356 | return roundHalfToEven2( value_, precision.itod() ); |
902 | 357 | } | 357 | } |
903 | 358 | #ifndef ZORBA_WITH_BIG_INTEGER | 358 | #ifndef ZORBA_WITH_BIG_INTEGER |
904 | 359 | template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_LL const& ) const; | 359 | template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_LL const& ) const; |
905 | 360 | template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_ULL const& ) const; | 360 | template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_ULL const& ) const; |
906 | 361 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 361 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
907 | 362 | 362 | ||
910 | 363 | Decimal::value_type Decimal::roundHalfToEven( value_type const &v, | 363 | Decimal::value_type Decimal::roundHalfToEven2( value_type const &v, |
911 | 364 | value_type const &precision ) { | 364 | value_type const &precision ) { |
912 | 365 | value_type const exp( value_type(10).pow( precision ) ); | 365 | value_type const exp( value_type(10).pow( precision ) ); |
913 | 366 | value_type result( v * exp ); | 366 | value_type result( v * exp ); |
914 | 367 | bool const aHalfVal = (result - MAPM::get0_5()) == result.floor(); | 367 | bool const aHalfVal = (result - MAPM::get0_5()) == result.floor(); |
915 | 368 | result += MAPM::get0_5(); | 368 | result += MAPM::get0_5(); |
916 | 369 | result = result.floor(); | 369 | result = result.floor(); |
917 | 370 | if ( aHalfVal && result.is_odd() ) | 370 | if ( aHalfVal && result.is_odd() ) |
919 | 371 | result -= 1; | 371 | --result; |
920 | 372 | result /= exp; | 372 | result /= exp; |
921 | 373 | return result; | 373 | return result; |
922 | 374 | } | 374 | } |
923 | 375 | 375 | ||
924 | === modified file 'src/zorbatypes/decimal.h' | |||
925 | --- src/zorbatypes/decimal.h 2012-03-30 19:03:09 +0000 | |||
926 | +++ src/zorbatypes/decimal.h 2012-04-16 15:38:09 +0000 | |||
927 | @@ -21,6 +21,7 @@ | |||
928 | 21 | #include <zorba/config.h> | 21 | #include <zorba/config.h> |
929 | 22 | 22 | ||
930 | 23 | #include "common/common.h" | 23 | #include "common/common.h" |
931 | 24 | #include "util/stl_util.h" | ||
932 | 24 | #include "zorbaserialization/archiver.h" | 25 | #include "zorbaserialization/archiver.h" |
933 | 25 | #include "zorbaserialization/class_serializer.h" | 26 | #include "zorbaserialization/class_serializer.h" |
934 | 26 | 27 | ||
935 | @@ -30,11 +31,11 @@ | |||
936 | 30 | #include "zstring.h" | 31 | #include "zstring.h" |
937 | 31 | 32 | ||
938 | 32 | #ifdef ZORBA_WITH_BIG_INTEGER | 33 | #ifdef ZORBA_WITH_BIG_INTEGER |
941 | 33 | # define TEMPLATE_DECL(T) /* nothing */ | 34 | # define TEMPLATE_DECL(I) /* nothing */ |
942 | 34 | # define INTEGER_IMPL(T) IntegerImpl | 35 | # define INTEGER_IMPL(I) IntegerImpl |
943 | 35 | #else | 36 | #else |
946 | 36 | # define TEMPLATE_DECL(T) template<typename T> | 37 | # define TEMPLATE_DECL(I) template<typename I> |
947 | 37 | # define INTEGER_IMPL(T) IntegerImpl<T> | 38 | # define INTEGER_IMPL(I) IntegerImpl<I> |
948 | 38 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 39 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
949 | 39 | 40 | ||
950 | 40 | namespace zorba { | 41 | namespace zorba { |
951 | @@ -46,23 +47,22 @@ | |||
952 | 46 | 47 | ||
953 | 47 | ////////// constructors ///////////////////////////////////////////////////// | 48 | ////////// constructors ///////////////////////////////////////////////////// |
954 | 48 | 49 | ||
969 | 49 | Decimal( char c ); | 50 | explicit Decimal( char c ); |
970 | 50 | Decimal( signed char c ); | 51 | explicit Decimal( signed char c ); |
971 | 51 | Decimal( short n ); | 52 | explicit Decimal( short n ); |
972 | 52 | Decimal( int n = 0 ); | 53 | explicit Decimal( int n = 0 ); |
973 | 53 | Decimal( long n ); | 54 | explicit Decimal( long n ); |
974 | 54 | Decimal( long long n ); | 55 | explicit Decimal( long long n ); |
975 | 55 | Decimal( unsigned char c ); | 56 | explicit Decimal( unsigned char c ); |
976 | 56 | Decimal( unsigned short n ); | 57 | explicit Decimal( unsigned short n ); |
977 | 57 | Decimal( unsigned int n ); | 58 | explicit Decimal( unsigned int n ); |
978 | 58 | Decimal( unsigned long n ); | 59 | explicit Decimal( unsigned long n ); |
979 | 59 | Decimal( unsigned long long n ); | 60 | explicit Decimal( unsigned long long n ); |
980 | 60 | Decimal( float n ); | 61 | explicit Decimal( float n ); |
981 | 61 | Decimal( double n ); | 62 | explicit Decimal( double n ); |
968 | 62 | Decimal( Decimal const &d ); | ||
982 | 63 | 63 | ||
985 | 64 | TEMPLATE_DECL(T) | 64 | TEMPLATE_DECL(I) |
986 | 65 | Decimal( INTEGER_IMPL(T) const &i ); | 65 | explicit Decimal( INTEGER_IMPL(I) const &i ); |
987 | 66 | 66 | ||
988 | 67 | /** | 67 | /** |
989 | 68 | * Constructs a %Decimal from a C string. | 68 | * Constructs a %Decimal from a C string. |
990 | @@ -71,7 +71,7 @@ | |||
991 | 71 | * whitespace is ignored. | 71 | * whitespace is ignored. |
992 | 72 | * @throw std::invalid_argument if \a s does not contain a valid decimal. | 72 | * @throw std::invalid_argument if \a s does not contain a valid decimal. |
993 | 73 | */ | 73 | */ |
995 | 74 | Decimal( char const *s ); | 74 | explicit Decimal( char const *s ); |
996 | 75 | 75 | ||
997 | 76 | /** | 76 | /** |
998 | 77 | * Constructs a %Decimal from a Double. | 77 | * Constructs a %Decimal from a Double. |
999 | @@ -79,7 +79,7 @@ | |||
1000 | 79 | * @param n The Double. | 79 | * @param n The Double. |
1001 | 80 | * @throw std::invalid_argument if \a n is not finite. | 80 | * @throw std::invalid_argument if \a n is not finite. |
1002 | 81 | */ | 81 | */ |
1004 | 82 | Decimal( Double const &n ); | 82 | explicit Decimal( Double const &n ); |
1005 | 83 | 83 | ||
1006 | 84 | /** | 84 | /** |
1007 | 85 | * Constructs a %Decimal from a Float. | 85 | * Constructs a %Decimal from a Float. |
1008 | @@ -87,30 +87,46 @@ | |||
1009 | 87 | * @param n The Float. | 87 | * @param n The Float. |
1010 | 88 | * @throw std::invalid_argument if \a n is not finite. | 88 | * @throw std::invalid_argument if \a n is not finite. |
1011 | 89 | */ | 89 | */ |
1013 | 90 | Decimal( Float const &n ); | 90 | explicit Decimal( Float const &n ); |
1014 | 91 | |||
1015 | 92 | /** | ||
1016 | 93 | * Conventional copy constructor. | ||
1017 | 94 | * | ||
1018 | 95 | * @param d The %Decimal to copy from. | ||
1019 | 96 | */ | ||
1020 | 97 | Decimal( Decimal const &d ); | ||
1021 | 91 | 98 | ||
1022 | 92 | ////////// assignment operators ///////////////////////////////////////////// | 99 | ////////// assignment operators ///////////////////////////////////////////// |
1023 | 93 | 100 | ||
1029 | 94 | Decimal& operator=( char c ); | 101 | /** |
1030 | 95 | Decimal& operator=( signed char c ); | 102 | * Conventional assignment operator. |
1031 | 96 | Decimal& operator=( short n ); | 103 | * |
1032 | 97 | Decimal& operator=( int n ); | 104 | * @param d The %Decimal to assign from. |
1033 | 98 | Decimal& operator=( long n ); | 105 | * @return Returns \c *this. |
1034 | 106 | */ | ||
1035 | 107 | Decimal& operator=( Decimal const &d ); | ||
1036 | 108 | |||
1037 | 109 | /** | ||
1038 | 110 | * For every built-in arithmetic type A, assign to this %Decimal. | ||
1039 | 111 | * | ||
1040 | 112 | * @tparam A The built-in arithmetic type. | ||
1041 | 113 | * @param n The arithmetic value to assign. | ||
1042 | 114 | * @return Returns \c *this. | ||
1043 | 115 | */ | ||
1044 | 116 | template<typename A> | ||
1045 | 117 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,Decimal&>::type | ||
1046 | 118 | operator=( A n ); | ||
1047 | 119 | |||
1048 | 120 | // These arithmetic types have to be special-cased. | ||
1049 | 99 | Decimal& operator=( long long n ); | 121 | Decimal& operator=( long long n ); |
1050 | 100 | Decimal& operator=( unsigned char c ); | ||
1051 | 101 | Decimal& operator=( unsigned short n ); | ||
1052 | 102 | Decimal& operator=( unsigned int n ); | ||
1053 | 103 | Decimal& operator=( unsigned long n ); | ||
1054 | 104 | Decimal& operator=( unsigned long long n ); | 122 | Decimal& operator=( unsigned long long n ); |
1057 | 105 | Decimal& operator=( float n ); | 123 | |
1056 | 106 | Decimal& operator=( double n ); | ||
1058 | 107 | Decimal& operator=( char const *s ); | 124 | Decimal& operator=( char const *s ); |
1059 | 108 | Decimal& operator=( Decimal const &d ); | ||
1060 | 109 | Decimal& operator=( Double const &d ); | 125 | Decimal& operator=( Double const &d ); |
1061 | 110 | Decimal& operator=( Float const &f ); | 126 | Decimal& operator=( Float const &f ); |
1062 | 111 | 127 | ||
1065 | 112 | TEMPLATE_DECL(T) | 128 | TEMPLATE_DECL(I) |
1066 | 113 | Decimal& operator=( INTEGER_IMPL(T) const &i ); | 129 | Decimal& operator=( INTEGER_IMPL(I) const &i ); |
1067 | 114 | 130 | ||
1068 | 115 | ////////// arithmetic operators ///////////////////////////////////////////// | 131 | ////////// arithmetic operators ///////////////////////////////////////////// |
1069 | 116 | 132 | ||
1070 | @@ -121,10 +137,11 @@ | |||
1071 | 121 | friend Decimal operator%( Decimal const&, Decimal const& ); | 137 | friend Decimal operator%( Decimal const&, Decimal const& ); |
1072 | 122 | 138 | ||
1073 | 123 | #define ZORBA_DECIMAL_OP(OP) \ | 139 | #define ZORBA_DECIMAL_OP(OP) \ |
1078 | 124 | TEMPLATE_DECL(T) \ | 140 | TEMPLATE_DECL(I) \ |
1079 | 125 | friend Decimal operator OP( Decimal const&, INTEGER_IMPL(T) const& ); \ | 141 | friend Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \ |
1080 | 126 | TEMPLATE_DECL(T) \ | 142 | \ |
1081 | 127 | friend Decimal operator OP( INTEGER_IMPL(T) const&, Decimal const& ) | 143 | TEMPLATE_DECL(I) \ |
1082 | 144 | friend Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& ) | ||
1083 | 128 | 145 | ||
1084 | 129 | ZORBA_DECIMAL_OP(+); | 146 | ZORBA_DECIMAL_OP(+); |
1085 | 130 | ZORBA_DECIMAL_OP(-); | 147 | ZORBA_DECIMAL_OP(-); |
1086 | @@ -140,7 +157,7 @@ | |||
1087 | 140 | Decimal& operator%=( Decimal const& ); | 157 | Decimal& operator%=( Decimal const& ); |
1088 | 141 | 158 | ||
1089 | 142 | #define ZORBA_DECIMAL_OP(OP) \ | 159 | #define ZORBA_DECIMAL_OP(OP) \ |
1091 | 143 | TEMPLATE_DECL(T) Decimal& operator OP( INTEGER_IMPL(T) const& ) | 160 | TEMPLATE_DECL(I) Decimal& operator OP( INTEGER_IMPL(I) const& ) |
1092 | 144 | 161 | ||
1093 | 145 | ZORBA_DECIMAL_OP(+=); | 162 | ZORBA_DECIMAL_OP(+=); |
1094 | 146 | ZORBA_DECIMAL_OP(-=); | 163 | ZORBA_DECIMAL_OP(-=); |
1095 | @@ -155,10 +172,10 @@ | |||
1096 | 155 | 172 | ||
1097 | 156 | #define ZORBA_DECIMAL_OP(OP) \ | 173 | #define ZORBA_DECIMAL_OP(OP) \ |
1098 | 157 | friend bool operator OP( Decimal const&, Decimal const& ); \ | 174 | friend bool operator OP( Decimal const&, Decimal const& ); \ |
1103 | 158 | TEMPLATE_DECL(T) \ | 175 | TEMPLATE_DECL(I) \ |
1104 | 159 | friend bool operator OP( Decimal const&, INTEGER_IMPL(T) const& ); \ | 176 | friend bool operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \ |
1105 | 160 | TEMPLATE_DECL(T) \ | 177 | TEMPLATE_DECL(I) \ |
1106 | 161 | friend bool operator OP( INTEGER_IMPL(T) const&, Decimal const& ) | 178 | friend bool operator OP( INTEGER_IMPL(I) const&, Decimal const& ) |
1107 | 162 | 179 | ||
1108 | 163 | ZORBA_DECIMAL_OP(==); | 180 | ZORBA_DECIMAL_OP(==); |
1109 | 164 | ZORBA_DECIMAL_OP(!=); | 181 | ZORBA_DECIMAL_OP(!=); |
1110 | @@ -176,11 +193,11 @@ | |||
1111 | 176 | Decimal floor() const; | 193 | Decimal floor() const; |
1112 | 177 | Decimal round() const; | 194 | Decimal round() const; |
1113 | 178 | 195 | ||
1116 | 179 | TEMPLATE_DECL(T) | 196 | TEMPLATE_DECL(I) |
1117 | 180 | Decimal round( INTEGER_IMPL(T) const &precision ) const; | 197 | Decimal round( INTEGER_IMPL(I) const &precision ) const; |
1118 | 181 | 198 | ||
1121 | 182 | TEMPLATE_DECL(T) | 199 | TEMPLATE_DECL(I) |
1122 | 183 | Decimal roundHalfToEven( INTEGER_IMPL(T) const &precision ) const; | 200 | Decimal roundHalfToEven( INTEGER_IMPL(I) const &precision ) const; |
1123 | 184 | 201 | ||
1124 | 185 | Decimal sqrt() const; | 202 | Decimal sqrt() const; |
1125 | 186 | 203 | ||
1126 | @@ -223,16 +240,16 @@ | |||
1127 | 223 | 240 | ||
1128 | 224 | static void reduce( char *s ); | 241 | static void reduce( char *s ); |
1129 | 225 | 242 | ||
1131 | 226 | static value_type round( value_type const &v, value_type const &precision ); | 243 | static value_type round2( value_type const &v, value_type const &precision ); |
1132 | 227 | 244 | ||
1135 | 228 | static value_type roundHalfToEven( value_type const &v, | 245 | static value_type roundHalfToEven2( value_type const &v, |
1136 | 229 | value_type const &precision ); | 246 | value_type const &precision ); |
1137 | 230 | 247 | ||
1138 | 231 | static zstring toString( value_type const&, | 248 | static zstring toString( value_type const&, |
1139 | 232 | int precision = ZORBA_FLOAT_POINT_PRECISION ); | 249 | int precision = ZORBA_FLOAT_POINT_PRECISION ); |
1140 | 233 | 250 | ||
1143 | 234 | TEMPLATE_DECL(T) friend class IntegerImpl; | 251 | TEMPLATE_DECL(I) friend class IntegerImpl; |
1144 | 235 | template<typename T> friend class FloatImpl; | 252 | template<typename F> friend class FloatImpl; |
1145 | 236 | 253 | ||
1146 | 237 | friend xs_long to_xs_long( Decimal const& ); | 254 | friend xs_long to_xs_long( Decimal const& ); |
1147 | 238 | }; | 255 | }; |
1148 | @@ -274,112 +291,49 @@ | |||
1149 | 274 | 291 | ||
1150 | 275 | ////////// assignment operators /////////////////////////////////////////////// | 292 | ////////// assignment operators /////////////////////////////////////////////// |
1151 | 276 | 293 | ||
1152 | 277 | inline Decimal& Decimal::operator=( char c ) { | ||
1153 | 278 | value_ = static_cast<long>( c ); | ||
1154 | 279 | return *this; | ||
1155 | 280 | } | ||
1156 | 281 | |||
1157 | 282 | inline Decimal& Decimal::operator=( signed char c ) { | ||
1158 | 283 | value_ = static_cast<long>( c ); | ||
1159 | 284 | return *this; | ||
1160 | 285 | } | ||
1161 | 286 | |||
1162 | 287 | inline Decimal& Decimal::operator=( short n ) { | ||
1163 | 288 | value_ = static_cast<long>( n ); | ||
1164 | 289 | return *this; | ||
1165 | 290 | } | ||
1166 | 291 | |||
1167 | 292 | inline Decimal& Decimal::operator=( int n ) { | ||
1168 | 293 | value_ = static_cast<long>( n ); | ||
1169 | 294 | return *this; | ||
1170 | 295 | } | ||
1171 | 296 | |||
1172 | 297 | inline Decimal& Decimal::operator=( long n ) { | ||
1173 | 298 | value_ = n; | ||
1174 | 299 | return *this; | ||
1175 | 300 | } | ||
1176 | 301 | |||
1177 | 302 | inline Decimal& Decimal::operator=( unsigned char c ) { | ||
1178 | 303 | value_ = static_cast<long>( c ); | ||
1179 | 304 | return *this; | ||
1180 | 305 | } | ||
1181 | 306 | |||
1182 | 307 | inline Decimal& Decimal::operator=( unsigned short n ) { | ||
1183 | 308 | value_ = static_cast<long>( n ); | ||
1184 | 309 | return *this; | ||
1185 | 310 | } | ||
1186 | 311 | |||
1187 | 312 | inline Decimal& Decimal::operator=( unsigned int n ) { | ||
1188 | 313 | value_ = static_cast<long>( n ); | ||
1189 | 314 | return *this; | ||
1190 | 315 | } | ||
1191 | 316 | |||
1192 | 317 | inline Decimal& Decimal::operator=( float n ) { | ||
1193 | 318 | value_ = n; | ||
1194 | 319 | return *this; | ||
1195 | 320 | } | ||
1196 | 321 | |||
1197 | 322 | inline Decimal& Decimal::operator=( double n ) { | ||
1198 | 323 | value_ = n; | ||
1199 | 324 | return *this; | ||
1200 | 325 | } | ||
1201 | 326 | |||
1202 | 327 | inline Decimal& Decimal::operator=( char const *s ) { | ||
1203 | 328 | parse( s, &value_ ); | ||
1204 | 329 | return *this; | ||
1205 | 330 | } | ||
1206 | 331 | |||
1207 | 332 | inline Decimal& Decimal::operator=( Decimal const &d ) { | 294 | inline Decimal& Decimal::operator=( Decimal const &d ) { |
1208 | 333 | value_ = d.value_; | 295 | value_ = d.value_; |
1209 | 334 | return *this; | 296 | return *this; |
1210 | 335 | } | 297 | } |
1211 | 336 | 298 | ||
1212 | 299 | template<typename A> inline | ||
1213 | 300 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,Decimal&>::type | ||
1214 | 301 | Decimal::operator=( A n ) { | ||
1215 | 302 | value_ = static_cast<long>( n ); | ||
1216 | 303 | return *this; | ||
1217 | 304 | } | ||
1218 | 305 | |||
1219 | 306 | inline Decimal& Decimal::operator=( char const *s ) { | ||
1220 | 307 | parse( s, &value_ ); | ||
1221 | 308 | return *this; | ||
1222 | 309 | } | ||
1223 | 310 | |||
1224 | 337 | ////////// arithmetic operators /////////////////////////////////////////////// | 311 | ////////// arithmetic operators /////////////////////////////////////////////// |
1225 | 338 | 312 | ||
1270 | 339 | inline Decimal operator+( Decimal const &d1, Decimal const &d2 ) { | 313 | #define ZORBA_DECIMAL_OP(OP) \ |
1271 | 340 | return d1.value_ + d2.value_; | 314 | inline Decimal operator OP( Decimal const &d1, Decimal const &d2 ) { \ |
1272 | 341 | } | 315 | return d1.value_ OP d2.value_; \ |
1273 | 342 | 316 | } | |
1274 | 343 | inline Decimal operator-( Decimal const &d1, Decimal const &d2 ) { | 317 | |
1275 | 344 | return d1.value_ - d2.value_; | 318 | ZORBA_DECIMAL_OP(+) |
1276 | 345 | } | 319 | ZORBA_DECIMAL_OP(-) |
1277 | 346 | 320 | ZORBA_DECIMAL_OP(*) | |
1278 | 347 | inline Decimal operator*( Decimal const &d1, Decimal const &d2 ) { | 321 | ZORBA_DECIMAL_OP(/) |
1279 | 348 | return d1.value_ * d2.value_; | 322 | ZORBA_DECIMAL_OP(%) |
1280 | 349 | } | 323 | #undef ZORBA_DECIMAL_OP |
1281 | 350 | 324 | ||
1282 | 351 | inline Decimal operator/( Decimal const &d1, Decimal const &d2 ) { | 325 | #define ZORBA_DECIMAL_OP(OP) \ |
1283 | 352 | return d1.value_ / d2.value_; | 326 | inline Decimal& Decimal::operator OP( Decimal const &d ) { \ |
1284 | 353 | } | 327 | value_ OP d.value_; \ |
1285 | 354 | 328 | return *this; \ | |
1286 | 355 | inline Decimal operator%( Decimal const &d1, Decimal const &d2 ) { | 329 | } |
1287 | 356 | return d1.value_ % d2.value_; | 330 | |
1288 | 357 | } | 331 | ZORBA_DECIMAL_OP(+=) |
1289 | 358 | 332 | ZORBA_DECIMAL_OP(-=) | |
1290 | 359 | inline Decimal& Decimal::operator+=( Decimal const &d ) { | 333 | ZORBA_DECIMAL_OP(*=) |
1291 | 360 | value_ += d.value_; | 334 | ZORBA_DECIMAL_OP(/=) |
1292 | 361 | return *this; | 335 | ZORBA_DECIMAL_OP(%=) |
1293 | 362 | } | 336 | #undef ZORBA_DECIMAL_OP |
1250 | 363 | |||
1251 | 364 | inline Decimal& Decimal::operator-=( Decimal const &d ) { | ||
1252 | 365 | value_ -= d.value_; | ||
1253 | 366 | return *this; | ||
1254 | 367 | } | ||
1255 | 368 | |||
1256 | 369 | inline Decimal& Decimal::operator*=( Decimal const &d ) { | ||
1257 | 370 | value_ *= d.value_; | ||
1258 | 371 | return *this; | ||
1259 | 372 | } | ||
1260 | 373 | |||
1261 | 374 | inline Decimal& Decimal::operator/=( Decimal const &d ) { | ||
1262 | 375 | value_ /= d.value_; | ||
1263 | 376 | return *this; | ||
1264 | 377 | } | ||
1265 | 378 | |||
1266 | 379 | inline Decimal& Decimal::operator%=( Decimal const &d ) { | ||
1267 | 380 | value_ %= d.value_; | ||
1268 | 381 | return *this; | ||
1269 | 382 | } | ||
1294 | 383 | 337 | ||
1295 | 384 | inline Decimal Decimal::operator-() const { | 338 | inline Decimal Decimal::operator-() const { |
1296 | 385 | return -value_; | 339 | return -value_; |
1297 | 386 | 340 | ||
1298 | === modified file 'src/zorbatypes/floatimpl.cpp' | |||
1299 | --- src/zorbatypes/floatimpl.cpp 2012-04-12 02:08:10 +0000 | |||
1300 | +++ src/zorbatypes/floatimpl.cpp 2012-04-16 15:38:09 +0000 | |||
1301 | @@ -169,22 +169,54 @@ | |||
1302 | 169 | template FloatImpl<double>::FloatImpl( INTEGER_IMPL_ULL const& ); | 169 | template FloatImpl<double>::FloatImpl( INTEGER_IMPL_ULL const& ); |
1303 | 170 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 170 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
1304 | 171 | 171 | ||
1305 | 172 | ////////// assignment operators /////////////////////////////////////////////// | ||
1306 | 173 | |||
1307 | 174 | template<typename FloatType> | ||
1308 | 175 | FloatImpl<FloatType>& FloatImpl<FloatType>::operator=( Decimal const &d ) { | ||
1309 | 176 | zstring const temp( d.toString() ); | ||
1310 | 177 | parse( temp.c_str() ); | ||
1311 | 178 | return *this; | ||
1312 | 179 | } | ||
1313 | 180 | |||
1314 | 181 | template<typename FloatType> | ||
1315 | 182 | TEMPLATE_DECL(IntType) | ||
1316 | 183 | FloatImpl<FloatType>& | ||
1317 | 184 | FloatImpl<FloatType>::operator=( INTEGER_IMPL(IntType) const &i ) { | ||
1318 | 185 | zstring const temp( i.toString() ); | ||
1319 | 186 | parse( temp.c_str() ); | ||
1320 | 187 | return *this; | ||
1321 | 188 | } | ||
1322 | 189 | |||
1323 | 190 | #ifndef ZORBA_WITH_BIG_INTEGER | ||
1324 | 191 | template | ||
1325 | 192 | FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_LL const& ); | ||
1326 | 193 | |||
1327 | 194 | template | ||
1328 | 195 | FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_ULL const& ); | ||
1329 | 196 | |||
1330 | 197 | template | ||
1331 | 198 | FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_LL const& ); | ||
1332 | 199 | |||
1333 | 200 | template | ||
1334 | 201 | FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_ULL const& ); | ||
1335 | 202 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
1336 | 203 | |||
1337 | 172 | ////////// math functions ///////////////////////////////////////////////////// | 204 | ////////// math functions ///////////////////////////////////////////////////// |
1338 | 173 | 205 | ||
1339 | 174 | template<typename FloatType> | 206 | template<typename FloatType> |
1340 | 175 | FloatImpl<FloatType> FloatImpl<FloatType>::acos() const { | 207 | FloatImpl<FloatType> FloatImpl<FloatType>::acos() const { |
1341 | 176 | if ( *this < neg_one() || *this > one() ) | 208 | if ( *this < neg_one() || *this > one() ) |
1342 | 177 | return nan(); | 209 | return nan(); |
1346 | 178 | if ( !isNegZero() ) | 210 | return FloatImpl<FloatType>( |
1347 | 179 | return std::acos( value_ ); | 211 | isNegZero() ? -std::acos( value_ ): std::acos( value_ ) |
1348 | 180 | return -std::acos( value_ ); | 212 | ); |
1349 | 181 | } | 213 | } |
1350 | 182 | 214 | ||
1351 | 183 | template<typename FloatType> | 215 | template<typename FloatType> |
1352 | 184 | FloatImpl<FloatType> FloatImpl<FloatType>::asin() const { | 216 | FloatImpl<FloatType> FloatImpl<FloatType>::asin() const { |
1353 | 185 | if ( *this < neg_one() || *this > one() ) | 217 | if ( *this < neg_one() || *this > one() ) |
1354 | 186 | return nan(); | 218 | return nan(); |
1356 | 187 | return std::asin( value_ ); | 219 | return FloatImpl<FloatType>( std::asin( value_ ) ); |
1357 | 188 | } | 220 | } |
1358 | 189 | 221 | ||
1359 | 190 | template<typename FloatType> | 222 | template<typename FloatType> |
1360 | @@ -220,8 +252,13 @@ | |||
1361 | 220 | FloatImpl<FloatType> FloatImpl<FloatType>::round( Integer const &precision ) const { | 252 | FloatImpl<FloatType> FloatImpl<FloatType>::round( Integer const &precision ) const { |
1362 | 221 | FloatImpl result; | 253 | FloatImpl result; |
1363 | 222 | if ( isFinite() && !isZero() ) { | 254 | if ( isFinite() && !isZero() ) { |
1366 | 223 | MAPM m = Decimal::round( value_, precision.itod() ); | 255 | MAPM m( |
1367 | 224 | if ( value_ < 0 && m == 0 ) | 256 | Decimal::round2( |
1368 | 257 | Decimal::value_type( value_ ), | ||
1369 | 258 | Decimal::value_type( precision.itod() ) | ||
1370 | 259 | ) | ||
1371 | 260 | ); | ||
1372 | 261 | if ( value_ < 0 && m.sign() == 0 ) | ||
1373 | 225 | result = neg_zero(); | 262 | result = neg_zero(); |
1374 | 226 | else { | 263 | else { |
1375 | 227 | char buf[200]; | 264 | char buf[200]; |
1376 | @@ -234,12 +271,17 @@ | |||
1377 | 234 | return result; | 271 | return result; |
1378 | 235 | } | 272 | } |
1379 | 236 | 273 | ||
1382 | 237 | template<typename FloatType> | 274 | template<typename FloatType> FloatImpl<FloatType> |
1383 | 238 | FloatImpl<FloatType> FloatImpl<FloatType>::roundHalfToEven( Integer const &precision) const { | 275 | FloatImpl<FloatType>::roundHalfToEven( Integer const &precision) const { |
1384 | 239 | FloatImpl result; | 276 | FloatImpl result; |
1385 | 240 | if ( isFinite() && !isZero() ) { | 277 | if ( isFinite() && !isZero() ) { |
1388 | 241 | MAPM m = Decimal::roundHalfToEven( value_, precision.itod() ); | 278 | MAPM m( |
1389 | 242 | if ( value_ < 0 && m == 0 ) | 279 | Decimal::roundHalfToEven2( |
1390 | 280 | Decimal::value_type( value_ ), | ||
1391 | 281 | Decimal::value_type( precision.itod() ) | ||
1392 | 282 | ) | ||
1393 | 283 | ); | ||
1394 | 284 | if ( value_ < 0 && m.sign() == 0 ) | ||
1395 | 243 | result = neg_zero(); | 285 | result = neg_zero(); |
1396 | 244 | else { | 286 | else { |
1397 | 245 | char buf[200]; | 287 | char buf[200]; |
1398 | @@ -353,8 +395,8 @@ | |||
1399 | 353 | #if 1 | 395 | #if 1 |
1400 | 354 | // This is the "spec" implementation, i.e., it is an exact application of | 396 | // This is the "spec" implementation, i.e., it is an exact application of |
1401 | 355 | // the spec in http://www.w3.org/TR/xpath-functions/#casting | 397 | // the spec in http://www.w3.org/TR/xpath-functions/#casting |
1404 | 356 | MAPM decimal_mapm = value_; | 398 | MAPM decimal_mapm( value_ ); |
1405 | 357 | decimal_mapm = decimal_mapm.round(precision_); | 399 | decimal_mapm = decimal_mapm.round( precision_ ); |
1406 | 358 | return Decimal::toString(decimal_mapm, max_precision()); | 400 | return Decimal::toString(decimal_mapm, max_precision()); |
1407 | 359 | #else | 401 | #else |
1408 | 360 | std::stringstream stream; | 402 | std::stringstream stream; |
1409 | 361 | 403 | ||
1410 | === modified file 'src/zorbatypes/floatimpl.h' | |||
1411 | --- src/zorbatypes/floatimpl.h 2012-03-30 19:03:09 +0000 | |||
1412 | +++ src/zorbatypes/floatimpl.h 2012-04-16 15:38:09 +0000 | |||
1413 | @@ -30,11 +30,11 @@ | |||
1414 | 30 | #include "zorbatypes_decl.h" | 30 | #include "zorbatypes_decl.h" |
1415 | 31 | 31 | ||
1416 | 32 | #ifdef ZORBA_WITH_BIG_INTEGER | 32 | #ifdef ZORBA_WITH_BIG_INTEGER |
1419 | 33 | # define TEMPLATE_DECL(T) /* nothing */ | 33 | # define TEMPLATE_DECL(I) /* nothing */ |
1420 | 34 | # define INTEGER_IMPL(T) IntegerImpl | 34 | # define INTEGER_IMPL(I) IntegerImpl |
1421 | 35 | #else | 35 | #else |
1424 | 36 | # define TEMPLATE_DECL(T) template<typename T> | 36 | # define TEMPLATE_DECL(I) template<typename I> |
1425 | 37 | # define INTEGER_IMPL(T) IntegerImpl<T> | 37 | # define INTEGER_IMPL(I) IntegerImpl<I> |
1426 | 38 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 38 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
1427 | 39 | 39 | ||
1428 | 40 | namespace zorba { | 40 | namespace zorba { |
1429 | @@ -56,23 +56,23 @@ | |||
1430 | 56 | 56 | ||
1431 | 57 | ////////// constructors ///////////////////////////////////////////////////// | 57 | ////////// constructors ///////////////////////////////////////////////////// |
1432 | 58 | 58 | ||
1447 | 59 | FloatImpl( char ); | 59 | explicit FloatImpl( char ); |
1448 | 60 | FloatImpl( signed char c ); | 60 | explicit FloatImpl( signed char c ); |
1449 | 61 | FloatImpl( short n ); | 61 | explicit FloatImpl( short n ); |
1450 | 62 | FloatImpl( int n = 0 ); | 62 | explicit FloatImpl( int n = 0 ); |
1451 | 63 | FloatImpl( long n ); | 63 | explicit FloatImpl( long n ); |
1452 | 64 | FloatImpl( long long n ); | 64 | explicit FloatImpl( long long n ); |
1453 | 65 | FloatImpl( unsigned char c ); | 65 | explicit FloatImpl( unsigned char c ); |
1454 | 66 | FloatImpl( unsigned short n ); | 66 | explicit FloatImpl( unsigned short n ); |
1455 | 67 | FloatImpl( unsigned int n ); | 67 | explicit FloatImpl( unsigned int n ); |
1456 | 68 | FloatImpl( unsigned long n ); | 68 | explicit FloatImpl( unsigned long n ); |
1457 | 69 | FloatImpl( unsigned long long n ); | 69 | explicit FloatImpl( unsigned long long n ); |
1458 | 70 | FloatImpl( float n ); | 70 | explicit FloatImpl( float n ); |
1459 | 71 | FloatImpl( double n ); | 71 | explicit FloatImpl( double n ); |
1460 | 72 | FloatImpl( Decimal const &d ); | 72 | explicit FloatImpl( Decimal const &d ); |
1461 | 73 | 73 | ||
1464 | 74 | TEMPLATE_DECL(T) | 74 | TEMPLATE_DECL(IntType) |
1465 | 75 | FloatImpl( INTEGER_IMPL(T) const &i ); | 75 | explicit FloatImpl( INTEGER_IMPL(IntType) const &i ); |
1466 | 76 | 76 | ||
1467 | 77 | /** | 77 | /** |
1468 | 78 | * Constructs a %FloatImpl from a C string. | 78 | * Constructs a %FloatImpl from a C string. |
1469 | @@ -84,62 +84,74 @@ | |||
1470 | 84 | * @throw std::range_error if \a s contains a number that either underflows | 84 | * @throw std::range_error if \a s contains a number that either underflows |
1471 | 85 | * or overflows the smallest or largest representable floating point number. | 85 | * or overflows the smallest or largest representable floating point number. |
1472 | 86 | */ | 86 | */ |
1474 | 87 | FloatImpl( char const *s ); | 87 | explicit FloatImpl( char const *s ); |
1475 | 88 | 88 | ||
1476 | 89 | /** | ||
1477 | 90 | * Constructs from another %FloatImpl even if its \c FloatType is different. | ||
1478 | 91 | * (This subsumes the conventional copy constructor.) | ||
1479 | 92 | * | ||
1480 | 93 | * @tparam FloatType2 the floating-point type of \a f. | ||
1481 | 94 | * @param f The %FloatImpl to copy from. | ||
1482 | 95 | */ | ||
1483 | 89 | template<typename FloatType2> | 96 | template<typename FloatType2> |
1484 | 90 | FloatImpl( FloatImpl<FloatType2> const &f ); | 97 | FloatImpl( FloatImpl<FloatType2> const &f ); |
1485 | 91 | 98 | ||
1486 | 92 | ////////// assignment operators ///////////////////////////////////////////// | 99 | ////////// assignment operators ///////////////////////////////////////////// |
1487 | 93 | 100 | ||
1488 | 101 | /** | ||
1489 | 102 | * Assign from a %FloatImpl even if its \c FloatType is different. | ||
1490 | 103 | * (This subsumes the conventional assignment operator.) | ||
1491 | 104 | * | ||
1492 | 105 | * @tparam FloatType2 the floating-point type of \a f. | ||
1493 | 106 | * @param f The %FloatImpl to assign from. | ||
1494 | 107 | * @return Returns \c *this. | ||
1495 | 108 | */ | ||
1496 | 109 | template<typename FloatType2> | ||
1497 | 110 | FloatImpl& operator=( FloatImpl<FloatType2> const &f ); | ||
1498 | 111 | |||
1499 | 112 | /** | ||
1500 | 113 | * For every built-in arithmetic type A, assign to this %FloatImpl. | ||
1501 | 114 | * | ||
1502 | 115 | * @tparam A The built-in arithmetic type. | ||
1503 | 116 | * @param n The arithmetic value to assign. | ||
1504 | 117 | * @return Returns \c *this. | ||
1505 | 118 | */ | ||
1506 | 94 | template<typename A> | 119 | template<typename A> |
1507 | 95 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | 120 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, |
1508 | 96 | FloatImpl&>::type | 121 | FloatImpl&>::type |
1509 | 97 | operator=( A n ); | 122 | operator=( A n ); |
1510 | 98 | 123 | ||
1513 | 99 | template<typename FloatType2> | 124 | FloatImpl& operator=( char const *s ); |
1514 | 100 | FloatImpl& operator=( FloatImpl<FloatType2> const &f ); | 125 | FloatImpl& operator=( Decimal const &d ); |
1515 | 126 | |||
1516 | 127 | TEMPLATE_DECL(I) | ||
1517 | 128 | FloatImpl& operator=( INTEGER_IMPL(I) const &i ); | ||
1518 | 101 | 129 | ||
1519 | 102 | ////////// arithmetic operators ///////////////////////////////////////////// | 130 | ////////// arithmetic operators ///////////////////////////////////////////// |
1520 | 103 | 131 | ||
1560 | 104 | template<typename A> | 132 | #define ZORBA_FLOAT_OP(OP) \ |
1561 | 105 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | 133 | template<typename A> \ |
1562 | 106 | FloatImpl&>::type | 134 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ |
1563 | 107 | operator+=( A n ); | 135 | FloatImpl&>::type \ |
1564 | 108 | 136 | operator OP( A n ) | |
1565 | 109 | template<typename A> | 137 | |
1566 | 110 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | 138 | ZORBA_FLOAT_OP(+=); |
1567 | 111 | FloatImpl&>::type | 139 | ZORBA_FLOAT_OP(-=); |
1568 | 112 | operator-=( A n ); | 140 | ZORBA_FLOAT_OP(*=); |
1569 | 113 | 141 | ZORBA_FLOAT_OP(/=); | |
1570 | 114 | template<typename A> | 142 | ZORBA_FLOAT_OP(%=); |
1571 | 115 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | 143 | #undef ZORBA_FLOAT_OP |
1572 | 116 | FloatImpl&>::type | 144 | |
1573 | 117 | operator*=( A n ); | 145 | #define ZORBA_FLOAT_OP(OP) \ |
1574 | 118 | 146 | template<typename FloatType2> \ | |
1575 | 119 | template<typename A> | 147 | FloatImpl& operator OP( FloatImpl<FloatType2> const &f ) |
1576 | 120 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | 148 | |
1577 | 121 | FloatImpl&>::type | 149 | ZORBA_FLOAT_OP(+=); |
1578 | 122 | operator/=( A n ); | 150 | ZORBA_FLOAT_OP(-=); |
1579 | 123 | 151 | ZORBA_FLOAT_OP(*=); | |
1580 | 124 | template<typename A> | 152 | ZORBA_FLOAT_OP(/=); |
1581 | 125 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | 153 | ZORBA_FLOAT_OP(%=); |
1582 | 126 | FloatImpl&>::type | 154 | #undef ZORBA_FLOAT_OP |
1544 | 127 | operator%=( A n ); | ||
1545 | 128 | |||
1546 | 129 | template<typename FloatType2> | ||
1547 | 130 | FloatImpl& operator+=( FloatImpl<FloatType2> const &f ); | ||
1548 | 131 | |||
1549 | 132 | template<typename FloatType2> | ||
1550 | 133 | FloatImpl& operator-=( FloatImpl<FloatType2> const &f ); | ||
1551 | 134 | |||
1552 | 135 | template<typename FloatType2> | ||
1553 | 136 | FloatImpl& operator*=( FloatImpl<FloatType2> const &f ); | ||
1554 | 137 | |||
1555 | 138 | template<typename FloatType2> | ||
1556 | 139 | FloatImpl& operator/=( FloatImpl<FloatType2> const &f ); | ||
1557 | 140 | |||
1558 | 141 | template<typename FloatType2> | ||
1559 | 142 | FloatImpl& operator%=( FloatImpl<FloatType2> const &f ); | ||
1583 | 143 | 155 | ||
1584 | 144 | FloatImpl operator-() const; | 156 | FloatImpl operator-() const; |
1585 | 145 | 157 | ||
1586 | @@ -231,7 +243,7 @@ | |||
1587 | 231 | void parse( char const* ); | 243 | void parse( char const* ); |
1588 | 232 | bool parse_etc( char const* ); | 244 | bool parse_etc( char const* ); |
1589 | 233 | 245 | ||
1591 | 234 | TEMPLATE_DECL(T) friend class IntegerImpl; | 246 | TEMPLATE_DECL(I) friend class IntegerImpl; |
1592 | 235 | friend class Decimal; | 247 | friend class Decimal; |
1593 | 236 | 248 | ||
1594 | 237 | friend class FloatImpl<float>; | 249 | friend class FloatImpl<float>; |
1595 | @@ -255,528 +267,524 @@ | |||
1596 | 255 | 267 | ||
1597 | 256 | ////////// constructors /////////////////////////////////////////////////////// | 268 | ////////// constructors /////////////////////////////////////////////////////// |
1598 | 257 | 269 | ||
1679 | 258 | template<typename FloatType> inline | 270 | template<typename F> |
1680 | 259 | FloatImpl<FloatType>::FloatImpl( char c ) : | 271 | inline FloatImpl<F>::FloatImpl( char c ) : |
1681 | 260 | value_( static_cast<value_type>( c ) ), precision_( max_precision() ) | 272 | value_( static_cast<F>( c ) ), precision_( max_precision() ) |
1682 | 261 | { | 273 | { |
1683 | 262 | } | 274 | } |
1684 | 263 | 275 | ||
1685 | 264 | template<typename FloatType> inline | 276 | template<typename F> |
1686 | 265 | FloatImpl<FloatType>::FloatImpl( signed char c ) : | 277 | inline FloatImpl<F>::FloatImpl( signed char c ) : |
1687 | 266 | value_( static_cast<value_type>( c ) ), precision_( max_precision() ) | 278 | value_( static_cast<F>( c ) ), precision_( max_precision() ) |
1688 | 267 | { | 279 | { |
1689 | 268 | } | 280 | } |
1690 | 269 | 281 | ||
1691 | 270 | template<typename FloatType> inline | 282 | template<typename F> |
1692 | 271 | FloatImpl<FloatType>::FloatImpl( short n ) : | 283 | inline FloatImpl<F>::FloatImpl( short n ) : |
1693 | 272 | value_( static_cast<value_type>( n ) ), precision_( max_precision() ) | 284 | value_( static_cast<F>( n ) ), precision_( max_precision() ) |
1694 | 273 | { | 285 | { |
1695 | 274 | } | 286 | } |
1696 | 275 | 287 | ||
1697 | 276 | template<typename FloatType> inline | 288 | template<typename F> |
1698 | 277 | FloatImpl<FloatType>::FloatImpl( int n ) : | 289 | inline FloatImpl<F>::FloatImpl( int n ) : |
1699 | 278 | value_( static_cast<value_type>( n ) ), precision_( max_precision() ) | 290 | value_( static_cast<F>( n ) ), precision_( max_precision() ) |
1700 | 279 | { | 291 | { |
1701 | 280 | } | 292 | } |
1702 | 281 | 293 | ||
1703 | 282 | template<typename FloatType> inline | 294 | template<typename F> |
1704 | 283 | FloatImpl<FloatType>::FloatImpl( long n ) : | 295 | inline FloatImpl<F>::FloatImpl( long n ) : |
1705 | 284 | value_( static_cast<value_type>( n ) ), precision_( max_precision() ) | 296 | value_( static_cast<F>( n ) ), precision_( max_precision() ) |
1706 | 285 | { | 297 | { |
1707 | 286 | } | 298 | } |
1708 | 287 | 299 | ||
1709 | 288 | template<typename FloatType> inline | 300 | template<typename F> |
1710 | 289 | FloatImpl<FloatType>::FloatImpl( long long n ) : | 301 | inline FloatImpl<F>::FloatImpl( long long n ) : |
1711 | 290 | value_( static_cast<value_type>( n ) ), precision_( max_precision() ) | 302 | value_( static_cast<F>( n ) ), precision_( max_precision() ) |
1712 | 291 | { | 303 | { |
1713 | 292 | } | 304 | } |
1714 | 293 | 305 | ||
1715 | 294 | template<typename FloatType> inline | 306 | template<typename F> |
1716 | 295 | FloatImpl<FloatType>::FloatImpl( unsigned char c ) : | 307 | inline FloatImpl<F>::FloatImpl( unsigned char c ) : |
1717 | 296 | value_( static_cast<value_type>( c ) ), precision_( max_precision() ) | 308 | value_( static_cast<F>( c ) ), precision_( max_precision() ) |
1718 | 297 | { | 309 | { |
1719 | 298 | } | 310 | } |
1720 | 299 | 311 | ||
1721 | 300 | template<typename FloatType> inline | 312 | template<typename F> |
1722 | 301 | FloatImpl<FloatType>::FloatImpl( unsigned short n ) : | 313 | inline FloatImpl<F>::FloatImpl( unsigned short n ) : |
1723 | 302 | value_( static_cast<value_type>( n ) ), precision_( max_precision() ) | 314 | value_( static_cast<F>( n ) ), precision_( max_precision() ) |
1724 | 303 | { | 315 | { |
1725 | 304 | } | 316 | } |
1726 | 305 | 317 | ||
1727 | 306 | template<typename FloatType> inline | 318 | template<typename F> |
1728 | 307 | FloatImpl<FloatType>::FloatImpl( unsigned int n ) : | 319 | inline FloatImpl<F>::FloatImpl( unsigned int n ) : |
1729 | 308 | value_( static_cast<value_type>( n ) ), precision_( max_precision() ) | 320 | value_( static_cast<F>( n ) ), precision_( max_precision() ) |
1730 | 309 | { | 321 | { |
1731 | 310 | } | 322 | } |
1732 | 311 | 323 | ||
1733 | 312 | template<typename FloatType> inline | 324 | template<typename F> |
1734 | 313 | FloatImpl<FloatType>::FloatImpl( unsigned long n ) : | 325 | inline FloatImpl<F>::FloatImpl( unsigned long n ) : |
1735 | 314 | value_( static_cast<value_type>( n ) ), precision_( max_precision() ) | 326 | value_( static_cast<F>( n ) ), precision_( max_precision() ) |
1736 | 315 | { | 327 | { |
1737 | 316 | } | 328 | } |
1738 | 317 | 329 | ||
1739 | 318 | template<typename FloatType> inline | 330 | template<typename F> |
1740 | 319 | FloatImpl<FloatType>::FloatImpl( unsigned long long n ) : | 331 | inline FloatImpl<F>::FloatImpl( unsigned long long n ) : |
1741 | 320 | value_( static_cast<value_type>( n ) ), precision_( max_precision() ) | 332 | value_( static_cast<F>( n ) ), precision_( max_precision() ) |
1742 | 321 | { | 333 | { |
1743 | 322 | } | 334 | } |
1744 | 323 | 335 | ||
1745 | 324 | template<typename FloatType> inline | 336 | template<typename F> |
1746 | 325 | FloatImpl<FloatType>::FloatImpl( float n ) : | 337 | inline FloatImpl<F>::FloatImpl( float n ) : |
1747 | 326 | value_( static_cast<value_type>( n ) ), precision_( max_precision() ) | 338 | value_( static_cast<F>( n ) ), precision_( max_precision() ) |
1748 | 327 | { | 339 | { |
1749 | 328 | } | 340 | } |
1750 | 329 | 341 | ||
1751 | 330 | template<typename FloatType> inline | 342 | template<typename F> |
1752 | 331 | FloatImpl<FloatType>::FloatImpl( double n ) : | 343 | inline FloatImpl<F>::FloatImpl( double n ) : |
1753 | 332 | value_( static_cast<value_type>( n ) ), precision_( max_precision() ) | 344 | value_( static_cast<F>( n ) ), precision_( max_precision() ) |
1754 | 333 | { | 345 | { |
1755 | 334 | } | 346 | } |
1756 | 335 | 347 | ||
1757 | 336 | template<typename FloatType> inline | 348 | template<typename F> |
1758 | 337 | FloatImpl<FloatType>::FloatImpl( char const *s ) { | 349 | inline FloatImpl<F>::FloatImpl( char const *s ) { |
1759 | 338 | parse( s ); | 350 | parse( s ); |
1760 | 339 | } | 351 | } |
1761 | 340 | 352 | ||
1766 | 341 | template<typename FloatType> | 353 | template<typename F> template<typename G> |
1767 | 342 | template<typename FloatType2> | 354 | inline FloatImpl<F>::FloatImpl( FloatImpl<G> const &f ) : |
1768 | 343 | inline FloatImpl<FloatType>::FloatImpl( FloatImpl<FloatType2> const &f ) : | 355 | value_( static_cast<F>( f.value_ ) ), precision_( max_precision() ) |
1765 | 344 | value_( static_cast<value_type>( f.value_ ) ), precision_( max_precision() ) | ||
1769 | 345 | { | 356 | { |
1770 | 346 | } | 357 | } |
1771 | 347 | 358 | ||
1774 | 348 | template<typename FloatType> | 359 | template<typename F> |
1775 | 349 | inline FloatImpl<FloatType>::FloatImpl( value_type v, precision_type p ) : | 360 | inline FloatImpl<F>::FloatImpl( value_type v, precision_type p ) : |
1776 | 350 | value_( v ), precision_( p ) | 361 | value_( v ), precision_( p ) |
1777 | 351 | { | 362 | { |
1778 | 352 | } | 363 | } |
1779 | 353 | 364 | ||
1780 | 354 | ////////// assignment operators /////////////////////////////////////////////// | 365 | ////////// assignment operators /////////////////////////////////////////////// |
1781 | 355 | 366 | ||
1784 | 356 | template<typename T> | 367 | template<typename F> template<typename G> |
1785 | 357 | template<typename A> inline | 368 | inline FloatImpl<F>& FloatImpl<F>::operator=( FloatImpl<G> const &f ) { |
1786 | 369 | value_ = static_cast<F>( f.value_ ); | ||
1787 | 370 | precision_ = max_precision(); | ||
1788 | 371 | return *this; | ||
1789 | 372 | } | ||
1790 | 373 | |||
1791 | 374 | template<typename F> template<typename A> inline | ||
1792 | 358 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | 375 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, |
1796 | 359 | FloatImpl<T>&>::type | 376 | FloatImpl<F>&>::type |
1797 | 360 | FloatImpl<T>::operator=( A n ) { | 377 | FloatImpl<F>::operator=( A n ) { |
1798 | 361 | value_ = static_cast<value_type>( n ); | 378 | value_ = static_cast<F>( n ); |
1799 | 362 | precision_ = max_precision(); | 379 | precision_ = max_precision(); |
1800 | 363 | return *this; | 380 | return *this; |
1801 | 364 | } | 381 | } |
1802 | 365 | 382 | ||
1808 | 366 | template<typename T> | 383 | template<typename F> |
1809 | 367 | template<typename U> | 384 | inline FloatImpl<F>& FloatImpl<F>::operator=( char const *s ) { |
1810 | 368 | inline FloatImpl<T>& FloatImpl<T>::operator=( FloatImpl<U> const &f ) { | 385 | parse( s ); |
1806 | 369 | value_ = static_cast<value_type>( f.value_ ); | ||
1807 | 370 | precision_ = max_precision(); | ||
1811 | 371 | return *this; | 386 | return *this; |
1812 | 372 | } | 387 | } |
1813 | 373 | 388 | ||
1814 | 374 | ////////// arithmetic operators /////////////////////////////////////////////// | 389 | ////////// arithmetic operators /////////////////////////////////////////////// |
1815 | 375 | 390 | ||
1818 | 376 | #define ZORBA_DEF_FLOATIMPL_OP(OP) \ | 391 | #define ZORBA_FLOAT_OP(OP) \ |
1819 | 377 | template<typename T,typename A> inline \ | 392 | template<typename F,typename A> inline \ |
1820 | 378 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ | 393 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ |
1824 | 379 | FloatImpl<T> >::type \ | 394 | FloatImpl<F> >::type \ |
1825 | 380 | operator OP( FloatImpl<T> const &f, A n ) { \ | 395 | operator OP( FloatImpl<F> const &f, A n ) { \ |
1826 | 381 | return FloatImpl<T>( f.getNumber() OP static_cast<T>( n ) ); \ | 396 | return FloatImpl<F>( f.getNumber() OP static_cast<F>( n ) ); \ |
1827 | 382 | } \ | 397 | } \ |
1881 | 383 | template<typename T,typename A> inline \ | 398 | \ |
1882 | 384 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ | 399 | template<typename F,typename A> inline \ |
1883 | 385 | FloatImpl<T> >::type \ | 400 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ |
1884 | 386 | operator OP( A n, FloatImpl<T> const &f ) { \ | 401 | FloatImpl<F> >::type \ |
1885 | 387 | return FloatImpl<T>( static_cast<T>( n ) OP f.getNumber() ); \ | 402 | operator OP( A n, FloatImpl<F> const &f ) { \ |
1886 | 388 | } | 403 | return FloatImpl<F>( static_cast<F>( n ) OP f.getNumber() ); \ |
1887 | 389 | 404 | } | |
1888 | 390 | ZORBA_DEF_FLOATIMPL_OP( + ) | 405 | |
1889 | 391 | ZORBA_DEF_FLOATIMPL_OP( - ) | 406 | ZORBA_FLOAT_OP(+) |
1890 | 392 | ZORBA_DEF_FLOATIMPL_OP( * ) | 407 | ZORBA_FLOAT_OP(-) |
1891 | 393 | ZORBA_DEF_FLOATIMPL_OP( / ) | 408 | ZORBA_FLOAT_OP(*) |
1892 | 394 | 409 | ZORBA_FLOAT_OP(/) | |
1893 | 395 | #undef ZORBA_DEF_FLOATIMPL_OP | 410 | #undef ZORBA_FLOAT_OP |
1894 | 396 | 411 | ||
1895 | 397 | template<typename T,typename A> inline | 412 | template<typename F,typename A> inline |
1896 | 398 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | 413 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, |
1897 | 399 | FloatImpl<T> >::type | 414 | FloatImpl<F> >::type |
1898 | 400 | operator%( FloatImpl<T> const &f, A n ) { | 415 | operator%( FloatImpl<F> const &f, A n ) { |
1899 | 401 | return FloatImpl<T>( std::fmod( f.getNumber(), static_cast<T>( n ) ) ); | 416 | return FloatImpl<F>( std::fmod( f.getNumber(), static_cast<F>( n ) ) ); |
1900 | 402 | } | 417 | } |
1901 | 403 | 418 | ||
1902 | 404 | template<typename T,typename A> inline | 419 | template<typename F,typename A> inline |
1903 | 405 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | 420 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, |
1904 | 406 | FloatImpl<T> >::type | 421 | FloatImpl<F> >::type |
1905 | 407 | operator%( A n, FloatImpl<T> const &f ) { | 422 | operator%( A n, FloatImpl<F> const &f ) { |
1906 | 408 | return FloatImpl<T>( std::fmod( static_cast<T>( n ), f.getNumber() ) ); | 423 | return FloatImpl<F>( std::fmod( static_cast<F>( n ), f.getNumber() ) ); |
1907 | 409 | } | 424 | } |
1908 | 410 | 425 | ||
1909 | 411 | #define ZORBA_DEF_FLOATIMPL_OP(OP) \ | 426 | #define ZORBA_FLOAT_OP(OP) \ |
1910 | 412 | template<typename T> inline \ | 427 | template<typename F> inline \ |
1911 | 413 | FloatImpl<T> operator OP( FloatImpl<T> const &f, FloatImpl<T> const &g ) { \ | 428 | FloatImpl<F> operator OP( FloatImpl<F> const &f, FloatImpl<F> const &g ) { \ |
1912 | 414 | return FloatImpl<T>( f.getNumber() OP g.getNumber() ); \ | 429 | return FloatImpl<F>( f.getNumber() OP g.getNumber() ); \ |
1913 | 415 | } | 430 | } |
1914 | 416 | 431 | ||
1915 | 417 | ZORBA_DEF_FLOATIMPL_OP( + ) | 432 | ZORBA_FLOAT_OP(+) |
1916 | 418 | ZORBA_DEF_FLOATIMPL_OP( - ) | 433 | ZORBA_FLOAT_OP(-) |
1917 | 419 | ZORBA_DEF_FLOATIMPL_OP( * ) | 434 | ZORBA_FLOAT_OP(*) |
1918 | 420 | ZORBA_DEF_FLOATIMPL_OP( / ) | 435 | ZORBA_FLOAT_OP(/) |
1919 | 421 | 436 | #undef ZORBA_FLOAT_OP | |
1920 | 422 | #undef ZORBA_DEF_FLOATIMPL_OP | 437 | |
1921 | 423 | 438 | template<typename F> | |
1922 | 424 | template<typename T> inline | 439 | inline FloatImpl<F> operator%( FloatImpl<F> const &f, FloatImpl<F> const &g ) { |
1923 | 425 | FloatImpl<T> operator%( FloatImpl<T> const &f, FloatImpl<T> const &g ) { | 440 | return FloatImpl<F>( std::fmod( f.getNumber(), g.getNumber() ) ); |
1924 | 426 | return FloatImpl<T>( std::fmod( f.getNumber(), g.getNumber() ) ); | 441 | } |
1925 | 427 | } | 442 | |
1926 | 428 | 443 | #define ZORBA_FLOAT_OP(OP) \ | |
1927 | 429 | #define ZORBA_DEF_FLOATIMPL_OP(OP) \ | 444 | template<typename F> template<typename A> inline \ |
1928 | 430 | template<typename T> \ | 445 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ |
1929 | 431 | template<typename A> inline \ | 446 | FloatImpl<F>&>::type \ |
1930 | 432 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ | 447 | FloatImpl<F>::operator OP( A n ) { \ |
1931 | 433 | FloatImpl<T>&>::type \ | 448 | value_ OP static_cast<F>( n ); \ |
1879 | 434 | FloatImpl<T>::operator OP( A n ) { \ | ||
1880 | 435 | value_ OP static_cast<value_type>( n ); \ | ||
1932 | 436 | return *this; \ | 449 | return *this; \ |
1933 | 437 | } | 450 | } |
1934 | 438 | 451 | ||
1948 | 439 | ZORBA_DEF_FLOATIMPL_OP( += ) | 452 | ZORBA_FLOAT_OP(+=) |
1949 | 440 | ZORBA_DEF_FLOATIMPL_OP( -= ) | 453 | ZORBA_FLOAT_OP(-=) |
1950 | 441 | ZORBA_DEF_FLOATIMPL_OP( *= ) | 454 | ZORBA_FLOAT_OP(*=) |
1951 | 442 | ZORBA_DEF_FLOATIMPL_OP( /= ) | 455 | ZORBA_FLOAT_OP(/=) |
1952 | 443 | ZORBA_DEF_FLOATIMPL_OP( %= ) | 456 | ZORBA_FLOAT_OP(%=) |
1953 | 444 | 457 | #undef ZORBA_FLOAT_OP | |
1954 | 445 | #undef ZORBA_DEF_FLOATIMPL_OP | 458 | |
1955 | 446 | 459 | #define ZORBA_FLOAT_OP(OP) \ | |
1956 | 447 | #define ZORBA_DEF_FLOATIMPL_OP(OP) \ | 460 | template<typename F> template<typename G> \ |
1957 | 448 | template<typename T> \ | 461 | inline FloatImpl<F>& FloatImpl<F>::operator OP( FloatImpl<G> const &f ) { \ |
1958 | 449 | template<typename U> \ | 462 | value_ OP static_cast<F>( f.value_ ); \ |
1946 | 450 | inline FloatImpl<T>& FloatImpl<T>::operator OP( FloatImpl<U> const &f ) { \ | ||
1947 | 451 | value_ OP static_cast<value_type>( f.value_ ); \ | ||
1959 | 452 | return *this; \ | 463 | return *this; \ |
1960 | 453 | } | 464 | } |
1961 | 454 | 465 | ||
2006 | 455 | ZORBA_DEF_FLOATIMPL_OP( += ) | 466 | ZORBA_FLOAT_OP(+=) |
2007 | 456 | ZORBA_DEF_FLOATIMPL_OP( -= ) | 467 | ZORBA_FLOAT_OP(-=) |
2008 | 457 | ZORBA_DEF_FLOATIMPL_OP( *= ) | 468 | ZORBA_FLOAT_OP(*=) |
2009 | 458 | ZORBA_DEF_FLOATIMPL_OP( /= ) | 469 | ZORBA_FLOAT_OP(/=) |
2010 | 459 | ZORBA_DEF_FLOATIMPL_OP( %= ) | 470 | #undef ZORBA_FLOAT_OP |
2011 | 460 | 471 | ||
2012 | 461 | #undef ZORBA_DEF_FLOATIMPL_OP | 472 | template<typename F> template<typename G> |
2013 | 462 | 473 | inline FloatImpl<F>& FloatImpl<F>::operator%=( FloatImpl<G> const &f ) { | |
2014 | 463 | template<typename FloatType> | 474 | value_ = std::fmod( value_, static_cast<F>( f.value_ ) ); |
2015 | 464 | inline FloatImpl<FloatType> FloatImpl<FloatType>::operator-() const { | 475 | return *this; |
2016 | 465 | return FloatImpl<FloatType>( -value_, precision_ ); | 476 | } |
2017 | 466 | } | 477 | |
2018 | 467 | 478 | template<typename F> | |
2019 | 468 | inline Double operator+( Double const &d, Float const &f ) { | 479 | inline FloatImpl<F> FloatImpl<F>::operator-() const { |
2020 | 469 | return d.getNumber() + f.getNumber(); | 480 | return FloatImpl<F>( -value_, precision_ ); |
2021 | 470 | } | 481 | } |
2022 | 471 | 482 | ||
2023 | 472 | inline Double operator+( Float const &f, Double const &d ) { | 483 | #define ZORBA_FLOAT_OP(OP) \ |
2024 | 473 | return f.getNumber() + d.getNumber(); | 484 | inline Double operator OP( Double const &d, Float const &f ) { \ |
2025 | 474 | } | 485 | return Double( d.getNumber() OP f.getNumber() ); \ |
2026 | 475 | 486 | } \ | |
2027 | 476 | inline Double operator-( Double const &d, Float const &f ) { | 487 | inline Double operator OP( Float const &f, Double const &d ) { \ |
2028 | 477 | return d.getNumber() - f.getNumber(); | 488 | return Double( f.getNumber() OP d.getNumber() ); \ |
2029 | 478 | } | 489 | } |
2030 | 479 | 490 | ||
2031 | 480 | inline Double operator-( Float const &f, Double const &d ) { | 491 | ZORBA_FLOAT_OP(+) |
2032 | 481 | return f.getNumber() - d.getNumber(); | 492 | ZORBA_FLOAT_OP(-) |
2033 | 482 | } | 493 | ZORBA_FLOAT_OP(*) |
2034 | 483 | 494 | ZORBA_FLOAT_OP(/) | |
2035 | 484 | inline Double operator*( Double const &d, Float const &f ) { | 495 | #undef ZORBA_FLOAT_OP |
1992 | 485 | return d.getNumber() * f.getNumber(); | ||
1993 | 486 | } | ||
1994 | 487 | |||
1995 | 488 | inline Double operator*( Float const &f, Double const &d ) { | ||
1996 | 489 | return f.getNumber() * d.getNumber(); | ||
1997 | 490 | } | ||
1998 | 491 | |||
1999 | 492 | inline Double operator/( Double const &d, Float const &f ) { | ||
2000 | 493 | return d.getNumber() / f.getNumber(); | ||
2001 | 494 | } | ||
2002 | 495 | |||
2003 | 496 | inline Double operator/( Float const &f, Double const &d ) { | ||
2004 | 497 | return f.getNumber() / d.getNumber(); | ||
2005 | 498 | } | ||
2036 | 499 | 496 | ||
2037 | 500 | inline Double operator%( Double const &d, Float const &f ) { | 497 | inline Double operator%( Double const &d, Float const &f ) { |
2039 | 501 | return std::fmod( d.getNumber(), static_cast<double>( f.getNumber() ) ); | 498 | return Double( |
2040 | 499 | std::fmod( d.getNumber(), static_cast<double>( f.getNumber() ) ) | ||
2041 | 500 | ); | ||
2042 | 502 | } | 501 | } |
2043 | 503 | 502 | ||
2044 | 504 | inline Double operator%( Float const &f, Double const &d ) { | 503 | inline Double operator%( Float const &f, Double const &d ) { |
2046 | 505 | return std::fmod( static_cast<double>( f.getNumber() ), d.getNumber() ); | 504 | return Double( |
2047 | 505 | std::fmod( static_cast<double>( f.getNumber() ), d.getNumber() ) | ||
2048 | 506 | ); | ||
2049 | 506 | } | 507 | } |
2050 | 507 | 508 | ||
2051 | 508 | ////////// relational operators /////////////////////////////////////////////// | 509 | ////////// relational operators /////////////////////////////////////////////// |
2052 | 509 | 510 | ||
2055 | 510 | template<typename T,typename U> | 511 | template<typename F,typename G> |
2056 | 511 | inline bool operator==( FloatImpl<T> const &f, FloatImpl<U> const &g ) { | 512 | inline bool operator==( FloatImpl<F> const &f, FloatImpl<G> const &g ) { |
2057 | 512 | return f.getNumber() == g.getNumber(); | 513 | return f.getNumber() == g.getNumber(); |
2058 | 513 | } | 514 | } |
2059 | 514 | 515 | ||
2062 | 515 | template<typename T,typename U> | 516 | template<typename F,typename G> |
2063 | 516 | inline bool operator!=( FloatImpl<T> const &f, FloatImpl<U> const &g ) { | 517 | inline bool operator!=( FloatImpl<F> const &f, FloatImpl<G> const &g ) { |
2064 | 517 | return f.getNumber() != g.getNumber(); | 518 | return f.getNumber() != g.getNumber(); |
2065 | 518 | } | 519 | } |
2066 | 519 | 520 | ||
2069 | 520 | template<typename T,typename U> | 521 | template<typename F,typename G> |
2070 | 521 | inline bool operator<( FloatImpl<T> const &f, FloatImpl<U> const &g ) { | 522 | inline bool operator<( FloatImpl<F> const &f, FloatImpl<G> const &g ) { |
2071 | 522 | return f.getNumber() < g.getNumber(); | 523 | return f.getNumber() < g.getNumber(); |
2072 | 523 | } | 524 | } |
2073 | 524 | 525 | ||
2076 | 525 | template<typename T,typename U> | 526 | template<typename F,typename G> |
2077 | 526 | inline bool operator<=( FloatImpl<T> const &f, FloatImpl<U> const &g ) { | 527 | inline bool operator<=( FloatImpl<F> const &f, FloatImpl<G> const &g ) { |
2078 | 527 | return !f.isNaN() && !g.isNaN() && f.getNumber() <= g.getNumber(); | 528 | return !f.isNaN() && !g.isNaN() && f.getNumber() <= g.getNumber(); |
2079 | 528 | } | 529 | } |
2080 | 529 | 530 | ||
2083 | 530 | template<typename T,typename U> | 531 | template<typename F,typename G> |
2084 | 531 | inline bool operator>( FloatImpl<T> const &f, FloatImpl<U> const &g ) { | 532 | inline bool operator>( FloatImpl<F> const &f, FloatImpl<G> const &g ) { |
2085 | 532 | return f.getNumber() > g.getNumber(); | 533 | return f.getNumber() > g.getNumber(); |
2086 | 533 | } | 534 | } |
2087 | 534 | 535 | ||
2090 | 535 | template<typename T,typename U> | 536 | template<typename F,typename G> |
2091 | 536 | inline bool operator>=( FloatImpl<T> const &f, FloatImpl<U> const &g ) { | 537 | inline bool operator>=( FloatImpl<F> const &f, FloatImpl<G> const &g ) { |
2092 | 537 | return !f.isNaN() && !g.isNaN() && f.getNumber() >= g.getNumber(); | 538 | return !f.isNaN() && !g.isNaN() && f.getNumber() >= g.getNumber(); |
2093 | 538 | } | 539 | } |
2094 | 539 | 540 | ||
2097 | 540 | template<typename T> | 541 | template<typename F> |
2098 | 541 | inline bool operator==( FloatImpl<T> const &f, double d ) { | 542 | inline bool operator==( FloatImpl<F> const &f, double d ) { |
2099 | 542 | return f.getNumber() == d; | 543 | return f.getNumber() == d; |
2100 | 543 | } | 544 | } |
2101 | 544 | 545 | ||
2104 | 545 | template<typename T> | 546 | template<typename F> |
2105 | 546 | inline bool operator==( double d, FloatImpl<T> const &f ) { | 547 | inline bool operator==( double d, FloatImpl<F> const &f ) { |
2106 | 547 | return d = f.getNumber(); | 548 | return d = f.getNumber(); |
2107 | 548 | } | 549 | } |
2108 | 549 | 550 | ||
2121 | 550 | template<typename T> | 551 | template<typename F> |
2122 | 551 | inline bool operator!=( FloatImpl<T> const &f, double d ) { | 552 | inline bool operator!=( FloatImpl<F> const &f, double d ) { |
2123 | 552 | return f.getNumber() != d; | 553 | return f.getNumber() != d; |
2124 | 553 | } | 554 | } |
2125 | 554 | 555 | ||
2126 | 555 | template<typename T> | 556 | template<typename F> |
2127 | 556 | inline bool operator!=( double d, FloatImpl<T> const &f ) { | 557 | inline bool operator!=( double d, FloatImpl<F> const &f ) { |
2128 | 557 | return f.getNumber() != d; | 558 | return f.getNumber() != d; |
2129 | 558 | } | 559 | } |
2130 | 559 | 560 | ||
2131 | 560 | template<typename T> | 561 | template<typename F> |
2132 | 561 | inline bool operator<( FloatImpl<T> const &f, double d ) { | 562 | inline bool operator<( FloatImpl<F> const &f, double d ) { |
2133 | 562 | return f.getNumber() < d; | 563 | return f.getNumber() < d; |
2134 | 563 | } | 564 | } |
2135 | 564 | 565 | ||
2138 | 565 | template<typename T> | 566 | template<typename F> |
2139 | 566 | inline bool operator<( double d, FloatImpl<T> const &f ) { | 567 | inline bool operator<( double d, FloatImpl<F> const &f ) { |
2140 | 567 | return d < f.getNumber(); | 568 | return d < f.getNumber(); |
2141 | 568 | } | 569 | } |
2142 | 569 | 570 | ||
2145 | 570 | template<typename T> | 571 | template<typename F> |
2146 | 571 | inline bool operator<=( FloatImpl<T> const &f, double d ) { | 572 | inline bool operator<=( FloatImpl<F> const &f, double d ) { |
2147 | 572 | return !f.isNaN() && d == d && f.getNumber() <= d; | 573 | return !f.isNaN() && d == d && f.getNumber() <= d; |
2148 | 573 | } | 574 | } |
2149 | 574 | 575 | ||
2152 | 575 | template<typename T> | 576 | template<typename F> |
2153 | 576 | inline bool operator<=( double d, FloatImpl<T> const &f ) { | 577 | inline bool operator<=( double d, FloatImpl<F> const &f ) { |
2154 | 577 | return d == d && !f.isNaN() && d <= f.getNumber(); | 578 | return d == d && !f.isNaN() && d <= f.getNumber(); |
2155 | 578 | } | 579 | } |
2156 | 579 | 580 | ||
2159 | 580 | template<typename T> | 581 | template<typename F> |
2160 | 581 | inline bool operator>( FloatImpl<T> const &f, double d ) { | 582 | inline bool operator>( FloatImpl<F> const &f, double d ) { |
2161 | 582 | return f.getNumber() > d; | 583 | return f.getNumber() > d; |
2162 | 583 | } | 584 | } |
2163 | 584 | 585 | ||
2166 | 585 | template<typename T> | 586 | template<typename F> |
2167 | 586 | inline bool operator>( double d, FloatImpl<T> const &f ) { | 587 | inline bool operator>( double d, FloatImpl<F> const &f ) { |
2168 | 587 | return d > f.getNumber(); | 588 | return d > f.getNumber(); |
2169 | 588 | } | 589 | } |
2170 | 589 | 590 | ||
2173 | 590 | template<typename T> | 591 | template<typename F> |
2174 | 591 | inline bool operator>=( FloatImpl<T> const &f, double d ) { | 592 | inline bool operator>=( FloatImpl<F> const &f, double d ) { |
2175 | 592 | return !f.isNaN() && d == d && f.getNumber() >= d; | 593 | return !f.isNaN() && d == d && f.getNumber() >= d; |
2176 | 593 | } | 594 | } |
2177 | 594 | 595 | ||
2180 | 595 | template<typename T> | 596 | template<typename F> |
2181 | 596 | inline bool operator>=( double d, FloatImpl<T> const &f ) { | 597 | inline bool operator>=( double d, FloatImpl<F> const &f ) { |
2182 | 597 | return d == d && !f.isNaN() && d >= f.getNumber(); | 598 | return d == d && !f.isNaN() && d >= f.getNumber(); |
2183 | 598 | } | 599 | } |
2184 | 599 | 600 | ||
2185 | 600 | ////////// math functions ///////////////////////////////////////////////////// | 601 | ////////// math functions ///////////////////////////////////////////////////// |
2186 | 601 | 602 | ||
2292 | 602 | template<typename FloatType> inline FloatImpl<FloatType> | 603 | template<typename F> |
2293 | 603 | FloatImpl<FloatType>::acosh() const { | 604 | inline FloatImpl<F> FloatImpl<F>::acosh() const { |
2294 | 604 | // formula from www.mathworks.com | 605 | // formula from www.mathworks.com |
2295 | 605 | return std::log( value_ + std::sqrt( value_ * value_ - 1 ) ); | 606 | return FloatImpl<F>( |
2296 | 606 | } | 607 | std::log( value_ + std::sqrt( value_ * value_ - 1 ) ) |
2297 | 607 | 608 | ); | |
2298 | 608 | template<typename FloatType> inline FloatImpl<FloatType> | 609 | } |
2299 | 609 | FloatImpl<FloatType>::asinh() const { | 610 | |
2300 | 610 | // formula from www.mathworks.com | 611 | template<typename F> |
2301 | 611 | return std::log( value_ + std::sqrt( value_ * value_ + 1 ) ); | 612 | inline FloatImpl<F> FloatImpl<F>::asinh() const { |
2302 | 612 | } | 613 | // formula from www.mathworks.com |
2303 | 613 | 614 | return FloatImpl<F>( | |
2304 | 614 | template<typename FloatType> inline FloatImpl<FloatType> | 615 | std::log( value_ + std::sqrt( value_ * value_ + 1 ) ) |
2305 | 615 | FloatImpl<FloatType>::atan() const { | 616 | ); |
2306 | 616 | return std::atan( value_ ); | 617 | } |
2307 | 617 | } | 618 | |
2308 | 618 | 619 | template<typename F> | |
2309 | 619 | template<typename FloatType> inline FloatImpl<FloatType> | 620 | inline FloatImpl<F> FloatImpl<F>::atan() const { |
2310 | 620 | FloatImpl<FloatType>::atanh() const { | 621 | return FloatImpl<F>( std::atan( value_ ) ); |
2311 | 621 | // formula from www.mathworks.com | 622 | } |
2312 | 622 | return 0.5 * std::log( (1 + value_) / (1 - value_) ); | 623 | |
2313 | 623 | } | 624 | template<typename F> |
2314 | 624 | 625 | inline FloatImpl<F> FloatImpl<F>::atanh() const { | |
2315 | 625 | template<typename FloatType> inline FloatImpl<FloatType> | 626 | // formula from www.mathworks.com |
2316 | 626 | FloatImpl<FloatType>::atan2( double x ) const { | 627 | return FloatImpl<F>( 0.5 * std::log( (1 + value_) / (1 - value_) ) ); |
2317 | 627 | return std::atan2( value_, static_cast<value_type>( x ) ); | 628 | } |
2318 | 628 | } | 629 | |
2319 | 629 | 630 | template<typename F> | |
2320 | 630 | template<typename FloatType> inline FloatImpl<FloatType> | 631 | inline FloatImpl<F> FloatImpl<F>::atan2( double x ) const { |
2321 | 631 | FloatImpl<FloatType>::atan2( FloatImpl<FloatType> const &x ) const { | 632 | return FloatImpl<F>( std::atan2( value_, static_cast<F>( x ) ) ); |
2322 | 632 | return atan2( x.value_ ); | 633 | } |
2323 | 633 | } | 634 | |
2324 | 634 | 635 | template<typename F> | |
2325 | 635 | template<typename FloatType> inline FloatImpl<FloatType> | 636 | inline FloatImpl<F> FloatImpl<F>::atan2( FloatImpl<F> const &x ) const { |
2326 | 636 | FloatImpl<FloatType>::ceil() const { | 637 | return FloatImpl<F>( atan2( x.value_ ) ); |
2327 | 637 | return std::ceil( value_ ); | 638 | } |
2328 | 638 | } | 639 | |
2329 | 639 | 640 | template<typename F> | |
2330 | 640 | template<typename FloatType> inline FloatImpl<FloatType> | 641 | inline FloatImpl<F> FloatImpl<F>::ceil() const { |
2331 | 641 | FloatImpl<FloatType>::cos() const { | 642 | return FloatImpl<F>( std::ceil( value_ ) ); |
2332 | 642 | return std::cos( value_ ); | 643 | } |
2333 | 643 | } | 644 | |
2334 | 644 | 645 | template<typename F> | |
2335 | 645 | template<typename FloatType> inline FloatImpl<FloatType> | 646 | inline FloatImpl<F> FloatImpl<F>::cos() const { |
2336 | 646 | FloatImpl<FloatType>::cosh() const { | 647 | return FloatImpl<F>( std::cos( value_ ) ); |
2337 | 647 | return std::cosh( value_ ); | 648 | } |
2338 | 648 | } | 649 | |
2339 | 649 | 650 | template<typename F> | |
2340 | 650 | template<typename FloatType> inline FloatImpl<FloatType> | 651 | inline FloatImpl<F> FloatImpl<F>::cosh() const { |
2341 | 651 | FloatImpl<FloatType>::exp() const { | 652 | return FloatImpl<F>( std::cosh( value_ ) ); |
2342 | 652 | return std::exp( value_ ); | 653 | } |
2343 | 653 | } | 654 | |
2344 | 654 | 655 | template<typename F> | |
2345 | 655 | template<typename FloatType> inline FloatImpl<FloatType> | 656 | inline FloatImpl<F> FloatImpl<F>::exp() const { |
2346 | 656 | FloatImpl<FloatType>::exp10() const { | 657 | return FloatImpl<F>( std::exp( value_ ) ); |
2347 | 657 | return std::pow( 10, value_ ); | 658 | } |
2348 | 658 | } | 659 | |
2349 | 659 | 660 | template<typename F> | |
2350 | 660 | template<typename FloatType> inline FloatImpl<FloatType> | 661 | inline FloatImpl<F> FloatImpl<F>::exp10() const { |
2351 | 661 | FloatImpl<FloatType>::floor() const { | 662 | return FloatImpl<F>( std::pow( 10, value_ ) ); |
2352 | 662 | return std::floor( value_ ); | 663 | } |
2353 | 663 | } | 664 | |
2354 | 664 | 665 | template<typename F> | |
2355 | 665 | template<typename FloatType> inline FloatImpl<FloatType> | 666 | inline FloatImpl<F> FloatImpl<F>::floor() const { |
2356 | 666 | FloatImpl<FloatType>::fmod( double d ) const { | 667 | return FloatImpl<F>( std::floor( value_ ) ); |
2357 | 667 | return std::fmod( value_, static_cast<value_type>( d ) ); | 668 | } |
2358 | 668 | } | 669 | |
2359 | 669 | 670 | template<typename F> | |
2360 | 670 | template<typename FloatType> inline FloatImpl<FloatType> | 671 | inline FloatImpl<F> FloatImpl<F>::fmod( double d ) const { |
2361 | 671 | FloatImpl<FloatType>::fmod( FloatImpl<FloatType> const &f ) const { | 672 | return FloatImpl<F>( std::fmod( value_, static_cast<F>( d ) ) ); |
2362 | 672 | return fmod( f.value_ ); | 673 | } |
2363 | 673 | } | 674 | |
2364 | 674 | 675 | template<typename F> | |
2365 | 675 | template<typename FloatType> | 676 | inline FloatImpl<F> |
2366 | 676 | FloatImpl<FloatType> FloatImpl<FloatType>::log() const { | 677 | FloatImpl<F>::fmod( FloatImpl<F> const &f ) const { |
2367 | 677 | return value_ < 0 ? nan() : FloatImpl<FloatType>( std::log( value_ ) ); | 678 | return FloatImpl<F>( fmod( f.value_ ) ); |
2368 | 678 | } | 679 | } |
2369 | 679 | 680 | ||
2370 | 680 | template<typename FloatType> | 681 | template<typename F> |
2371 | 681 | FloatImpl<FloatType> FloatImpl<FloatType>::log10() const { | 682 | FloatImpl<F> FloatImpl<F>::log() const { |
2372 | 682 | return value_ < 0 ? nan() : FloatImpl<FloatType>( std::log10( value_ ) ); | 683 | return value_ < 0 ? nan() : FloatImpl<F>( std::log( value_ ) ); |
2373 | 683 | } | 684 | } |
2374 | 684 | 685 | ||
2375 | 685 | template<typename FloatType> inline FloatImpl<FloatType> | 686 | template<typename F> |
2376 | 686 | FloatImpl<FloatType>::pow( int p ) const { | 687 | FloatImpl<F> FloatImpl<F>::log10() const { |
2377 | 687 | return std::pow( value_, p ); | 688 | return value_ < 0 ? nan() : FloatImpl<F>( std::log10( value_ ) ); |
2378 | 688 | } | 689 | } |
2379 | 689 | 690 | ||
2380 | 690 | template<typename FloatType> inline FloatImpl<FloatType> | 691 | template<typename F> |
2381 | 691 | FloatImpl<FloatType>::pow( FloatImpl<FloatType> const &p ) const { | 692 | inline FloatImpl<F> FloatImpl<F>::pow( int p ) const { |
2382 | 692 | return p.isNaN() ? value_ : std::pow( value_, p.value_ ); | 693 | return FloatImpl<F>( std::pow( value_, p ) ); |
2383 | 693 | } | 694 | } |
2384 | 694 | 695 | ||
2385 | 695 | template<typename FloatType> inline FloatImpl<FloatType> | 696 | template<typename F> |
2386 | 696 | FloatImpl<FloatType>::sin() const { | 697 | inline FloatImpl<F> |
2387 | 697 | return std::sin( value_ ); | 698 | FloatImpl<F>::pow( FloatImpl<F> const &p ) const { |
2388 | 698 | } | 699 | return FloatImpl<F>( |
2389 | 699 | 700 | p.isNaN() ? value_ : std::pow( value_, p.value_ ) | |
2390 | 700 | template<typename FloatType> inline FloatImpl<FloatType> | 701 | ); |
2391 | 701 | FloatImpl<FloatType>::sinh() const { | 702 | } |
2392 | 702 | return std::sinh( value_ ); | 703 | |
2393 | 703 | } | 704 | template<typename F> |
2394 | 704 | 705 | inline FloatImpl<F> FloatImpl<F>::sin() const { | |
2395 | 705 | template<typename FloatType> inline FloatImpl<FloatType> | 706 | return FloatImpl<F>( std::sin( value_ ) ); |
2396 | 706 | FloatImpl<FloatType>::sqrt() const { | 707 | } |
2397 | 708 | |||
2398 | 709 | template<typename F> | ||
2399 | 710 | inline FloatImpl<F> FloatImpl<F>::sinh() const { | ||
2400 | 711 | return FloatImpl<F>( std::sinh( value_ ) ); | ||
2401 | 712 | } | ||
2402 | 713 | |||
2403 | 714 | template<typename F> | ||
2404 | 715 | inline FloatImpl<F> FloatImpl<F>::sqrt() const { | ||
2405 | 707 | return value_ < 0 ? nan() : FloatImpl( std::sqrt( value_ ) ); | 716 | return value_ < 0 ? nan() : FloatImpl( std::sqrt( value_ ) ); |
2406 | 708 | } | 717 | } |
2407 | 709 | 718 | ||
2411 | 710 | template<typename FloatType> inline FloatImpl<FloatType> | 719 | template<typename F> |
2412 | 711 | FloatImpl<FloatType>::tan() const { | 720 | inline FloatImpl<F> FloatImpl<F>::tan() const { |
2413 | 712 | return std::tan( value_ ); | 721 | return FloatImpl<F>( std::tan( value_ ) ); |
2414 | 713 | } | 722 | } |
2415 | 714 | 723 | ||
2419 | 715 | template<typename FloatType> inline FloatImpl<FloatType> | 724 | template<typename F> |
2420 | 716 | FloatImpl<FloatType>::tanh() const { | 725 | inline FloatImpl<F> FloatImpl<F>::tanh() const { |
2421 | 717 | return std::tanh( value_ ); | 726 | return FloatImpl<F>( std::tanh( value_ ) ); |
2422 | 718 | } | 727 | } |
2423 | 719 | 728 | ||
2424 | 720 | ////////// miscellaneous ////////////////////////////////////////////////////// | 729 | ////////// miscellaneous ////////////////////////////////////////////////////// |
2425 | 721 | 730 | ||
2429 | 722 | template<typename T> | 731 | template<typename F> template<typename G> |
2430 | 723 | template<typename U> | 732 | inline int FloatImpl<F>::compare( FloatImpl<G> const &f ) const { |
2428 | 724 | inline int FloatImpl<T>::compare( FloatImpl<U> const &f ) const { | ||
2431 | 725 | return value_ < f.value_ ? -1 : value_ > f.value_ ? 1 : 0; | 733 | return value_ < f.value_ ? -1 : value_ > f.value_ ? 1 : 0; |
2432 | 726 | } | 734 | } |
2433 | 727 | 735 | ||
2436 | 728 | template<typename FloatType> | 736 | template<typename F> |
2437 | 729 | inline uint32_t FloatImpl<FloatType>::hash() const { | 737 | inline uint32_t FloatImpl<F>::hash() const { |
2438 | 730 | return static_cast<uint32_t>( value_ ); | 738 | return static_cast<uint32_t>( value_ ); |
2439 | 731 | } | 739 | } |
2440 | 732 | 740 | ||
2443 | 733 | template<typename FloatType> | 741 | template<typename F> |
2444 | 734 | inline bool FloatImpl<FloatType>::isNeg() const { | 742 | inline bool FloatImpl<F>::isNeg() const { |
2445 | 735 | return value_ < 0; | 743 | return value_ < 0; |
2446 | 736 | } | 744 | } |
2447 | 737 | 745 | ||
2450 | 738 | template<typename FloatType> | 746 | template<typename F> |
2451 | 739 | inline bool FloatImpl<FloatType>::isPos() const { | 747 | inline bool FloatImpl<F>::isPos() const { |
2452 | 740 | return value_ > 0; | 748 | return value_ > 0; |
2453 | 741 | } | 749 | } |
2454 | 742 | 750 | ||
2457 | 743 | template<typename FloatType> | 751 | template<typename F> |
2458 | 744 | inline bool FloatImpl<FloatType>::isPosZero() const { | 752 | inline bool FloatImpl<F>::isPosZero() const { |
2459 | 745 | return value_ == 0 && !isNegZero(); | 753 | return value_ == 0 && !isNegZero(); |
2460 | 746 | } | 754 | } |
2461 | 747 | 755 | ||
2464 | 748 | template<typename FloatType> | 756 | template<typename F> |
2465 | 749 | inline bool FloatImpl<FloatType>::isNaN() const { | 757 | inline bool FloatImpl<F>::isNaN() const { |
2466 | 750 | return value_ != value_; | 758 | return value_ != value_; |
2467 | 751 | } | 759 | } |
2468 | 752 | 760 | ||
2481 | 753 | template<typename FloatType> | 761 | template<typename F> |
2482 | 754 | inline bool FloatImpl<FloatType>::isNegInf() const { | 762 | inline bool FloatImpl<F>::isNegInf() const { |
2483 | 755 | return value_ == -std::numeric_limits<FloatType>::infinity(); | 763 | return value_ == -std::numeric_limits<F>::infinity(); |
2484 | 756 | } | 764 | } |
2485 | 757 | 765 | ||
2486 | 758 | template<typename FloatType> | 766 | template<typename F> |
2487 | 759 | inline bool FloatImpl<FloatType>::isPosInf() const { | 767 | inline bool FloatImpl<F>::isPosInf() const { |
2488 | 760 | return value_ == std::numeric_limits<FloatType>::infinity(); | 768 | return value_ == std::numeric_limits<F>::infinity(); |
2489 | 761 | } | 769 | } |
2490 | 762 | 770 | ||
2491 | 763 | template<typename FloatType> | 771 | template<typename F> |
2492 | 764 | inline bool FloatImpl<FloatType>::isFinite() const { | 772 | inline bool FloatImpl<F>::isFinite() const { |
2493 | 765 | return !isNaN() && !isPosInf() && !isNegInf(); | 773 | return !isNaN() && !isPosInf() && !isNegInf(); |
2494 | 766 | } | 774 | } |
2495 | 767 | 775 | ||
2498 | 768 | template<typename FloatType> | 776 | template<typename F> |
2499 | 769 | inline bool FloatImpl<FloatType>::isInteger() const { | 777 | inline bool FloatImpl<F>::isInteger() const { |
2500 | 770 | return isFinite() && ::floor( value_ ) == value_; | 778 | return isFinite() && ::floor( value_ ) == value_; |
2501 | 771 | } | 779 | } |
2502 | 772 | 780 | ||
2505 | 773 | template <typename FloatType> | 781 | template <typename F> |
2506 | 774 | inline bool FloatImpl<FloatType>::isZero() const { | 782 | inline bool FloatImpl<F>::isZero() const { |
2507 | 775 | return value_ == 0; | 783 | return value_ == 0; |
2508 | 776 | } | 784 | } |
2509 | 777 | 785 | ||
2512 | 778 | template<typename FloatType> inline | 786 | template<typename F> |
2513 | 779 | std::ostream& operator<<( std::ostream &os, FloatImpl<FloatType> const &f ) { | 787 | inline std::ostream& operator<<( std::ostream &os, FloatImpl<F> const &f ) { |
2514 | 780 | return os << f.toString(); | 788 | return os << f.toString(); |
2515 | 781 | } | 789 | } |
2516 | 782 | 790 | ||
2517 | 783 | 791 | ||
2518 | === modified file 'src/zorbatypes/integer.cpp' | |||
2519 | --- src/zorbatypes/integer.cpp 2012-03-30 19:03:09 +0000 | |||
2520 | +++ src/zorbatypes/integer.cpp 2012-04-16 15:38:09 +0000 | |||
2521 | @@ -230,13 +230,13 @@ | |||
2522 | 230 | 230 | ||
2523 | 231 | TEMPLATE_DECL(T) | 231 | TEMPLATE_DECL(T) |
2524 | 232 | INTEGER_IMPL(T) INTEGER_IMPL(T)::round( IntegerImpl const &precision ) const { | 232 | INTEGER_IMPL(T) INTEGER_IMPL(T)::round( IntegerImpl const &precision ) const { |
2526 | 233 | return IntegerImpl( Decimal::round( itod(), precision.itod() ) ); | 233 | return IntegerImpl( Decimal::round2( itod(), precision.itod() ) ); |
2527 | 234 | } | 234 | } |
2528 | 235 | 235 | ||
2529 | 236 | TEMPLATE_DECL(T) | 236 | TEMPLATE_DECL(T) |
2530 | 237 | INTEGER_IMPL(T) | 237 | INTEGER_IMPL(T) |
2531 | 238 | INTEGER_IMPL(T)::roundHalfToEven( IntegerImpl const &precision ) const { | 238 | INTEGER_IMPL(T)::roundHalfToEven( IntegerImpl const &precision ) const { |
2533 | 239 | return IntegerImpl( Decimal::roundHalfToEven( itod(), precision.itod() ) ); | 239 | return IntegerImpl( Decimal::roundHalfToEven2( itod(), precision.itod() ) ); |
2534 | 240 | } | 240 | } |
2535 | 241 | 241 | ||
2536 | 242 | ////////// miscellaneous ////////////////////////////////////////////////////// | 242 | ////////// miscellaneous ////////////////////////////////////////////////////// |
2537 | 243 | 243 | ||
2538 | === modified file 'src/zorbatypes/integer.h' | |||
2539 | --- src/zorbatypes/integer.h 2012-04-12 02:08:10 +0000 | |||
2540 | +++ src/zorbatypes/integer.h 2012-04-16 15:38:09 +0000 | |||
2541 | @@ -22,8 +22,8 @@ | |||
2542 | 22 | #include <limits> | 22 | #include <limits> |
2543 | 23 | 23 | ||
2544 | 24 | #include <zorba/config.h> | 24 | #include <zorba/config.h> |
2545 | 25 | |||
2546 | 25 | #include "common/common.h" | 26 | #include "common/common.h" |
2547 | 26 | |||
2548 | 27 | #include "util/stl_util.h" | 27 | #include "util/stl_util.h" |
2549 | 28 | 28 | ||
2550 | 29 | #include "m_apm.h" | 29 | #include "m_apm.h" |
2551 | @@ -32,25 +32,25 @@ | |||
2552 | 32 | #include "zstring.h" | 32 | #include "zstring.h" |
2553 | 33 | 33 | ||
2554 | 34 | #ifdef ZORBA_WITH_BIG_INTEGER | 34 | #ifdef ZORBA_WITH_BIG_INTEGER |
2557 | 35 | # define TEMPLATE_DECL(T) /* nothing */ | 35 | # define TEMPLATE_DECL(I) /* nothing */ |
2558 | 36 | # define INTEGER_IMPL(T) IntegerImpl | 36 | # define TEMPLATE_DECL2(I,A) template<typename A> |
2559 | 37 | # define INTEGER_IMPL(I) IntegerImpl | ||
2560 | 37 | #else | 38 | #else |
2563 | 38 | # define TEMPLATE_DECL(T) template<typename T> | 39 | # define TEMPLATE_DECL(I) template<typename I> |
2564 | 39 | # define INTEGER_IMPL(T) IntegerImpl<T> | 40 | # define TEMPLATE_DECL2(I,A) template<typename I,typename A> |
2565 | 41 | # define INTEGER_IMPL(I) IntegerImpl<I> | ||
2566 | 40 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 42 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
2567 | 41 | #define INTEGER_IMPL_LL INTEGER_IMPL(long long) | 43 | #define INTEGER_IMPL_LL INTEGER_IMPL(long long) |
2568 | 42 | #define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long) | 44 | #define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long) |
2569 | 43 | 45 | ||
2570 | 44 | namespace zorba { | 46 | namespace zorba { |
2571 | 45 | 47 | ||
2573 | 46 | TEMPLATE_DECL(T) | 48 | TEMPLATE_DECL(I) |
2574 | 47 | class IntegerImpl; | 49 | class IntegerImpl; |
2575 | 48 | 50 | ||
2578 | 49 | namespace serialization | 51 | namespace serialization { |
2577 | 50 | { | ||
2579 | 51 | class Archiver; | 52 | class Archiver; |
2582 | 52 | 53 | TEMPLATE_DECL(I) void operator&( Archiver&, INTEGER_IMPL(I)& ); | |
2581 | 53 | TEMPLATE_DECL(T) void operator&( Archiver&, INTEGER_IMPL(T)& ); | ||
2583 | 54 | } | 54 | } |
2584 | 55 | 55 | ||
2585 | 56 | /////////////////////////////////////////////////////////////////////////////// | 56 | /////////////////////////////////////////////////////////////////////////////// |
2586 | @@ -61,23 +61,20 @@ | |||
2587 | 61 | 61 | ||
2588 | 62 | ////////// constructors ///////////////////////////////////////////////////// | 62 | ////////// constructors ///////////////////////////////////////////////////// |
2589 | 63 | 63 | ||
2607 | 64 | IntegerImpl( char c ); | 64 | explicit IntegerImpl( char c ); |
2608 | 65 | IntegerImpl( signed char c ); | 65 | explicit IntegerImpl( signed char c ); |
2609 | 66 | IntegerImpl( short n ); | 66 | explicit IntegerImpl( short n ); |
2610 | 67 | IntegerImpl( int n = 0 ); | 67 | explicit IntegerImpl( int n = 0 ); |
2611 | 68 | IntegerImpl( long n ); | 68 | explicit IntegerImpl( long n ); |
2612 | 69 | IntegerImpl( long long n ); | 69 | explicit IntegerImpl( long long n ); |
2613 | 70 | IntegerImpl( unsigned char c ); | 70 | explicit IntegerImpl( unsigned char c ); |
2614 | 71 | IntegerImpl( unsigned short n ); | 71 | explicit IntegerImpl( unsigned short n ); |
2615 | 72 | IntegerImpl( unsigned int n ); | 72 | explicit IntegerImpl( unsigned int n ); |
2616 | 73 | IntegerImpl( unsigned long n ); | 73 | explicit IntegerImpl( unsigned long n ); |
2617 | 74 | IntegerImpl( unsigned long long n ); | 74 | explicit IntegerImpl( unsigned long long n ); |
2618 | 75 | IntegerImpl( float n ); | 75 | explicit IntegerImpl( float n ); |
2619 | 76 | IntegerImpl( double n ); | 76 | explicit IntegerImpl( double n ); |
2620 | 77 | IntegerImpl( Decimal const &d ); | 77 | explicit IntegerImpl( Decimal const &d ); |
2604 | 78 | |||
2605 | 79 | TEMPLATE_DECL(U) | ||
2606 | 80 | IntegerImpl( INTEGER_IMPL(U) const &i ); | ||
2621 | 81 | 78 | ||
2622 | 82 | /** | 79 | /** |
2623 | 83 | * Constructs an %IntegerImpl from a C string. | 80 | * Constructs an %IntegerImpl from a C string. |
2624 | @@ -89,7 +86,7 @@ | |||
2625 | 89 | * or overflows the smallest or largest representable integer (only when not | 86 | * or overflows the smallest or largest representable integer (only when not |
2626 | 90 | * compiled with ZORBA_WITH_BIG_INTEGER). | 87 | * compiled with ZORBA_WITH_BIG_INTEGER). |
2627 | 91 | */ | 88 | */ |
2629 | 92 | IntegerImpl( char const *s ); | 89 | explicit IntegerImpl( char const *s ); |
2630 | 93 | 90 | ||
2631 | 94 | /** | 91 | /** |
2632 | 95 | * Constructs an %IntegerImpl from a Double. | 92 | * Constructs an %IntegerImpl from a Double. |
2633 | @@ -97,7 +94,7 @@ | |||
2634 | 97 | * @param d The Double. | 94 | * @param d The Double. |
2635 | 98 | * @throw std::invalid_argument if \a d is not finite. | 95 | * @throw std::invalid_argument if \a d is not finite. |
2636 | 99 | */ | 96 | */ |
2638 | 100 | IntegerImpl( Double const &d ); | 97 | explicit IntegerImpl( Double const &d ); |
2639 | 101 | 98 | ||
2640 | 102 | /** | 99 | /** |
2641 | 103 | * Constructs an %IntegerImpl from a Float. | 100 | * Constructs an %IntegerImpl from a Float. |
2642 | @@ -105,54 +102,113 @@ | |||
2643 | 105 | * @param f The Float. | 102 | * @param f The Float. |
2644 | 106 | * @throw std::invalid_argument if \a f is not finite. | 103 | * @throw std::invalid_argument if \a f is not finite. |
2645 | 107 | */ | 104 | */ |
2647 | 108 | IntegerImpl( Float const &f ); | 105 | explicit IntegerImpl( Float const &f ); |
2648 | 106 | |||
2649 | 107 | /** | ||
2650 | 108 | * Constructs from another %IntegerImpl even if its \c IntType is different. | ||
2651 | 109 | * (This subsumes the conventional copy constructor.) | ||
2652 | 110 | * | ||
2653 | 111 | * @tparam IntType2 the integer type of \a i. | ||
2654 | 112 | * @param i The %IntegerImpl to copy from. | ||
2655 | 113 | */ | ||
2656 | 114 | TEMPLATE_DECL(IntType2) | ||
2657 | 115 | IntegerImpl( INTEGER_IMPL(IntType2) const &i ); | ||
2658 | 109 | 116 | ||
2659 | 110 | ////////// assignment operators ///////////////////////////////////////////// | 117 | ////////// assignment operators ///////////////////////////////////////////// |
2660 | 111 | 118 | ||
2674 | 112 | IntegerImpl& operator=( char c ); | 119 | /** |
2675 | 113 | IntegerImpl& operator=( signed char c ); | 120 | * Assign from an %IntegerImpl even if its \c IntType is different. |
2676 | 114 | IntegerImpl& operator=( short n ); | 121 | * (This subsumes the conventional assignment operator.) |
2677 | 115 | IntegerImpl& operator=( int n ); | 122 | * |
2678 | 116 | IntegerImpl& operator=( long n ); | 123 | * @tparam IntType2 the integer type of \a i. |
2679 | 117 | IntegerImpl& operator=( long long n ); | 124 | * @param i The %IntegerImpl to assign from. |
2680 | 118 | IntegerImpl& operator=( unsigned char c ); | 125 | * @return Returns \c *this. |
2681 | 119 | IntegerImpl& operator=( unsigned short n ); | 126 | */ |
2682 | 120 | IntegerImpl& operator=( unsigned int n ); | 127 | TEMPLATE_DECL(IntType2) |
2683 | 121 | IntegerImpl& operator=( unsigned long n ); | 128 | IntegerImpl& operator=( INTEGER_IMPL(IntType2) const &i ); |
2684 | 122 | IntegerImpl& operator=( unsigned long long n ); | 129 | |
2685 | 123 | IntegerImpl& operator=( float n ); | 130 | /** |
2686 | 124 | IntegerImpl& operator=( double n ); | 131 | * For every built-in arithmetic type A, assign to this %IntegerImpl. |
2687 | 132 | * | ||
2688 | 133 | * @tparam A The built-in arithmetic type. | ||
2689 | 134 | * @param n The arithmetic value to assign. | ||
2690 | 135 | * @return Returns \c *this. | ||
2691 | 136 | */ | ||
2692 | 137 | template<typename A> | ||
2693 | 138 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | ||
2694 | 139 | IntegerImpl&>::type | ||
2695 | 140 | operator=( A n ); | ||
2696 | 141 | |||
2697 | 142 | // These arithmetic types have to be special-cased. | ||
2698 | 143 | IntegerImpl& operator=( long long ); | ||
2699 | 144 | IntegerImpl& operator=( unsigned long ); | ||
2700 | 145 | IntegerImpl& operator=( unsigned long long ); | ||
2701 | 146 | |||
2702 | 125 | IntegerImpl& operator=( char const *s ); | 147 | IntegerImpl& operator=( char const *s ); |
2703 | 126 | IntegerImpl& operator=( Decimal const &d ); | 148 | IntegerImpl& operator=( Decimal const &d ); |
2704 | 127 | IntegerImpl& operator=( Double const &d ); | 149 | IntegerImpl& operator=( Double const &d ); |
2705 | 128 | IntegerImpl& operator=( Float const &f ); | 150 | IntegerImpl& operator=( Float const &f ); |
2706 | 129 | 151 | ||
2707 | 130 | TEMPLATE_DECL(U) | ||
2708 | 131 | IntegerImpl& operator=( INTEGER_IMPL(U) const &i ); | ||
2709 | 132 | |||
2710 | 133 | ////////// arithmetic operators ///////////////////////////////////////////// | 152 | ////////// arithmetic operators ///////////////////////////////////////////// |
2711 | 134 | 153 | ||
2712 | 135 | #define ZORBA_INTEGER_OP(OP) \ | 154 | #define ZORBA_INTEGER_OP(OP) \ |
2733 | 136 | TEMPLATE_DECL(T) friend \ | 155 | TEMPLATE_DECL(I) friend \ |
2734 | 137 | INTEGER_IMPL(T) operator OP( INTEGER_IMPL(T) const&, \ | 156 | INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const&, \ |
2735 | 138 | INTEGER_IMPL(T) const& ); \ | 157 | INTEGER_IMPL(I) const& ); \ |
2736 | 139 | TEMPLATE_DECL(T) friend \ | 158 | \ |
2737 | 140 | Decimal operator OP( INTEGER_IMPL(T) const&, Decimal const& ); \ | 159 | TEMPLATE_DECL(I) friend \ |
2738 | 141 | TEMPLATE_DECL(T) friend \ | 160 | Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \ |
2739 | 142 | Decimal operator OP( Decimal const&, INTEGER_IMPL(T) const& ) | 161 | \ |
2740 | 143 | 162 | TEMPLATE_DECL(I) friend \ | |
2741 | 144 | ZORBA_INTEGER_OP(+); | 163 | Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& ) |
2742 | 145 | ZORBA_INTEGER_OP(-); | 164 | |
2743 | 146 | ZORBA_INTEGER_OP(*); | 165 | ZORBA_INTEGER_OP(+); |
2744 | 147 | ZORBA_INTEGER_OP(/); | 166 | ZORBA_INTEGER_OP(-); |
2745 | 148 | ZORBA_INTEGER_OP(%); | 167 | ZORBA_INTEGER_OP(*); |
2746 | 149 | #undef ZORBA_INTEGER_OP | 168 | ZORBA_INTEGER_OP(/); |
2747 | 150 | 169 | ZORBA_INTEGER_OP(%); | |
2748 | 151 | IntegerImpl& operator+=( IntegerImpl const& ); | 170 | #undef ZORBA_INTEGER_OP |
2749 | 152 | IntegerImpl& operator-=( IntegerImpl const& ); | 171 | |
2750 | 153 | IntegerImpl& operator*=( IntegerImpl const& ); | 172 | #define ZORBA_INTEGER_OP(OP) \ |
2751 | 154 | IntegerImpl& operator/=( IntegerImpl const& ); | 173 | TEMPLATE_DECL2(I,A) friend \ |
2752 | 155 | IntegerImpl& operator%=( IntegerImpl const& ); | 174 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ |
2753 | 175 | INTEGER_IMPL(I)>::type \ | ||
2754 | 176 | operator OP( INTEGER_IMPL(I) const&, A ); \ | ||
2755 | 177 | \ | ||
2756 | 178 | TEMPLATE_DECL2(I,A) friend \ | ||
2757 | 179 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ | ||
2758 | 180 | INTEGER_IMPL(I)>::type \ | ||
2759 | 181 | operator OP( A, INTEGER_IMPL(I) const& ) | ||
2760 | 182 | |||
2761 | 183 | ZORBA_INTEGER_OP(+); | ||
2762 | 184 | ZORBA_INTEGER_OP(-); | ||
2763 | 185 | ZORBA_INTEGER_OP(*); | ||
2764 | 186 | ZORBA_INTEGER_OP(/); | ||
2765 | 187 | ZORBA_INTEGER_OP(%); | ||
2766 | 188 | #undef ZORBA_INTEGER_OP | ||
2767 | 189 | |||
2768 | 190 | #define ZORBA_INTEGER_OP(OP,TYPE) \ | ||
2769 | 191 | IntegerImpl& operator OP( TYPE ) | ||
2770 | 192 | |||
2771 | 193 | ZORBA_INTEGER_OP(+=,IntegerImpl const&); | ||
2772 | 194 | ZORBA_INTEGER_OP(-=,IntegerImpl const&); | ||
2773 | 195 | ZORBA_INTEGER_OP(*=,IntegerImpl const&); | ||
2774 | 196 | ZORBA_INTEGER_OP(/=,IntegerImpl const&); | ||
2775 | 197 | ZORBA_INTEGER_OP(%=,IntegerImpl const&); | ||
2776 | 198 | #undef ZORBA_INTEGER_OP | ||
2777 | 199 | |||
2778 | 200 | #define ZORBA_INTEGER_OP(OP) \ | ||
2779 | 201 | template<typename A> \ | ||
2780 | 202 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ | ||
2781 | 203 | IntegerImpl&>::type \ | ||
2782 | 204 | operator OP( A ) | ||
2783 | 205 | |||
2784 | 206 | ZORBA_INTEGER_OP(+=); | ||
2785 | 207 | ZORBA_INTEGER_OP(-=); | ||
2786 | 208 | ZORBA_INTEGER_OP(*=); | ||
2787 | 209 | ZORBA_INTEGER_OP(/=); | ||
2788 | 210 | ZORBA_INTEGER_OP(%=); | ||
2789 | 211 | #undef ZORBA_INTEGER_OP | ||
2790 | 156 | 212 | ||
2791 | 157 | IntegerImpl operator-() const; | 213 | IntegerImpl operator-() const; |
2792 | 158 | 214 | ||
2793 | @@ -164,12 +220,31 @@ | |||
2794 | 164 | ////////// relational operators ///////////////////////////////////////////// | 220 | ////////// relational operators ///////////////////////////////////////////// |
2795 | 165 | 221 | ||
2796 | 166 | #define ZORBA_INTEGER_OP(OP) \ | 222 | #define ZORBA_INTEGER_OP(OP) \ |
2803 | 167 | TEMPLATE_DECL(T) friend \ | 223 | TEMPLATE_DECL(I) friend \ |
2804 | 168 | bool operator OP( INTEGER_IMPL(T) const&, INTEGER_IMPL(T) const& ); \ | 224 | bool operator OP( INTEGER_IMPL(I) const&, INTEGER_IMPL(I) const& ); \ |
2805 | 169 | TEMPLATE_DECL(T) friend \ | 225 | \ |
2806 | 170 | bool operator OP( INTEGER_IMPL(T) const&, Decimal const& ); \ | 226 | TEMPLATE_DECL(I) friend \ |
2807 | 171 | TEMPLATE_DECL(T) friend \ | 227 | bool operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \ |
2808 | 172 | bool operator OP( Decimal const&, INTEGER_IMPL(T) const& ) | 228 | \ |
2809 | 229 | TEMPLATE_DECL(I) friend \ | ||
2810 | 230 | bool operator OP( Decimal const&, INTEGER_IMPL(I) const& ) | ||
2811 | 231 | |||
2812 | 232 | ZORBA_INTEGER_OP(==); | ||
2813 | 233 | ZORBA_INTEGER_OP(!=); | ||
2814 | 234 | ZORBA_INTEGER_OP(< ); | ||
2815 | 235 | ZORBA_INTEGER_OP(<=); | ||
2816 | 236 | ZORBA_INTEGER_OP(> ); | ||
2817 | 237 | ZORBA_INTEGER_OP(>=); | ||
2818 | 238 | #undef ZORBA_INTEGER_OP | ||
2819 | 239 | |||
2820 | 240 | #define ZORBA_INTEGER_OP(OP) \ | ||
2821 | 241 | TEMPLATE_DECL2(I,A) friend \ | ||
2822 | 242 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \ | ||
2823 | 243 | operator OP( INTEGER_IMPL(I) const&, A ); \ | ||
2824 | 244 | \ | ||
2825 | 245 | TEMPLATE_DECL2(I,A) friend \ | ||
2826 | 246 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \ | ||
2827 | 247 | operator OP( A, INTEGER_IMPL(I) const& ) | ||
2828 | 173 | 248 | ||
2829 | 174 | ZORBA_INTEGER_OP(==); | 249 | ZORBA_INTEGER_OP(==); |
2830 | 175 | ZORBA_INTEGER_OP(!=); | 250 | ZORBA_INTEGER_OP(!=); |
2831 | @@ -214,6 +289,11 @@ | |||
2832 | 214 | } | 289 | } |
2833 | 215 | 290 | ||
2834 | 216 | #ifdef ZORBA_WITH_BIG_INTEGER | 291 | #ifdef ZORBA_WITH_BIG_INTEGER |
2835 | 292 | template<typename T> | ||
2836 | 293 | static value_type cast( T n ) { | ||
2837 | 294 | return value_type( static_cast<long>( n ) ); | ||
2838 | 295 | } | ||
2839 | 296 | |||
2840 | 217 | static value_type ftoi( MAPM const &d ) { | 297 | static value_type ftoi( MAPM const &d ) { |
2841 | 218 | return d.sign() >= 0 ? d.floor() : d.ceil(); | 298 | return d.sign() >= 0 ? d.floor() : d.ceil(); |
2842 | 219 | } | 299 | } |
2843 | @@ -222,6 +302,11 @@ | |||
2844 | 222 | return value_; // intentional no-op | 302 | return value_; // intentional no-op |
2845 | 223 | } | 303 | } |
2846 | 224 | #else | 304 | #else |
2847 | 305 | template<typename T> | ||
2848 | 306 | static value_type cast( T n ) { | ||
2849 | 307 | return static_cast<value_type>( n ); | ||
2850 | 308 | } | ||
2851 | 309 | |||
2852 | 225 | bool is_long() const; | 310 | bool is_long() const; |
2853 | 226 | 311 | ||
2854 | 227 | static value_type ftoi( value_type v ) { | 312 | static value_type ftoi( value_type v ) { |
2855 | @@ -239,7 +324,7 @@ | |||
2856 | 239 | template<typename T> friend class FloatImpl; | 324 | template<typename T> friend class FloatImpl; |
2857 | 240 | 325 | ||
2858 | 241 | #ifndef ZORBA_WITH_BIG_INTEGER | 326 | #ifndef ZORBA_WITH_BIG_INTEGER |
2860 | 242 | template<typename U> friend class IntegerImpl; | 327 | template<typename T> friend class IntegerImpl; |
2861 | 243 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 328 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
2862 | 244 | 329 | ||
2863 | 245 | friend xs_int to_xs_int( INTEGER_IMPL_LL const& ); | 330 | friend xs_int to_xs_int( INTEGER_IMPL_LL const& ); |
2864 | @@ -247,8 +332,8 @@ | |||
2865 | 247 | friend xs_unsignedInt to_xs_unsignedInt( INTEGER_IMPL_LL const& ); | 332 | friend xs_unsignedInt to_xs_unsignedInt( INTEGER_IMPL_LL const& ); |
2866 | 248 | friend xs_unsignedLong to_xs_unsignedLong( INTEGER_IMPL_LL const& ); | 333 | friend xs_unsignedLong to_xs_unsignedLong( INTEGER_IMPL_LL const& ); |
2867 | 249 | 334 | ||
2870 | 250 | TEMPLATE_DECL(T) friend | 335 | TEMPLATE_DECL(I) friend |
2871 | 251 | void serialization::operator&( serialization::Archiver&, INTEGER_IMPL(T)& ); | 336 | void serialization::operator&( serialization::Archiver&, INTEGER_IMPL(I)& ); |
2872 | 252 | }; | 337 | }; |
2873 | 253 | 338 | ||
2874 | 254 | typedef INTEGER_IMPL_LL Integer; | 339 | typedef INTEGER_IMPL_LL Integer; |
2875 | @@ -256,78 +341,78 @@ | |||
2876 | 256 | 341 | ||
2877 | 257 | ////////// constructors /////////////////////////////////////////////////////// | 342 | ////////// constructors /////////////////////////////////////////////////////// |
2878 | 258 | 343 | ||
2951 | 259 | TEMPLATE_DECL(T) | 344 | TEMPLATE_DECL(I) |
2952 | 260 | inline INTEGER_IMPL(T)::IntegerImpl( char c ) : | 345 | inline INTEGER_IMPL(I)::IntegerImpl( char c ) : |
2953 | 261 | value_( static_cast<long>( c ) ) | 346 | value_( static_cast<long>( c ) ) |
2954 | 262 | { | 347 | { |
2955 | 263 | } | 348 | } |
2956 | 264 | 349 | ||
2957 | 265 | TEMPLATE_DECL(T) | 350 | TEMPLATE_DECL(I) |
2958 | 266 | inline INTEGER_IMPL(T)::IntegerImpl( signed char c ) : | 351 | inline INTEGER_IMPL(I)::IntegerImpl( signed char c ) : |
2959 | 267 | value_( static_cast<long>( c ) ) | 352 | value_( static_cast<long>( c ) ) |
2960 | 268 | { | 353 | { |
2961 | 269 | } | 354 | } |
2962 | 270 | 355 | ||
2963 | 271 | TEMPLATE_DECL(T) | 356 | TEMPLATE_DECL(I) |
2964 | 272 | inline INTEGER_IMPL(T)::IntegerImpl( short n ) : | 357 | inline INTEGER_IMPL(I)::IntegerImpl( short n ) : |
2965 | 273 | value_( static_cast<long>( n ) ) | 358 | value_( static_cast<long>( n ) ) |
2966 | 274 | { | 359 | { |
2967 | 275 | } | 360 | } |
2968 | 276 | 361 | ||
2969 | 277 | TEMPLATE_DECL(T) | 362 | TEMPLATE_DECL(I) |
2970 | 278 | inline INTEGER_IMPL(T)::IntegerImpl( int n ) : | 363 | inline INTEGER_IMPL(I)::IntegerImpl( int n ) : |
2971 | 279 | value_( static_cast<long>( n ) ) | 364 | value_( static_cast<long>( n ) ) |
2972 | 280 | { | 365 | { |
2973 | 281 | } | 366 | } |
2974 | 282 | 367 | ||
2975 | 283 | TEMPLATE_DECL(T) | 368 | TEMPLATE_DECL(I) |
2976 | 284 | inline INTEGER_IMPL(T)::IntegerImpl( long n ) : | 369 | inline INTEGER_IMPL(I)::IntegerImpl( long n ) : |
2977 | 285 | value_( n ) | 370 | value_( n ) |
2978 | 286 | { | 371 | { |
2979 | 287 | } | 372 | } |
2980 | 288 | 373 | ||
2981 | 289 | #ifndef ZORBA_WITH_BIG_INTEGER | 374 | #ifndef ZORBA_WITH_BIG_INTEGER |
2982 | 290 | TEMPLATE_DECL(T) | 375 | TEMPLATE_DECL(I) |
2983 | 291 | inline INTEGER_IMPL(T)::IntegerImpl( long long n ) : | 376 | inline INTEGER_IMPL(I)::IntegerImpl( long long n ) : |
2984 | 292 | value_( n ) | 377 | value_( n ) |
2985 | 293 | { | 378 | { |
2986 | 294 | } | 379 | } |
2987 | 295 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 380 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
2988 | 296 | 381 | ||
2989 | 297 | TEMPLATE_DECL(T) | 382 | TEMPLATE_DECL(I) |
2990 | 298 | inline INTEGER_IMPL(T)::IntegerImpl( unsigned char c ) : | 383 | inline INTEGER_IMPL(I)::IntegerImpl( unsigned char c ) : |
2991 | 299 | value_( static_cast<long>( c ) ) | 384 | value_( static_cast<long>( c ) ) |
2992 | 300 | { | 385 | { |
2993 | 301 | } | 386 | } |
2994 | 302 | 387 | ||
2995 | 303 | TEMPLATE_DECL(T) | 388 | TEMPLATE_DECL(I) |
2996 | 304 | inline INTEGER_IMPL(T)::IntegerImpl( unsigned short n ) : | 389 | inline INTEGER_IMPL(I)::IntegerImpl( unsigned short n ) : |
2997 | 305 | value_( static_cast<long>( n ) ) | 390 | value_( static_cast<long>( n ) ) |
2998 | 306 | { | 391 | { |
2999 | 307 | } | 392 | } |
3000 | 308 | 393 | ||
3001 | 309 | TEMPLATE_DECL(T) | 394 | TEMPLATE_DECL(I) |
3002 | 310 | inline INTEGER_IMPL(T)::IntegerImpl( unsigned int n ) : | 395 | inline INTEGER_IMPL(I)::IntegerImpl( unsigned int n ) : |
3003 | 311 | value_( static_cast<long>( n ) ) | 396 | value_( static_cast<long>( n ) ) |
3004 | 312 | { | 397 | { |
3005 | 313 | } | 398 | } |
3006 | 314 | 399 | ||
3007 | 315 | #ifndef ZORBA_WITH_BIG_INTEGER | 400 | #ifndef ZORBA_WITH_BIG_INTEGER |
3008 | 316 | TEMPLATE_DECL(T) | 401 | TEMPLATE_DECL(I) |
3009 | 317 | inline INTEGER_IMPL(T)::IntegerImpl( unsigned long n ) : | 402 | inline INTEGER_IMPL(I)::IntegerImpl( unsigned long n ) : |
3010 | 318 | value_( static_cast<value_type>( n ) ) | 403 | value_( static_cast<value_type>( n ) ) |
3011 | 319 | { | 404 | { |
3012 | 320 | } | 405 | } |
3013 | 321 | 406 | ||
3014 | 322 | TEMPLATE_DECL(T) | 407 | TEMPLATE_DECL(I) |
3015 | 323 | inline INTEGER_IMPL(T)::IntegerImpl( unsigned long long n ) : | 408 | inline INTEGER_IMPL(I)::IntegerImpl( unsigned long long n ) : |
3016 | 324 | value_( static_cast<value_type>( n ) ) | 409 | value_( static_cast<value_type>( n ) ) |
3017 | 325 | { | 410 | { |
3018 | 326 | } | 411 | } |
3019 | 327 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 412 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3020 | 328 | 413 | ||
3021 | 329 | TEMPLATE_DECL(T) | 414 | TEMPLATE_DECL(I) |
3022 | 330 | inline INTEGER_IMPL(T)::IntegerImpl( float n ) : | 415 | inline INTEGER_IMPL(I)::IntegerImpl( float n ) : |
3023 | 331 | #ifdef ZORBA_WITH_BIG_INTEGER | 416 | #ifdef ZORBA_WITH_BIG_INTEGER |
3024 | 332 | value_( static_cast<double>( n ) ) | 417 | value_( static_cast<double>( n ) ) |
3025 | 333 | #else | 418 | #else |
3026 | @@ -336,8 +421,8 @@ | |||
3027 | 336 | { | 421 | { |
3028 | 337 | } | 422 | } |
3029 | 338 | 423 | ||
3032 | 339 | TEMPLATE_DECL(T) | 424 | TEMPLATE_DECL(I) |
3033 | 340 | inline INTEGER_IMPL(T)::IntegerImpl( double n ) : | 425 | inline INTEGER_IMPL(I)::IntegerImpl( double n ) : |
3034 | 341 | #ifdef ZORBA_WITH_BIG_INTEGER | 426 | #ifdef ZORBA_WITH_BIG_INTEGER |
3035 | 342 | value_( n ) | 427 | value_( n ) |
3036 | 343 | #else | 428 | #else |
3037 | @@ -346,111 +431,56 @@ | |||
3038 | 346 | { | 431 | { |
3039 | 347 | } | 432 | } |
3040 | 348 | 433 | ||
3043 | 349 | TEMPLATE_DECL(T) | 434 | TEMPLATE_DECL(I) |
3044 | 350 | inline INTEGER_IMPL(T)::IntegerImpl( char const *s ) { | 435 | inline INTEGER_IMPL(I)::IntegerImpl( char const *s ) { |
3045 | 351 | parse( s ); | 436 | parse( s ); |
3046 | 352 | } | 437 | } |
3047 | 353 | 438 | ||
3051 | 354 | TEMPLATE_DECL(T) | 439 | TEMPLATE_DECL(I) |
3052 | 355 | TEMPLATE_DECL(U) | 440 | TEMPLATE_DECL(J) |
3053 | 356 | inline INTEGER_IMPL(T)::IntegerImpl( INTEGER_IMPL(U) const &i ) : | 441 | inline INTEGER_IMPL(I)::IntegerImpl( INTEGER_IMPL(J) const &i ) : |
3054 | 357 | value_( i.value_ ) | 442 | value_( i.value_ ) |
3055 | 358 | { | 443 | { |
3056 | 359 | } | 444 | } |
3057 | 360 | 445 | ||
3058 | 361 | ////////// assignment operators /////////////////////////////////////////////// | 446 | ////////// assignment operators /////////////////////////////////////////////// |
3059 | 362 | 447 | ||
3144 | 363 | TEMPLATE_DECL(T) | 448 | TEMPLATE_DECL(I) template<typename A> inline |
3145 | 364 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( char c ) { | 449 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, |
3146 | 365 | value_ = static_cast<long>( c ); | 450 | INTEGER_IMPL(I)&>::type |
3147 | 366 | return *this; | 451 | INTEGER_IMPL(I)::operator=( A n ) { |
3148 | 367 | } | 452 | value_ = static_cast<long>( n ); |
3149 | 368 | 453 | return *this; | |
3150 | 369 | TEMPLATE_DECL(T) | 454 | } |
3151 | 370 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( signed char c ) { | 455 | |
3152 | 371 | value_ = static_cast<long>( c ); | 456 | #ifndef ZORBA_WITH_BIG_INTEGER |
3153 | 372 | return *this; | 457 | template<typename I> |
3154 | 373 | } | 458 | inline IntegerImpl<I>& IntegerImpl<I>::operator=( long long n ) { |
3155 | 374 | 459 | value_ = n; | |
3156 | 375 | TEMPLATE_DECL(T) | 460 | return *this; |
3157 | 376 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( short n ) { | 461 | } |
3158 | 377 | value_ = static_cast<long>( n ); | 462 | |
3159 | 378 | return *this; | 463 | template<typename I> |
3160 | 379 | } | 464 | inline IntegerImpl<I>& IntegerImpl<I>::operator=( unsigned long n ) { |
3161 | 380 | 465 | value_ = static_cast<long>( n ); | |
3162 | 381 | TEMPLATE_DECL(T) | 466 | return *this; |
3163 | 382 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( int n ) { | 467 | } |
3164 | 383 | value_ = static_cast<long>( n ); | 468 | |
3165 | 384 | return *this; | 469 | template<typename I> |
3166 | 385 | } | 470 | inline IntegerImpl<I>& IntegerImpl<I>::operator=( unsigned long long n ) { |
3167 | 386 | 471 | value_ = n; | |
3168 | 387 | TEMPLATE_DECL(T) | 472 | return *this; |
3169 | 388 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( long n ) { | 473 | } |
3170 | 389 | value_ = n; | 474 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3171 | 390 | return *this; | 475 | |
3172 | 391 | } | 476 | TEMPLATE_DECL(I) |
3173 | 392 | 477 | inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( char const *s ) { | |
3090 | 393 | #ifndef ZORBA_WITH_BIG_INTEGER | ||
3091 | 394 | TEMPLATE_DECL(T) | ||
3092 | 395 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( long long n ) { | ||
3093 | 396 | value_ = n; | ||
3094 | 397 | return *this; | ||
3095 | 398 | } | ||
3096 | 399 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
3097 | 400 | |||
3098 | 401 | TEMPLATE_DECL(T) | ||
3099 | 402 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned char c ) { | ||
3100 | 403 | value_ = static_cast<long>( c ); | ||
3101 | 404 | return *this; | ||
3102 | 405 | } | ||
3103 | 406 | |||
3104 | 407 | TEMPLATE_DECL(T) | ||
3105 | 408 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned short n ) { | ||
3106 | 409 | value_ = static_cast<long>( n ); | ||
3107 | 410 | return *this; | ||
3108 | 411 | } | ||
3109 | 412 | |||
3110 | 413 | TEMPLATE_DECL(T) | ||
3111 | 414 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned int n ) { | ||
3112 | 415 | value_ = static_cast<long>( n ); | ||
3113 | 416 | return *this; | ||
3114 | 417 | } | ||
3115 | 418 | |||
3116 | 419 | #ifndef ZORBA_WITH_BIG_INTEGER | ||
3117 | 420 | TEMPLATE_DECL(T) | ||
3118 | 421 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned long n ) { | ||
3119 | 422 | value_ = static_cast<long>( n ); | ||
3120 | 423 | return *this; | ||
3121 | 424 | } | ||
3122 | 425 | |||
3123 | 426 | TEMPLATE_DECL(T) | ||
3124 | 427 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned long long n ) { | ||
3125 | 428 | value_ = n; | ||
3126 | 429 | return *this; | ||
3127 | 430 | } | ||
3128 | 431 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
3129 | 432 | |||
3130 | 433 | TEMPLATE_DECL(T) | ||
3131 | 434 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( float n ) { | ||
3132 | 435 | value_ = static_cast<long>( n ); | ||
3133 | 436 | return *this; | ||
3134 | 437 | } | ||
3135 | 438 | |||
3136 | 439 | TEMPLATE_DECL(T) | ||
3137 | 440 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( double n ) { | ||
3138 | 441 | value_ = static_cast<long>( n ); | ||
3139 | 442 | return *this; | ||
3140 | 443 | } | ||
3141 | 444 | |||
3142 | 445 | TEMPLATE_DECL(T) | ||
3143 | 446 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( char const *s ) { | ||
3174 | 447 | parse( s ); | 478 | parse( s ); |
3175 | 448 | return *this; | 479 | return *this; |
3176 | 449 | } | 480 | } |
3177 | 450 | 481 | ||
3181 | 451 | TEMPLATE_DECL(T) | 482 | TEMPLATE_DECL(I) TEMPLATE_DECL(J) |
3182 | 452 | TEMPLATE_DECL(U) | 483 | inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( INTEGER_IMPL(J) const &i ) { |
3180 | 453 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( INTEGER_IMPL(U) const &i ) { | ||
3183 | 454 | value_ = i.value_; | 484 | value_ = i.value_; |
3184 | 455 | return *this; | 485 | return *this; |
3185 | 456 | } | 486 | } |
3186 | @@ -458,26 +488,66 @@ | |||
3187 | 458 | ////////// arithmetic operators /////////////////////////////////////////////// | 488 | ////////// arithmetic operators /////////////////////////////////////////////// |
3188 | 459 | 489 | ||
3189 | 460 | #define ZORBA_INTEGER_OP(OP) \ | 490 | #define ZORBA_INTEGER_OP(OP) \ |
3205 | 461 | TEMPLATE_DECL(T) inline \ | 491 | TEMPLATE_DECL(I) inline \ |
3206 | 462 | INTEGER_IMPL(T) operator OP( INTEGER_IMPL(T) const &i, \ | 492 | INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const &i, \ |
3207 | 463 | INTEGER_IMPL(T) const &j ) { \ | 493 | INTEGER_IMPL(I) const &j ) { \ |
3208 | 464 | return i.value_ OP j.value_; \ | 494 | return INTEGER_IMPL(I)( i.value_ OP j.value_ ); \ |
3209 | 465 | } | 495 | } |
3210 | 466 | 496 | ||
3211 | 467 | ZORBA_INTEGER_OP(+) | 497 | ZORBA_INTEGER_OP(+) |
3212 | 468 | ZORBA_INTEGER_OP(-) | 498 | ZORBA_INTEGER_OP(-) |
3213 | 469 | ZORBA_INTEGER_OP(*) | 499 | ZORBA_INTEGER_OP(*) |
3214 | 470 | ZORBA_INTEGER_OP(%) | 500 | ZORBA_INTEGER_OP(%) |
3215 | 471 | #undef ZORBA_INTEGER_OP | 501 | #undef ZORBA_INTEGER_OP |
3216 | 472 | 502 | ||
3217 | 473 | TEMPLATE_DECL(T) inline | 503 | TEMPLATE_DECL(I) inline |
3218 | 474 | INTEGER_IMPL(T) operator/( INTEGER_IMPL(T) const &i, INTEGER_IMPL(T) const &j ) { | 504 | INTEGER_IMPL(I) operator/( INTEGER_IMPL(I) const &i, |
3219 | 475 | return INTEGER_IMPL(T)::ftoi( i.value_ / j.value_ ); | 505 | INTEGER_IMPL(I) const &j ) { |
3220 | 506 | return INTEGER_IMPL(I)( INTEGER_IMPL(I)::ftoi( i.value_ / j.value_ ) ); | ||
3221 | 507 | } | ||
3222 | 508 | |||
3223 | 509 | #define ZORBA_INTEGER_OP(OP) \ | ||
3224 | 510 | TEMPLATE_DECL2(I,A) inline \ | ||
3225 | 511 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ | ||
3226 | 512 | INTEGER_IMPL(I)>::type \ | ||
3227 | 513 | operator OP( INTEGER_IMPL(I) const& i, A n ) { \ | ||
3228 | 514 | return INTEGER_IMPL(I)( i.value_ OP INTEGER_IMPL(I)::cast( n ) ); \ | ||
3229 | 515 | } \ | ||
3230 | 516 | \ | ||
3231 | 517 | TEMPLATE_DECL2(I,A) inline \ | ||
3232 | 518 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ | ||
3233 | 519 | INTEGER_IMPL(I)>::type \ | ||
3234 | 520 | operator OP( A n, INTEGER_IMPL(I) const &i ) { \ | ||
3235 | 521 | return INTEGER_IMPL(I)( INTEGER_IMPL(I)::cast( n ) OP i.value_ ); \ | ||
3236 | 522 | } | ||
3237 | 523 | |||
3238 | 524 | ZORBA_INTEGER_OP(+) | ||
3239 | 525 | ZORBA_INTEGER_OP(-) | ||
3240 | 526 | ZORBA_INTEGER_OP(*) | ||
3241 | 527 | ZORBA_INTEGER_OP(%) | ||
3242 | 528 | #undef ZORBA_INTEGER_OP | ||
3243 | 529 | |||
3244 | 530 | TEMPLATE_DECL2(I,A) inline | ||
3245 | 531 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | ||
3246 | 532 | INTEGER_IMPL(I)>::type | ||
3247 | 533 | operator/( INTEGER_IMPL(I) const &i, A n ) { | ||
3248 | 534 | return INTEGER_IMPL(I)( | ||
3249 | 535 | INTEGER_IMPL(I)::ftoi( i.value_ / INTEGER_IMPL(I)::cast( n ) ) | ||
3250 | 536 | ); | ||
3251 | 537 | } | ||
3252 | 538 | |||
3253 | 539 | TEMPLATE_DECL2(I,A) inline | ||
3254 | 540 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | ||
3255 | 541 | INTEGER_IMPL(I)>::type | ||
3256 | 542 | operator/( A n, INTEGER_IMPL(I) const &i ) { | ||
3257 | 543 | return INTEGER_IMPL(I)( | ||
3258 | 544 | INTEGER_IMPL(I)::ftoi( INTEGER_IMPL(I)::cast( n ) / i.value_ ) | ||
3259 | 545 | ); | ||
3260 | 476 | } | 546 | } |
3261 | 477 | 547 | ||
3262 | 478 | #define ZORBA_INTEGER_OP(OP) \ | 548 | #define ZORBA_INTEGER_OP(OP) \ |
3265 | 479 | TEMPLATE_DECL(T) inline \ | 549 | TEMPLATE_DECL(I) inline \ |
3266 | 480 | INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator OP( IntegerImpl const &i ) { \ | 550 | INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator OP( IntegerImpl const &i ) { \ |
3267 | 481 | value_ OP i.value_; \ | 551 | value_ OP i.value_; \ |
3268 | 482 | return *this; \ | 552 | return *this; \ |
3269 | 483 | } | 553 | } |
3270 | @@ -488,39 +558,62 @@ | |||
3271 | 488 | ZORBA_INTEGER_OP(%=) | 558 | ZORBA_INTEGER_OP(%=) |
3272 | 489 | #undef ZORBA_INTEGER_OP | 559 | #undef ZORBA_INTEGER_OP |
3273 | 490 | 560 | ||
3276 | 491 | TEMPLATE_DECL(T) | 561 | TEMPLATE_DECL(I) |
3277 | 492 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator/=( IntegerImpl const &i ) { | 562 | inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator/=( IntegerImpl const &i ) { |
3278 | 493 | value_ = ftoi( value_ / i.value_ ); | 563 | value_ = ftoi( value_ / i.value_ ); |
3279 | 494 | return *this; | 564 | return *this; |
3280 | 495 | } | 565 | } |
3281 | 496 | 566 | ||
3289 | 497 | TEMPLATE_DECL(T) | 567 | #define ZORBA_INTEGER_OP(OP) \ |
3290 | 498 | inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator-() const { | 568 | TEMPLATE_DECL(I) template<typename A> inline \ |
3291 | 499 | return -value_; | 569 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \ |
3292 | 500 | } | 570 | INTEGER_IMPL(I)&>::type \ |
3293 | 501 | 571 | INTEGER_IMPL(I)::operator OP( A n ) { \ | |
3294 | 502 | TEMPLATE_DECL(T) | 572 | value_ OP cast( n ); \ |
3295 | 503 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator++() { | 573 | return *this; \ |
3296 | 574 | } | ||
3297 | 575 | |||
3298 | 576 | ZORBA_INTEGER_OP(+=) | ||
3299 | 577 | ZORBA_INTEGER_OP(-=) | ||
3300 | 578 | ZORBA_INTEGER_OP(*=) | ||
3301 | 579 | ZORBA_INTEGER_OP(%=) | ||
3302 | 580 | #undef ZORBA_INTEGER_OP | ||
3303 | 581 | |||
3304 | 582 | TEMPLATE_DECL(I) template<typename A> inline | ||
3305 | 583 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, | ||
3306 | 584 | INTEGER_IMPL(I)&>::type | ||
3307 | 585 | INTEGER_IMPL(I)::operator/=( A n ) { | ||
3308 | 586 | value_ = ftoi( value_ / cast( n ) ); | ||
3309 | 587 | return *this; | ||
3310 | 588 | } | ||
3311 | 589 | |||
3312 | 590 | TEMPLATE_DECL(I) | ||
3313 | 591 | inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator-() const { | ||
3314 | 592 | return INTEGER_IMPL(I)( -value_ ); | ||
3315 | 593 | } | ||
3316 | 594 | |||
3317 | 595 | TEMPLATE_DECL(I) | ||
3318 | 596 | inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator++() { | ||
3319 | 504 | ++value_; | 597 | ++value_; |
3320 | 505 | return *this; | 598 | return *this; |
3321 | 506 | } | 599 | } |
3322 | 507 | 600 | ||
3326 | 508 | TEMPLATE_DECL(T) | 601 | TEMPLATE_DECL(I) |
3327 | 509 | inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator++(int) { | 602 | inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator++(int) { |
3328 | 510 | INTEGER_IMPL(T) const result( *this ); | 603 | INTEGER_IMPL(I) const result( *this ); |
3329 | 511 | ++value_; | 604 | ++value_; |
3330 | 512 | return result; | 605 | return result; |
3331 | 513 | } | 606 | } |
3332 | 514 | 607 | ||
3335 | 515 | TEMPLATE_DECL(T) | 608 | TEMPLATE_DECL(I) |
3336 | 516 | inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator--() { | 609 | inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator--() { |
3337 | 517 | --value_; | 610 | --value_; |
3338 | 518 | return *this; | 611 | return *this; |
3339 | 519 | } | 612 | } |
3340 | 520 | 613 | ||
3344 | 521 | TEMPLATE_DECL(T) | 614 | TEMPLATE_DECL(I) |
3345 | 522 | inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator--(int) { | 615 | inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator--(int) { |
3346 | 523 | INTEGER_IMPL(T) const result( *this ); | 616 | INTEGER_IMPL(I) const result( *this ); |
3347 | 524 | --value_; | 617 | --value_; |
3348 | 525 | return result; | 618 | return result; |
3349 | 526 | } | 619 | } |
3350 | @@ -528,8 +621,8 @@ | |||
3351 | 528 | ////////// relational operators /////////////////////////////////////////////// | 621 | ////////// relational operators /////////////////////////////////////////////// |
3352 | 529 | 622 | ||
3353 | 530 | #define ZORBA_INTEGER_OP(OP) \ | 623 | #define ZORBA_INTEGER_OP(OP) \ |
3356 | 531 | TEMPLATE_DECL(T) inline \ | 624 | TEMPLATE_DECL(I) inline \ |
3357 | 532 | bool operator OP( INTEGER_IMPL(T) const &i, INTEGER_IMPL(T) const &j ) { \ | 625 | bool operator OP( INTEGER_IMPL(I) const &i, INTEGER_IMPL(I) const &j ) { \ |
3358 | 533 | return i.value_ OP j.value_; \ | 626 | return i.value_ OP j.value_; \ |
3359 | 534 | } | 627 | } |
3360 | 535 | 628 | ||
3361 | @@ -541,6 +634,27 @@ | |||
3362 | 541 | ZORBA_INTEGER_OP(>=) | 634 | ZORBA_INTEGER_OP(>=) |
3363 | 542 | #undef ZORBA_INTEGER_OP | 635 | #undef ZORBA_INTEGER_OP |
3364 | 543 | 636 | ||
3365 | 637 | #define ZORBA_INTEGER_OP(OP) \ | ||
3366 | 638 | TEMPLATE_DECL2(I,A) inline \ | ||
3367 | 639 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \ | ||
3368 | 640 | operator OP( INTEGER_IMPL(I) const &i, A n ) { \ | ||
3369 | 641 | return i.value_ OP INTEGER_IMPL(I)::cast( n ); \ | ||
3370 | 642 | } \ | ||
3371 | 643 | \ | ||
3372 | 644 | TEMPLATE_DECL2(I,A) inline \ | ||
3373 | 645 | typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \ | ||
3374 | 646 | operator OP( A n, INTEGER_IMPL(I) const &i ) { \ | ||
3375 | 647 | return INTEGER_IMPL(I)::cast( n ) OP i.value_; \ | ||
3376 | 648 | } \ | ||
3377 | 649 | |||
3378 | 650 | ZORBA_INTEGER_OP(==) | ||
3379 | 651 | ZORBA_INTEGER_OP(!=) | ||
3380 | 652 | ZORBA_INTEGER_OP(< ) | ||
3381 | 653 | ZORBA_INTEGER_OP(<=) | ||
3382 | 654 | ZORBA_INTEGER_OP(> ) | ||
3383 | 655 | ZORBA_INTEGER_OP(>=) | ||
3384 | 656 | #undef ZORBA_INTEGER_OP | ||
3385 | 657 | |||
3386 | 544 | ////////// miscellaneous ////////////////////////////////////////////////////// | 658 | ////////// miscellaneous ////////////////////////////////////////////////////// |
3387 | 545 | 659 | ||
3388 | 546 | #ifdef ZORBA_WITH_BIG_INTEGER | 660 | #ifdef ZORBA_WITH_BIG_INTEGER |
3389 | @@ -555,31 +669,31 @@ | |||
3390 | 555 | 669 | ||
3391 | 556 | #else | 670 | #else |
3392 | 557 | 671 | ||
3395 | 558 | template<typename IntType> | 672 | template<typename I> |
3396 | 559 | inline int IntegerImpl<IntType>::compare( IntegerImpl const &i ) const { | 673 | inline int IntegerImpl<I>::compare( IntegerImpl const &i ) const { |
3397 | 560 | return value_ < i.value_ ? -1 : value_ > i.value_ ? 1 : 0; | 674 | return value_ < i.value_ ? -1 : value_ > i.value_ ? 1 : 0; |
3398 | 561 | } | 675 | } |
3399 | 562 | 676 | ||
3402 | 563 | template<typename IntType> | 677 | template<typename I> |
3403 | 564 | inline uint32_t IntegerImpl<IntType>::hash() const { | 678 | inline uint32_t IntegerImpl<I>::hash() const { |
3404 | 565 | return static_cast<uint32_t>( value_ ); | 679 | return static_cast<uint32_t>( value_ ); |
3405 | 566 | } | 680 | } |
3406 | 567 | 681 | ||
3409 | 568 | template<typename IntType> | 682 | template<typename I> |
3410 | 569 | inline bool IntegerImpl<IntType>::is_long() const { | 683 | inline bool IntegerImpl<I>::is_long() const { |
3411 | 570 | return value_ >= std::numeric_limits<long>::min() && | 684 | return value_ >= std::numeric_limits<long>::min() && |
3412 | 571 | value_ <= std::numeric_limits<long>::max(); | 685 | value_ <= std::numeric_limits<long>::max(); |
3413 | 572 | } | 686 | } |
3414 | 573 | 687 | ||
3417 | 574 | template<typename IntType> | 688 | template<typename I> |
3418 | 575 | inline int IntegerImpl<IntType>::sign() const { | 689 | inline int IntegerImpl<I>::sign() const { |
3419 | 576 | return ztd::lt0( value_ ) ? -1 : value_ > 0 ? 1 : 0; | 690 | return ztd::lt0( value_ ) ? -1 : value_ > 0 ? 1 : 0; |
3420 | 577 | } | 691 | } |
3421 | 578 | 692 | ||
3422 | 579 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 693 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3423 | 580 | 694 | ||
3426 | 581 | TEMPLATE_DECL(T) | 695 | TEMPLATE_DECL(I) |
3427 | 582 | inline std::ostream& operator<<( std::ostream &os, INTEGER_IMPL(T) const &i ) { | 696 | inline std::ostream& operator<<( std::ostream &os, INTEGER_IMPL(I) const &i ) { |
3428 | 583 | return os << i.toString(); | 697 | return os << i.toString(); |
3429 | 584 | } | 698 | } |
3430 | 585 | 699 |
Validation queue starting for merge proposal. zorbatest. lambda. nu:8080/ remotequeue/ bug-966355- 2012-04- 16T16-04- 19.631Z/ log.html
Log at: http://