Merge lp:~zorba-coders/zorba/bug-966355 into lp:zorba

Proposed by Paul J. Lucas
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
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_BIG_INTEGER=OFF).

Description of the change

Added operators for built-in types (when ZORBA_WITH_BIG_INTEGER=OFF).

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-to-construct (by comparison to a built-in arithmetic type) class object by "accident" by now forcing to you explicitly construct them.

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.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-966355-2012-04-16T16-04-19.631Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/annotations/annotations.h'
--- src/annotations/annotations.h 2012-03-30 19:03:09 +0000
+++ src/annotations/annotations.h 2012-04-16 15:38:09 +0000
@@ -83,7 +83,7 @@
83 };83 };
8484
85protected:85protected:
86 typedef std::bitset<zann_end + 1> RuleBitSet;86 typedef std::bitset<static_cast<int>(zann_end) + 1> RuleBitSet;
8787
88protected:88protected:
89 static std::vector<store::Item_t> theAnnotId2NameMap;89 static std::vector<store::Item_t> theAnnotId2NameMap;
9090
=== modified file 'src/compiler/rewriter/rules/flwor_rules.cpp'
--- src/compiler/rewriter/rules/flwor_rules.cpp 2012-04-05 18:06:01 +0000
+++ src/compiler/rewriter/rules/flwor_rules.cpp 2012-04-16 15:38:09 +0000
@@ -1037,7 +1037,7 @@
1037 err::XPTY0004);1037 err::XPTY0004);
10381038
1039 if (TypeOps::is_subtype(tm, *valType, *rtm.INTEGER_TYPE_ONE, posLoc) &&1039 if (TypeOps::is_subtype(tm, *valType, *rtm.INTEGER_TYPE_ONE, posLoc) &&
1040 val->getIntegerValue() >= xs_integer::one())1040 val->getIntegerValue() >= 1)
1041 {1041 {
1042 return true;1042 return true;
1043 }1043 }
10441044
=== modified file 'src/compiler/rewriter/rules/fold_rules.cpp'
--- src/compiler/rewriter/rules/fold_rules.cpp 2012-03-30 19:03:09 +0000
+++ src/compiler/rewriter/rules/fold_rules.cpp 2012-04-16 15:38:09 +0000
@@ -928,19 +928,19 @@
928 {928 {
929 xs_integer ival = val->getIntegerValue();929 xs_integer ival = val->getIntegerValue();
930930
931 if (ival < xs_integer::zero())931 if (ival < 0)
932 {932 {
933 if (!count_expr->isNonDiscardable())933 if (!count_expr->isNonDiscardable())
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);
935 }935 }
936 else if (ival == xs_integer::zero())936 else if (ival == 0)
937 {937 {
938 return expr_tools::fix_annotations(938 return expr_tools::fix_annotations(
939 new fo_expr(fo.get_sctx(), fo.get_loc(),939 new fo_expr(fo.get_sctx(), fo.get_loc(),
940 GET_BUILTIN_FUNCTION(FN_EMPTY_1),940 GET_BUILTIN_FUNCTION(FN_EMPTY_1),
941 count_expr->get_arg(0)));941 count_expr->get_arg(0)));
942 }942 }
943 else if (ival == xs_integer::one())943 else if (ival == 1)
944 {944 {
945 return expr_tools::fix_annotations(945 return expr_tools::fix_annotations(
946 new fo_expr(fo.get_sctx(),946 new fo_expr(fo.get_sctx(),
947947
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2012-04-12 02:08:10 +0000
+++ src/compiler/translator/translator.cpp 2012-04-16 15:38:09 +0000
@@ -9754,8 +9754,8 @@
9754 {9754 {
9755 case FunctionConsts::FN_HEAD_1:9755 case FunctionConsts::FN_HEAD_1:
9756 {9756 {
9757 arguments.push_back(new const_expr(theRootSctx, loc, xs_integer(1)));9757 arguments.push_back(new const_expr(theRootSctx, loc, xs_integer::one()));
9758 arguments.push_back(new const_expr(theRootSctx, loc, xs_integer(1)));9758 arguments.push_back(new const_expr(theRootSctx, loc, xs_integer::one()));
9759 function* f = GET_BUILTIN_FUNCTION(OP_ZORBA_SUBSEQUENCE_INT_3);9759 function* f = GET_BUILTIN_FUNCTION(OP_ZORBA_SUBSEQUENCE_INT_3);
9760 fo_expr_t foExpr = new fo_expr(theRootSctx, loc, f, arguments);9760 fo_expr_t foExpr = new fo_expr(theRootSctx, loc, f, arguments);
9761 normalize_fo(foExpr);9761 normalize_fo(foExpr);
97629762
=== modified file 'src/runtime/collections/collections_impl.cpp'
--- src/runtime/collections/collections_impl.cpp 2012-04-14 06:12:29 +0000
+++ src/runtime/collections/collections_impl.cpp 2012-04-16 15:38:09 +0000
@@ -451,7 +451,7 @@
451{451{
452 store::Collection_t collection;452 store::Collection_t collection;
453 store::Item_t node;453 store::Item_t node;
454 xs_integer pos = 1;454 xs_integer pos( 1 );
455 bool found;455 bool found;
456456
457 PlanIteratorState* state;457 PlanIteratorState* state;
@@ -466,8 +466,7 @@
466466
467 found = collection->findNode(node, pos);467 found = collection->findNode(node, pos);
468 ZORBA_ASSERT(found);468 ZORBA_ASSERT(found);
469 STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, pos+xs_integer(1)),469 STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, pos+1), state);
470 state);
471 }470 }
472471
473 STACK_END (state);472 STACK_END (state);
@@ -1638,7 +1637,7 @@
1638 const StaticallyKnownCollection* collectionDecl;1637 const StaticallyKnownCollection* collectionDecl;
1639 store::Item_t collectionName;1638 store::Item_t collectionName;
1640 store::Item_t numNodesItem;1639 store::Item_t numNodesItem;
1641 xs_integer numNodes = 1;1640 xs_integer numNodes( 1 );
1642 std::vector<store::Item_t> nodes;1641 std::vector<store::Item_t> nodes;
1643 std::auto_ptr<store::PUL> pul;1642 std::auto_ptr<store::PUL> pul;
16441643
@@ -1674,7 +1673,7 @@
1674 // create the pul and add the primitive1673 // create the pul and add the primitive
1675 pul.reset(GENV_ITEMFACTORY->createPendingUpdateList());1674 pul.reset(GENV_ITEMFACTORY->createPendingUpdateList());
16761675
1677 for (xs_integer i = 0; i < numNodes; ++i)1676 for (xs_integer i( 0 ); i < numNodes; ++i)
1678 nodes.push_back(collection->nodeAt(i));1677 nodes.push_back(collection->nodeAt(i));
16791678
1680 pul->addDeleteFromCollection(&loc, collectionName, nodes, false, theDynamicCollection);1679 pul->addDeleteFromCollection(&loc, collectionName, nodes, false, theDynamicCollection);
@@ -1762,7 +1761,7 @@
1762 const StaticallyKnownCollection* collectionDecl;1761 const StaticallyKnownCollection* collectionDecl;
1763 store::Item_t collectionName;1762 store::Item_t collectionName;
1764 store::Item_t numNodesItem;1763 store::Item_t numNodesItem;
1765 xs_integer numNodes = 1;1764 xs_integer numNodes( 1 );
1766 std::vector<store::Item_t> nodes;1765 std::vector<store::Item_t> nodes;
1767 std::auto_ptr<store::PUL> pul;1766 std::auto_ptr<store::PUL> pul;
17681767
@@ -1796,7 +1795,7 @@
1796 // create the pul and add the primitive1795 // create the pul and add the primitive
1797 pul.reset(GENV_ITEMFACTORY->createPendingUpdateList());1796 pul.reset(GENV_ITEMFACTORY->createPendingUpdateList());
17981797
1799 for (xs_integer i = numNodes; i > xs_integer(0); --i)1798 for (xs_integer i = numNodes; i > 0; --i)
1800 nodes.push_back(collection->nodeAt(collection->size() - i));1799 nodes.push_back(collection->nodeAt(collection->size() - i));
18011800
1802 pul->addDeleteFromCollection(&loc, collectionName, nodes, true, theDynamicCollection);1801 pul->addDeleteFromCollection(&loc, collectionName, nodes, true, theDynamicCollection);
18031802
=== modified file 'src/runtime/core/gflwor/window_iterator.cpp'
--- src/runtime/core/gflwor/window_iterator.cpp 2012-04-09 23:08:06 +0000
+++ src/runtime/core/gflwor/window_iterator.cpp 2012-04-16 15:38:09 +0000
@@ -150,7 +150,7 @@
150150
151 if (!theCurVars.empty())151 if (!theCurVars.empty())
152 {152 {
153 aInputSeq->getItem(aPosition, lItem);153 aInputSeq->getItem(xs_integer(aPosition), lItem);
154 bindVariables(lItem, theCurVars, aPlanState);154 bindVariables(lItem, theCurVars, aPlanState);
155 }155 }
156156
@@ -158,7 +158,7 @@
158 {158 {
159 if (aPosition > 1)159 if (aPosition > 1)
160 {160 {
161 aInputSeq->getItem(aPosition - 1, lItem);161 aInputSeq->getItem(xs_integer(aPosition - 1), lItem);
162 }162 }
163 else163 else
164 {164 {
@@ -170,9 +170,9 @@
170170
171 if (!theNextVars.empty())171 if (!theNextVars.empty())
172 {172 {
173 if (aInputSeq->containsItem(aPosition + 1))173 if (aInputSeq->containsItem(xs_integer(aPosition + 1)))
174 {174 {
175 aInputSeq->getItem(aPosition + 1, lItem);175 aInputSeq->getItem(xs_integer(aPosition + 1), lItem);
176 }176 }
177 else177 else
178 {178 {
@@ -185,7 +185,7 @@
185 if (!thePosVars.empty())185 if (!thePosVars.empty())
186 {186 {
187 store::Item_t lPosItem;187 store::Item_t lPosItem;
188 GENV_ITEMFACTORY->createInteger(lPosItem, Integer(aPosition));188 GENV_ITEMFACTORY->createInteger(lPosItem, xs_integer(aPosition));
189 bindVariables(lPosItem, thePosVars, aPlanState);189 bindVariables(lPosItem, thePosVars, aPlanState);
190 }190 }
191}191}
@@ -208,7 +208,7 @@
208208
209 if (!theCurOuterVars.empty())209 if (!theCurOuterVars.empty())
210 {210 {
211 aInputSeq->getItem(aPosition, lItem);211 aInputSeq->getItem(xs_integer(aPosition), lItem);
212 bindVariables(lItem, theCurOuterVars, aPlanState);212 bindVariables(lItem, theCurOuterVars, aPlanState);
213 }213 }
214214
@@ -216,7 +216,7 @@
216 {216 {
217 if (aPosition > 1)217 if (aPosition > 1)
218 {218 {
219 aInputSeq->getItem(aPosition - 1, lItem);219 aInputSeq->getItem(xs_integer(aPosition - 1), lItem);
220 }220 }
221 else221 else
222 {222 {
@@ -228,9 +228,9 @@
228228
229 if (!theNextOuterVars.empty())229 if (!theNextOuterVars.empty())
230 {230 {
231 if (aInputSeq->containsItem(aPosition + 1))231 if (aInputSeq->containsItem(xs_integer(aPosition + 1)))
232 {232 {
233 aInputSeq->getItem(aPosition + 1, lItem);233 aInputSeq->getItem(xs_integer(aPosition + 1), lItem);
234 }234 }
235 else235 else
236 {236 {
@@ -716,11 +716,14 @@
716 ulong aStartPos,716 ulong aStartPos,
717 ulong aEndPos) const717 ulong aEndPos) const
718{718{
719 xs_integer const lStartPos( aStartPos );
720 xs_integer const lEndPos( aEndPos );
721
719 for (std::vector<LetVarIter_t>::const_iterator lVarIter = theVarRefs.begin();722 for (std::vector<LetVarIter_t>::const_iterator lVarIter = theVarRefs.begin();
720 lVarIter != theVarRefs.end();723 lVarIter != theVarRefs.end();
721 ++lVarIter)724 ++lVarIter)
722 {725 {
723 (*lVarIter)->bind(aInputSeq, aPlanState, aStartPos, aEndPos);726 (*lVarIter)->bind(aInputSeq, aPlanState, lStartPos, lEndPos);
724 }727 }
725}728}
726729
@@ -736,13 +739,13 @@
736 if (lState->theOpenWindows.empty())739 if (lState->theOpenWindows.empty())
737 {740 {
738 if (lState->theCurInputPos > theMaxNeededHistory)741 if (lState->theCurInputPos > theMaxNeededHistory)
739 lState->theDomainSeq->purgeUpTo(lState->theCurInputPos - theMaxNeededHistory);742 lState->theDomainSeq->purgeUpTo(xs_integer(lState->theCurInputPos - theMaxNeededHistory));
740 }743 }
741 else744 else
742 {745 {
743 int32_t lPurgeTo = lState->theOpenWindows.front().theStartPos - theMaxNeededHistory;746 int32_t lPurgeTo = lState->theOpenWindows.front().theStartPos - theMaxNeededHistory;
744 if (lPurgeTo > 0)747 if (lPurgeTo > 0)
745 lState->theDomainSeq->purgeUpTo(lPurgeTo);748 lState->theDomainSeq->purgeUpTo(xs_integer(lPurgeTo));
746 }749 }
747 }750 }
748}751}
@@ -769,7 +772,8 @@
769 if (theWindowType == WindowIterator::SLIDING)772 if (theWindowType == WindowIterator::SLIDING)
770 {773 {
771 // Get the next item from the domain sequence774 // Get the next item from the domain sequence
772 while (lState->theDomainSeq->containsItem(lState->theCurInputPos))775 // TODO: can the xs_integer be hoisted?
776 while (lState->theDomainSeq->containsItem(xs_integer(lState->theCurInputPos)))
773 {777 {
774 // If the current item satisfies the start condition, create a candidate778 // If the current item satisfies the start condition, create a candidate
775 // window starting at the current domain item.779 // window starting at the current domain item.
@@ -857,7 +861,8 @@
857 // Doing this switch now also avoids further overhad861 // Doing this switch now also avoids further overhad
858 if (theEndClause.theHasEndClause)862 if (theEndClause.theHasEndClause)
859 {863 {
860 while (lState->theDomainSeq->containsItem(lState->theCurInputPos))864 // TODO: can the xs_integer be hoisted?
865 while (lState->theDomainSeq->containsItem(xs_integer(lState->theCurInputPos)))
861 {866 {
862 if (lState->theOpenWindows.empty() &&867 if (lState->theOpenWindows.empty() &&
863 theStartClause.evaluate(aPlanState,868 theStartClause.evaluate(aPlanState,
@@ -898,7 +903,8 @@
898 }903 }
899 else904 else
900 {905 {
901 while (lState->theDomainSeq->containsItem(lState->theCurInputPos))906 // TODO: can the xs_integer be hoisted?
907 while (lState->theDomainSeq->containsItem(xs_integer(lState->theCurInputPos)))
902 {908 {
903 if (theStartClause.evaluate(aPlanState,909 if (theStartClause.evaluate(aPlanState,
904 lState->theDomainSeq,910 lState->theDomainSeq,
905911
=== modified file 'src/runtime/core/trycatch.cpp'
--- src/runtime/core/trycatch.cpp 2012-04-09 23:08:06 +0000
+++ src/runtime/core/trycatch.cpp 2012-04-16 15:38:09 +0000
@@ -274,7 +274,8 @@
274274
275 // function arity275 // function arity
276 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;276 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
277 GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getFnArity() );277 GENV_ITEMFACTORY->createInteger(
278 lTmpValue, xs_integer(lIter->getFnArity()));
278 GENV_ITEMFACTORY->createAttributeNode(279 GENV_ITEMFACTORY->createAttributeNode(
279 lTmpAttr, lFunction.getp(), lArityQName, lTypeName,280 lTmpAttr, lFunction.getp(), lArityQName, lTypeName,
280 lTmpValue);281 lTmpValue);
@@ -289,28 +290,31 @@
289290
290 // location line begin291 // location line begin
291 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;292 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
292 GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getLine() );293 GENV_ITEMFACTORY->createInteger( lTmpValue, xs_integer(lIter->getLine()) );
293 GENV_ITEMFACTORY->createAttributeNode(294 GENV_ITEMFACTORY->createAttributeNode(
294 lTmpAttr, lLocation.getp(), lLineBeginQName, lTypeName,295 lTmpAttr, lLocation.getp(), lLineBeginQName, lTypeName,
295 lTmpValue);296 lTmpValue);
296297
297 // location line end298 // location line end
298 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;299 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
299 GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getLineEnd() );300 GENV_ITEMFACTORY->createInteger(
301 lTmpValue, xs_integer(lIter->getLineEnd()));
300 GENV_ITEMFACTORY->createAttributeNode(302 GENV_ITEMFACTORY->createAttributeNode(
301 lTmpAttr, lLocation.getp(), lLineEndQName, lTypeName,303 lTmpAttr, lLocation.getp(), lLineEndQName, lTypeName,
302 lTmpValue);304 lTmpValue);
303305
304 // location column begin306 // location column begin
305 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;307 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
306 GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getColumn() );308 GENV_ITEMFACTORY->createInteger(
309 lTmpValue, xs_integer(lIter->getColumn()));
307 GENV_ITEMFACTORY->createAttributeNode(310 GENV_ITEMFACTORY->createAttributeNode(
308 lTmpAttr, lLocation.getp(), lColumnBeginQName, lTypeName,311 lTmpAttr, lLocation.getp(), lColumnBeginQName, lTypeName,
309 lTmpValue);312 lTmpValue);
310313
311 // location column end314 // location column end
312 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;315 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
313 GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getColumnEnd() );316 GENV_ITEMFACTORY->createInteger(
317 lTmpValue, xs_integer(lIter->getColumnEnd()));
314 GENV_ITEMFACTORY->createAttributeNode(318 GENV_ITEMFACTORY->createAttributeNode(
315 lTmpAttr, lLocation.getp(), lColumnEndQName, lTypeName,319 lTmpAttr, lLocation.getp(), lColumnEndQName, lTypeName,
316 lTmpValue);320 lTmpValue);
@@ -446,7 +450,8 @@
446 if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) &&450 if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) &&
447 ue->has_source() ) {451 ue->has_source() ) {
448 store::Item_t lErrorLineItem;452 store::Item_t lErrorLineItem;
449 GENV_ITEMFACTORY->createInteger(lErrorLineItem, ue->source_line());453 GENV_ITEMFACTORY->createInteger(
454 lErrorLineItem, xs_integer(ue->source_line()));
450 lErrorLineIter = new ItemIterator(lErrorLineItem);455 lErrorLineIter = new ItemIterator(lErrorLineItem);
451 }456 }
452 else457 else
@@ -472,7 +477,8 @@
472 if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) &&477 if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) &&
473 ue->has_source() ) {478 ue->has_source() ) {
474 store::Item_t lErrorColumnItem;479 store::Item_t lErrorColumnItem;
475 GENV_ITEMFACTORY->createInteger(lErrorColumnItem, ue->source_column());480 GENV_ITEMFACTORY->createInteger(
481 lErrorColumnItem, xs_integer(ue->source_column()));
476 lErrorColumnIter = new ItemIterator(lErrorColumnItem);482 lErrorColumnIter = new ItemIterator(lErrorColumnItem);
477 }483 }
478 else484 else
479485
=== modified file 'src/runtime/maths/maths_impl.cpp'
--- src/runtime/maths/maths_impl.cpp 2012-03-30 19:03:09 +0000
+++ src/runtime/maths/maths_impl.cpp 2012-04-16 15:38:09 +0000
@@ -500,7 +500,7 @@
500 PlanIteratorState* state;500 PlanIteratorState* state;
501 DEFAULT_STACK_INIT ( PlanIteratorState, state, planState );501 DEFAULT_STACK_INIT ( PlanIteratorState, state, planState );
502502
503 GENV_ITEMFACTORY->createDouble(result, 3.141592653589793e0);503 GENV_ITEMFACTORY->createDouble(result, xs_double(3.141592653589793e0));
504 STACK_PUSH (true, state);504 STACK_PUSH (true, state);
505505
506 STACK_END (state);506 STACK_END (state);
507507
=== modified file 'src/runtime/numerics/format_integer_impl.cpp'
--- src/runtime/numerics/format_integer_impl.cpp 2012-03-30 19:03:09 +0000
+++ src/runtime/numerics/format_integer_impl.cpp 2012-04-16 15:38:09 +0000
@@ -164,8 +164,8 @@
164 static const unsigned int letter_range = 'Z' - 'A' + 1;164 static const unsigned int letter_range = 'Z' - 'A' + 1;
165 static xs_integer integer_digit(letter_range);165 static xs_integer integer_digit(letter_range);
166 xs_integer upper_int = valueInteger/integer_digit;166 xs_integer upper_int = valueInteger/integer_digit;
167 if(upper_int > xs_integer::zero())167 if(upper_int > 0)
168 formatIntegerAZ(upper_int - xs_integer::one(), c0, resultString);168 formatIntegerAZ(upper_int - 1, c0, resultString);
169 xs_integer mod_integer = valueInteger % integer_digit;169 xs_integer mod_integer = valueInteger % integer_digit;
170 xs_int mod_int = to_xs_int(mod_integer);170 xs_int mod_int = to_xs_int(mod_integer);
171 resultString += (c0 + mod_int);171 resultString += (c0 + mod_int);
@@ -426,7 +426,7 @@
426 formatIntegerEnglish(valueInteger/integer_##big_number_name, false, resultString); \426 formatIntegerEnglish(valueInteger/integer_##big_number_name, false, resultString); \
427 resultString += " " #big_number_name; \427 resultString += " " #big_number_name; \
428 value_mod = valueInteger % integer_##big_number_name; \428 value_mod = valueInteger % integer_##big_number_name; \
429 if(value_mod > xs_integer::zero()) \429 if(value_mod > 0) \
430 { \430 { \
431 resultString += " "; \431 resultString += " "; \
432 formatIntegerEnglish(value_mod, is_ordinal, resultString); \432 formatIntegerEnglish(value_mod, is_ordinal, resultString); \
@@ -439,7 +439,7 @@
439 else if (valueInteger >= integer_##decim) \439 else if (valueInteger >= integer_##decim) \
440 { \440 { \
441 value_mod = valueInteger % integer_##decim; \441 value_mod = valueInteger % integer_##decim; \
442 if(value_mod > xs_integer::zero()) \442 if(value_mod > 0) \
443 { \443 { \
444 resultString += decim_cardinal; \444 resultString += decim_cardinal; \
445 resultString += "-"; \445 resultString += "-"; \
@@ -504,7 +504,7 @@
504 IF_GE_DECIM(3, "three", "third")504 IF_GE_DECIM(3, "three", "third")
505 IF_GE_DECIM(2, "two", "second")505 IF_GE_DECIM(2, "two", "second")
506 IF_GE_DECIM(1, "one", "first")506 IF_GE_DECIM(1, "one", "first")
507 else if (valueInteger == xs_integer::zero())507 else if (valueInteger == 0)
508 {508 {
509 if(!is_ordinal)509 if(!is_ordinal)
510 resultString += "zero";510 resultString += "zero";
@@ -771,7 +771,7 @@
771 if (consumeNext(value_item, theChildren[0].getp(), planState))771 if (consumeNext(value_item, theChildren[0].getp(), planState))
772 {772 {
773 valueInteger = value_item->getIntegerValue();773 valueInteger = value_item->getIntegerValue();
774 if(valueInteger < xs_integer::zero())774 if(valueInteger < 0)
775 {775 {
776 valueInteger = -valueInteger;776 valueInteger = -valueInteger;
777 is_neg = true;777 is_neg = true;
@@ -811,17 +811,17 @@
811 if((c0 == 'a') || (c0 == 'A'))811 if((c0 == 'a') || (c0 == 'A'))
812 {812 {
813 checkOptionalModifier(utf8_picture, 1, &is_ordinal, &is_traditional, utf8_word_terminal);813 checkOptionalModifier(utf8_picture, 1, &is_ordinal, &is_traditional, utf8_word_terminal);
814 if(valueInteger > xs_integer::zero())814 if(valueInteger > 0)
815 {815 {
816 if(is_neg)816 if(is_neg)
817 resultString += '-';817 resultString += '-';
818 formatIntegerAZ(valueInteger-xs_integer::one(), c0, resultString);818 formatIntegerAZ(valueInteger-1, c0, resultString);
819 }819 }
820 }820 }
821 else if((c0 == 'i') || (c0 == 'I'))821 else if((c0 == 'i') || (c0 == 'I'))
822 {822 {
823 checkOptionalModifier(utf8_picture, 1, &is_ordinal, &is_traditional, utf8_word_terminal);823 checkOptionalModifier(utf8_picture, 1, &is_ordinal, &is_traditional, utf8_word_terminal);
824 if(valueInteger > xs_integer::zero())824 if(valueInteger > 0)
825 {825 {
826 if(is_neg)826 if(is_neg)
827 resultString += ("-");827 resultString += ("-");
828828
=== modified file 'src/runtime/random/random_impl.cpp'
--- src/runtime/random/random_impl.cpp 2012-03-30 19:03:09 +0000
+++ src/runtime/random/random_impl.cpp 2012-04-16 15:38:09 +0000
@@ -45,7 +45,7 @@
4545
46 consumeNext(seed, theChildren[0].getp(), planState);46 consumeNext(seed, theChildren[0].getp(), planState);
47 consumeNext(num, theChildren[1].getp(), planState);47 consumeNext(num, theChildren[1].getp(), planState);
48 if ( num->getIntegerValue() < xs_integer( 0 ) ) 48 if ( num->getIntegerValue() < 0 )
49 {49 {
50 STACK_PUSH(false, state);50 STACK_PUSH(false, state);
51 }51 }
@@ -110,7 +110,7 @@
110 DEFAULT_STACK_INIT(RandomIteratorState, state, planState);110 DEFAULT_STACK_INIT(RandomIteratorState, state, planState);
111111
112 consumeNext(num, theChildren[0].getp(), planState);112 consumeNext(num, theChildren[0].getp(), planState);
113 if ( num->getIntegerValue() < xs_integer( 0 ) ) 113 if ( num->getIntegerValue() < 0 )
114 {114 {
115 STACK_PUSH(false, state);115 STACK_PUSH(false, state);
116 }116 }
117117
=== modified file 'src/runtime/sequences/sequences_impl.cpp'
--- src/runtime/sequences/sequences_impl.cpp 2012-03-30 19:03:09 +0000
+++ src/runtime/sequences/sequences_impl.cpp 2012-04-16 15:38:09 +0000
@@ -322,12 +322,12 @@
322 }322 }
323323
324 state->thePosition = lPositionItem->getIntegerValue();324 state->thePosition = lPositionItem->getIntegerValue();
325 if (state->thePosition < xs_integer::one())325 if (state->thePosition < 1)
326 state->thePosition = xs_integer::one();326 state->thePosition = 1;
327327
328 while (consumeNext(result, theChildren[0].getp(), planState))328 while (consumeNext(result, theChildren[0].getp(), planState))
329 {329 {
330 if ( state->theCurrentPos == state->thePosition-xs_integer::one() ) // position found => insert sequence330 if ( state->theCurrentPos == state->thePosition-1 ) // position found => insert sequence
331 {331 {
332 state->theTargetItem = result;332 state->theTargetItem = result;
333 while ( consumeNext(result, theChildren[2].getp(), planState))333 while ( consumeNext(result, theChildren[2].getp(), planState))
334334
=== modified file 'src/runtime/store/maps_impl.cpp'
--- src/runtime/store/maps_impl.cpp 2012-03-30 19:03:09 +0000
+++ src/runtime/store/maps_impl.cpp 2012-04-16 15:38:09 +0000
@@ -540,7 +540,7 @@
540 );540 );
541 }541 }
542542
543 GENV_ITEMFACTORY->createInteger(result, lIndex->size());543 GENV_ITEMFACTORY->createInteger(result, xs_integer(lIndex->size()));
544544
545 STACK_PUSH(true, state);545 STACK_PUSH(true, state);
546546
547547
=== modified file 'src/store/naive/atomic_items.cpp'
--- src/store/naive/atomic_items.cpp 2012-03-30 19:03:09 +0000
+++ src/store/naive/atomic_items.cpp 2012-04-16 15:38:09 +0000
@@ -1472,7 +1472,7 @@
1472store::Item_t StructuralAnyUriItem::getLevel() const1472store::Item_t StructuralAnyUriItem::getLevel() const
1473{1473{
1474 store::Item_t lResult;1474 store::Item_t lResult;
1475 GET_FACTORY().createInteger(lResult, theOrdPath.getLevel());1475 GET_FACTORY().createInteger(lResult, xs_integer(theOrdPath.getLevel()));
1476 return lResult;1476 return lResult;
1477}1477}
14781478
@@ -2747,7 +2747,7 @@
2747}2747}
27482748
2749xs_nonNegativeInteger LongItem::getUnsignedIntegerValue() const {2749xs_nonNegativeInteger LongItem::getUnsignedIntegerValue() const {
2750 return theValue >= 0 ? theValue : -theValue;2750 return xs_nonNegativeInteger( theValue >= 0 ? theValue : -theValue );
2751}2751}
27522752
2753store::Item* LongItem::getType() const2753store::Item* LongItem::getType() const
27542754
=== modified file 'src/store/naive/collection.h'
--- src/store/naive/collection.h 2012-03-28 23:58:23 +0000
+++ src/store/naive/collection.h 2012-04-16 15:38:09 +0000
@@ -65,7 +65,7 @@
6565
66 /************************* Updates on collection ****************************/66 /************************* Updates on collection ****************************/
6767
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;
6969
70 virtual zorba::xs_integer addNodes(70 virtual zorba::xs_integer addNodes(
71 std::vector<store::Item_t>& nodes,71 std::vector<store::Item_t>& nodes,
7272
=== modified file 'src/store/naive/node_items.cpp'
--- src/store/naive/node_items.cpp 2012-04-12 02:08:10 +0000
+++ src/store/naive/node_items.cpp 2012-04-16 15:38:09 +0000
@@ -1294,7 +1294,7 @@
1294 lCurrent = lCurrent->getParent();1294 lCurrent = lCurrent->getParent();
1295 }1295 }
1296 store::Item_t lRes;1296 store::Item_t lRes;
1297 GET_FACTORY().createInteger(lRes, lNumLevels);1297 GET_FACTORY().createInteger(lRes, xs_integer(lNumLevels));
1298 return lRes;1298 return lRes;
1299}1299}
13001300
13011301
=== modified file 'src/store/naive/pul_primitives.cpp'
--- src/store/naive/pul_primitives.cpp 2012-03-30 19:03:09 +0000
+++ src/store/naive/pul_primitives.cpp 2012-04-16 15:38:09 +0000
@@ -986,7 +986,7 @@
986986
987 for (uint64_t i = 0; i < size; ++i)987 for (uint64_t i = 0; i < size; ++i)
988 {988 {
989 XmlNode* root = static_cast<XmlNode*>(collection->nodeAt(i).getp());989 XmlNode* root = static_cast<XmlNode*>(collection->nodeAt(xs_integer(i)).getp());
990 XmlTree* tree = root->getTree();990 XmlTree* tree = root->getTree();
991 if (tree->getRefCount() > 1)991 if (tree->getRefCount() > 1)
992 throw XQUERY_EXCEPTION(992 throw XQUERY_EXCEPTION(
@@ -1021,7 +1021,7 @@
1021 std::size_t numNodes = theNodes.size();1021 std::size_t numNodes = theNodes.size();
1022 for (std::size_t i = 0; i < numNodes; ++i)1022 for (std::size_t i = 0; i < numNodes; ++i)
1023 {1023 {
1024 lColl->addNode(theNodes[i], -1);1024 lColl->addNode(theNodes[i], xs_integer(-1));
1025 ++theNumApplied;1025 ++theNumApplied;
1026 }1026 }
1027}1027}
@@ -1051,9 +1051,10 @@
10511051
1052 for (long i = theNumApplied-1; i >= 0; --i)1052 for (long i = theNumApplied-1; i >= 0; --i)
1053 {1053 {
1054 ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(lastPos));1054 xs_integer xs_lastPos( lastPos );
1055 ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(xs_lastPos));
10551056
1056 lColl->removeNode(lastPos);1057 lColl->removeNode(xs_lastPos);
1057 --lastPos;1058 --lastPos;
1058 }1059 }
1059}1060}
@@ -1075,7 +1076,7 @@
1075 std::size_t numNodes = theNodes.size();1076 std::size_t numNodes = theNodes.size();
1076 for (std::size_t i = 0; i < numNodes; ++i)1077 for (std::size_t i = 0; i < numNodes; ++i)
1077 {1078 {
1078 lColl->addNode(theNodes[i], i);1079 lColl->addNode(theNodes[i], xs_integer(i));
1079 ++theNumApplied;1080 ++theNumApplied;
1080 }1081 }
1081}1082}
@@ -1087,11 +1088,12 @@
1087 (GET_STORE().getCollection(theName, theDynamicCollection).getp());1088 (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1088 assert(lColl);1089 assert(lColl);
10891090
1091 xs_integer const zero( xs_integer::zero() );
1090 for (std::size_t i = 0; i < theNumApplied; ++i)1092 for (std::size_t i = 0; i < theNumApplied; ++i)
1091 {1093 {
1092 ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(0));1094 ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(zero));
10931095
1094 lColl->removeNode((uint64_t)0);1096 lColl->removeNode(zero);
1095 }1097 }
1096}1098}
10971099
@@ -1108,9 +1110,10 @@
1108 theIsApplied = true;1110 theIsApplied = true;
11091111
1110 std::size_t numNodes = theNodes.size();1112 std::size_t numNodes = theNodes.size();
1113 xs_integer const neg_1( -1 );
1111 for (std::size_t i = 0; i < numNodes; ++i)1114 for (std::size_t i = 0; i < numNodes; ++i)
1112 {1115 {
1113 lColl->addNode(theNodes[i], -1);1116 lColl->addNode(theNodes[i], neg_1);
1114 }1117 }
1115}1118}
11161119
@@ -1135,11 +1138,12 @@
1135 );1138 );
1136 }1139 }
11371140
1141 xs_integer const xs_lastPos( lastPos );
1138 for (long i = theNumApplied-1; i >= 0; --i)1142 for (long i = theNumApplied-1; i >= 0; --i)
1139 {1143 {
1140 ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(lastPos));1144 ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(xs_lastPos));
11411145
1142 lColl->removeNode(lastPos);1146 lColl->removeNode(xs_lastPos);
1143 }1147 }
1144}1148}
11451149
@@ -1170,7 +1174,7 @@
1170 assert(lColl);1174 assert(lColl);
1171 ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos));1175 ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos));
11721176
1173 lColl->removeNodes(theFirstPos, (uint64_t)theNodes.size());1177 lColl->removeNodes(theFirstPos, xs_integer(theNodes.size()));
1174}1178}
11751179
11761180
@@ -1201,7 +1205,7 @@
1201 assert(lColl);1205 assert(lColl);
1202 ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos));1206 ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos));
12031207
1204 lColl->removeNodes(theFirstPos, (uint64_t)theNodes.size());1208 lColl->removeNodes(theFirstPos, xs_integer(theNodes.size()));
1205}1209}
12061210
12071211
@@ -1240,7 +1244,7 @@
1240 {1244 {
1241 for (std::size_t i = numNodes; i > 0; --i)1245 for (std::size_t i = numNodes; i > 0; --i)
1242 {1246 {
1243 if (theNodes[i-1] != lColl->nodeAt(size - i))1247 if (theNodes[i-1] != lColl->nodeAt(xs_integer(size - i)))
1244 {1248 {
1245 isLast = false;1249 isLast = false;
1246 break;1250 break;
12471251
=== modified file 'src/store/naive/simple_collection.cpp'
--- src/store/naive/simple_collection.cpp 2012-03-30 19:03:09 +0000
+++ src/store/naive/simple_collection.cpp 2012-04-16 15:38:09 +0000
@@ -124,16 +124,16 @@
124124
125 SYNC_CODE(AutoLatch lock(theLatch, Latch::WRITE););125 SYNC_CODE(AutoLatch lock(theLatch, Latch::WRITE););
126126
127 if (lPosition < 0 || to_xs_unsignedLong(lPosition) >= theXmlTrees.size())127 if (lPosition < 0 || lPosition >= theXmlTrees.size())
128 {128 {
129 theXmlTrees.push_back(nodeItem);129 theXmlTrees.push_back(nodeItem);
130 node->setCollection(this, (uint64_t)theXmlTrees.size() - 1);130 node->setCollection(this, xs_integer(theXmlTrees.size() - 1));
131 }131 }
132 else132 else
133 {133 {
134134
135 theXmlTrees.insert(theXmlTrees.begin() + (std::size_t)lPosition, nodeItem);135 theXmlTrees.insert(theXmlTrees.begin() + (std::size_t)lPosition, nodeItem);
136 node->setCollection(this, to_xs_unsignedInt(lPosition));136 node->setCollection(this, xs_integer(lPosition));
137 }137 }
138}138}
139139
@@ -203,7 +203,7 @@
203 );203 );
204 }204 }
205 205
206 node->setCollection(this, lTargetPos + i);206 node->setCollection(this, xs_integer(lTargetPos + i));
207 }207 }
208208
209 theXmlTrees.resize(numNodes + numNewNodes);209 theXmlTrees.resize(numNodes + numNewNodes);
@@ -232,7 +232,7 @@
232 theXmlTrees[lTargetPos + i].transfer(nodes[i]);232 theXmlTrees[lTargetPos + i].transfer(nodes[i]);
233 }233 }
234234
235 return lTargetPos;235 return xs_integer( lTargetPos );
236}236}
237237
238238
@@ -261,7 +261,7 @@
261 {261 {
262 ZORBA_ASSERT(node->getCollection() == this);262 ZORBA_ASSERT(node->getCollection() == this);
263263
264 node->setCollection(NULL, 0);264 node->setCollection(NULL, xs_integer(0));
265 std::size_t lPosition = to_xs_unsignedInt(position);265 std::size_t lPosition = to_xs_unsignedInt(position);
266 theXmlTrees.erase(theXmlTrees.begin() + lPosition);266 theXmlTrees.erase(theXmlTrees.begin() + lPosition);
267 return true;267 return true;
@@ -292,7 +292,7 @@
292 XmlNode* node = static_cast<XmlNode*>(theXmlTrees[lPosition].getp());292 XmlNode* node = static_cast<XmlNode*>(theXmlTrees[lPosition].getp());
293 ZORBA_ASSERT(node->getCollection() == this);293 ZORBA_ASSERT(node->getCollection() == this);
294294
295 node->setCollection(NULL, 0);295 node->setCollection(NULL, xs_integer(0));
296 theXmlTrees.erase(theXmlTrees.begin() + lPosition);296 theXmlTrees.erase(theXmlTrees.begin() + lPosition);
297 return true;297 return true;
298 }298 }
@@ -314,7 +314,7 @@
314314
315 if (lNum == 0 || lPosition >= theXmlTrees.size())315 if (lNum == 0 || lPosition >= theXmlTrees.size())
316 {316 {
317 return 0;317 return xs_integer(0);
318 }318 }
319 else319 else
320 {320 {
@@ -328,12 +328,12 @@
328 { 328 {
329 XmlNode* node = static_cast<XmlNode*>(theXmlTrees[lPosition].getp());329 XmlNode* node = static_cast<XmlNode*>(theXmlTrees[lPosition].getp());
330 ZORBA_ASSERT(node->getCollection() == this);330 ZORBA_ASSERT(node->getCollection() == this);
331 node->setCollection(NULL, 0);331 node->setCollection(NULL, xs_integer(0));
332332
333 theXmlTrees.erase(theXmlTrees.begin() + lPosition);333 theXmlTrees.erase(theXmlTrees.begin() + lPosition);
334 }334 }
335335
336 return last-lPosition;336 return xs_integer(last-lPosition);
337 }337 }
338}338}
339339
@@ -434,7 +434,7 @@
434434
435 for (std::size_t i = 0; i < numTrees; ++i)435 for (std::size_t i = 0; i < numTrees; ++i)
436 {436 {
437 BASE_NODE(theXmlTrees[i])->getTree()->setPosition(i);437 BASE_NODE(theXmlTrees[i])->getTree()->setPosition(xs_integer(i));
438 }438 }
439}439}
440440
441441
=== modified file 'src/store/naive/simple_collection.h'
--- src/store/naive/simple_collection.h 2012-03-30 19:03:09 +0000
+++ src/store/naive/simple_collection.h 2012-04-16 15:38:09 +0000
@@ -100,7 +100,7 @@
100100
101 const store::Item* getName() const { return theName.getp(); }101 const store::Item* getName() const { return theName.getp(); }
102102
103 xs_integer size() const { return theXmlTrees.size(); }103 xs_integer size() const { return xs_integer( theXmlTrees.size() ); }
104104
105 bool isDynamic() const { return theIsDynamic; }105 bool isDynamic() const { return theIsDynamic; }
106106
@@ -110,7 +110,7 @@
110110
111 store::Iterator_t getIterator();111 store::Iterator_t getIterator();
112112
113 void addNode(store::Item* node, xs_integer position = -1);113 void addNode(store::Item* node, xs_integer position = xs_integer(-1));
114114
115 xs_integer addNodes(115 xs_integer addNodes(
116 std::vector<store::Item_t>& nodes,116 std::vector<store::Item_t>& nodes,
117117
=== modified file 'src/store/naive/simple_index_general.cpp'
--- src/store/naive/simple_index_general.cpp 2012-03-30 19:03:09 +0000
+++ src/store/naive/simple_index_general.cpp 2012-04-16 15:38:09 +0000
@@ -1667,13 +1667,13 @@
1667 {1667 {
1668 if (haveLower)1668 if (haveLower)
1669 {1669 {
1670 xs_double doubleValue = lowerKey->getDecimalValue();1670 xs_double const doubleValue( lowerKey->getDecimalValue() );
1671 GET_FACTORY().createDouble(lowerAltKey, doubleValue);1671 GET_FACTORY().createDouble(lowerAltKey, doubleValue);
1672 }1672 }
16731673
1674 if (haveUpper)1674 if (haveUpper)
1675 {1675 {
1676 xs_double doubleValue = upperKey->getDecimalValue();1676 xs_double const doubleValue( upperKey->getDecimalValue() );
1677 GET_FACTORY().createDouble(upperAltKey, doubleValue);1677 GET_FACTORY().createDouble(upperAltKey, doubleValue);
1678 }1678 }
16791679
@@ -1697,13 +1697,13 @@
1697 {1697 {
1698 if (haveLower)1698 if (haveLower)
1699 {1699 {
1700 xs_decimal decimalValue = lowerKey->getLongValue();1700 xs_decimal const decimalValue( lowerKey->getLongValue() );
1701 GET_FACTORY().createDecimal(lowerAltKey, decimalValue);1701 GET_FACTORY().createDecimal(lowerAltKey, decimalValue);
1702 }1702 }
17031703
1704 if (haveUpper)1704 if (haveUpper)
1705 {1705 {
1706 xs_decimal decimalValue = upperKey->getLongValue();1706 xs_decimal const decimalValue( upperKey->getLongValue() );
1707 GET_FACTORY().createDecimal(upperAltKey, decimalValue);1707 GET_FACTORY().createDecimal(upperAltKey, decimalValue);
1708 }1708 }
17091709
@@ -1714,13 +1714,13 @@
1714 {1714 {
1715 if (haveLower)1715 if (haveLower)
1716 {1716 {
1717 xs_double doubleValue = lowerKey->getLongValue();1717 xs_double doubleValue( lowerKey->getLongValue() );
1718 GET_FACTORY().createDouble(lowerAltKey, doubleValue);1718 GET_FACTORY().createDouble(lowerAltKey, doubleValue);
1719 }1719 }
17201720
1721 if (haveUpper)1721 if (haveUpper)
1722 {1722 {
1723 xs_double doubleValue = upperKey->getLongValue();1723 xs_double const doubleValue( upperKey->getLongValue() );
1724 GET_FACTORY().createDouble(upperAltKey, doubleValue);1724 GET_FACTORY().createDouble(upperAltKey, doubleValue);
1725 }1725 }
17261726
@@ -1772,14 +1772,14 @@
17721772
1773 if (idx->theMaps[store::XS_DOUBLE])1773 if (idx->theMaps[store::XS_DOUBLE])
1774 {1774 {
1775 xs_double doubleValue = longItem->getLongValue();1775 xs_double const doubleValue( longItem->getLongValue() );
1776 GET_FACTORY().createDouble(altKey, doubleValue);1776 GET_FACTORY().createDouble(altKey, doubleValue);
1777 probeMap(store::XS_DOUBLE, altKey, altKey);1777 probeMap(store::XS_DOUBLE, altKey, altKey);
1778 }1778 }
17791779
1780 if (idx->theMaps[store::XS_DECIMAL])1780 if (idx->theMaps[store::XS_DECIMAL])
1781 {1781 {
1782 xs_decimal decimalValue = longItem->getLongValue();1782 xs_decimal const decimalValue( longItem->getLongValue() );
1783 GET_FACTORY().createDecimal(altKey, decimalValue);1783 GET_FACTORY().createDecimal(altKey, decimalValue);
1784 probeMap(store::XS_DECIMAL, altKey, altKey);1784 probeMap(store::XS_DECIMAL, altKey, altKey);
1785 }1785 }
@@ -1806,7 +1806,7 @@
18061806
1807 if (idx->theMaps[store::XS_DOUBLE])1807 if (idx->theMaps[store::XS_DOUBLE])
1808 {1808 {
1809 xs_double doubleValue = decimalItem->getDecimalValue();1809 xs_double const doubleValue( decimalItem->getDecimalValue() );
1810 GET_FACTORY().createDouble(altKey, doubleValue);1810 GET_FACTORY().createDouble(altKey, doubleValue);
1811 probeMap(store::XS_DOUBLE, altKey, altKey);1811 probeMap(store::XS_DOUBLE, altKey, altKey);
1812 }1812 }
18131813
=== modified file 'src/store/naive/simple_lazy_temp_seq.cpp'
--- src/store/naive/simple_lazy_temp_seq.cpp 2012-03-30 19:03:09 +0000
+++ src/store/naive/simple_lazy_temp_seq.cpp 2012-04-16 15:38:09 +0000
@@ -238,7 +238,7 @@
238xs_integer SimpleLazyTempSeq::getSize() const238xs_integer SimpleLazyTempSeq::getSize() const
239{239{
240 ZORBA_ASSERT(false);240 ZORBA_ASSERT(false);
241 return 0;241 return xs_integer(0);
242}242}
243243
244244
@@ -250,7 +250,7 @@
250********************************************************************************/250********************************************************************************/
251store::Iterator_t SimpleLazyTempSeq::getIterator() const251store::Iterator_t SimpleLazyTempSeq::getIterator() const
252{252{
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()));
254}254}
255255
256256
@@ -307,9 +307,9 @@
307307
308bool SimpleLazyTempSeqIter::next(store::Item_t& result)308bool SimpleLazyTempSeqIter::next(store::Item_t& result)
309{309{
310 if (theCurPos < theEndPos && theTempSeq->containsItem(theCurPos+1))310 if (theCurPos < theEndPos && theTempSeq->containsItem(xs_integer(theCurPos+1)))
311 {311 {
312 theTempSeq->getItem(++theCurPos, result);312 theTempSeq->getItem(xs_integer(++theCurPos), result);
313 return true;313 return true;
314 }314 }
315 else315 else
316316
=== modified file 'src/store/naive/simple_temp_seq.cpp'
--- src/store/naive/simple_temp_seq.cpp 2012-03-30 19:03:09 +0000
+++ src/store/naive/simple_temp_seq.cpp 2012-04-16 15:38:09 +0000
@@ -133,7 +133,7 @@
133********************************************************************************/133********************************************************************************/
134xs_integer SimpleTempSeq::getSize() const134xs_integer SimpleTempSeq::getSize() const
135{135{
136 return theItems.size();136 return xs_integer( theItems.size() );
137}137}
138138
139139
140140
=== modified file 'src/zorbatypes/decimal.cpp'
--- src/zorbatypes/decimal.cpp 2012-04-12 02:08:10 +0000
+++ src/zorbatypes/decimal.cpp 2012-04-16 15:38:09 +0000
@@ -334,15 +334,15 @@
334334
335TEMPLATE_DECL(T)335TEMPLATE_DECL(T)
336Decimal Decimal::round( INTEGER_IMPL(T) const &precision ) const {336Decimal Decimal::round( INTEGER_IMPL(T) const &precision ) const {
337 return round( value_, precision.itod() );337 return round2( value_, precision.itod() );
338}338}
339#ifndef ZORBA_WITH_BIG_INTEGER339#ifndef ZORBA_WITH_BIG_INTEGER
340template Decimal Decimal::round( INTEGER_IMPL_LL const& ) const;340template Decimal Decimal::round( INTEGER_IMPL_LL const& ) const;
341template Decimal Decimal::round( INTEGER_IMPL_ULL const& ) const;341template Decimal Decimal::round( INTEGER_IMPL_ULL const& ) const;
342#endif /* ZORBA_WITH_BIG_INTEGER */342#endif /* ZORBA_WITH_BIG_INTEGER */
343343
344Decimal::value_type Decimal::round( value_type const &v,344Decimal::value_type Decimal::round2( value_type const &v,
345 value_type const &precision ) {345 value_type const &precision ) {
346 value_type const exp( value_type(10).pow( precision ) );346 value_type const exp( value_type(10).pow( precision ) );
347 value_type result( v * exp );347 value_type result( v * exp );
348 result += MAPM::get0_5();348 result += MAPM::get0_5();
@@ -353,22 +353,22 @@
353353
354TEMPLATE_DECL(T)354TEMPLATE_DECL(T)
355Decimal Decimal::roundHalfToEven( INTEGER_IMPL(T) const &precision ) const {355Decimal Decimal::roundHalfToEven( INTEGER_IMPL(T) const &precision ) const {
356 return roundHalfToEven( value_, precision.itod() );356 return roundHalfToEven2( value_, precision.itod() );
357}357}
358#ifndef ZORBA_WITH_BIG_INTEGER358#ifndef ZORBA_WITH_BIG_INTEGER
359template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_LL const& ) const;359template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_LL const& ) const;
360template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_ULL const& ) const;360template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_ULL const& ) const;
361#endif /* ZORBA_WITH_BIG_INTEGER */361#endif /* ZORBA_WITH_BIG_INTEGER */
362362
363Decimal::value_type Decimal::roundHalfToEven( value_type const &v,363Decimal::value_type Decimal::roundHalfToEven2( value_type const &v,
364 value_type const &precision ) {364 value_type const &precision ) {
365 value_type const exp( value_type(10).pow( precision ) );365 value_type const exp( value_type(10).pow( precision ) );
366 value_type result( v * exp );366 value_type result( v * exp );
367 bool const aHalfVal = (result - MAPM::get0_5()) == result.floor();367 bool const aHalfVal = (result - MAPM::get0_5()) == result.floor();
368 result += MAPM::get0_5();368 result += MAPM::get0_5();
369 result = result.floor();369 result = result.floor();
370 if ( aHalfVal && result.is_odd() )370 if ( aHalfVal && result.is_odd() )
371 result -= 1;371 --result;
372 result /= exp;372 result /= exp;
373 return result;373 return result;
374}374}
375375
=== modified file 'src/zorbatypes/decimal.h'
--- src/zorbatypes/decimal.h 2012-03-30 19:03:09 +0000
+++ src/zorbatypes/decimal.h 2012-04-16 15:38:09 +0000
@@ -21,6 +21,7 @@
21#include <zorba/config.h>21#include <zorba/config.h>
2222
23#include "common/common.h"23#include "common/common.h"
24#include "util/stl_util.h"
24#include "zorbaserialization/archiver.h"25#include "zorbaserialization/archiver.h"
25#include "zorbaserialization/class_serializer.h"26#include "zorbaserialization/class_serializer.h"
2627
@@ -30,11 +31,11 @@
30#include "zstring.h"31#include "zstring.h"
3132
32#ifdef ZORBA_WITH_BIG_INTEGER33#ifdef ZORBA_WITH_BIG_INTEGER
33# define TEMPLATE_DECL(T) /* nothing */34# define TEMPLATE_DECL(I) /* nothing */
34# define INTEGER_IMPL(T) IntegerImpl35# define INTEGER_IMPL(I) IntegerImpl
35#else36#else
36# define TEMPLATE_DECL(T) template<typename T>37# define TEMPLATE_DECL(I) template<typename I>
37# define INTEGER_IMPL(T) IntegerImpl<T>38# define INTEGER_IMPL(I) IntegerImpl<I>
38#endif /* ZORBA_WITH_BIG_INTEGER */39#endif /* ZORBA_WITH_BIG_INTEGER */
3940
40namespace zorba {41namespace zorba {
@@ -46,23 +47,22 @@
4647
47 ////////// constructors /////////////////////////////////////////////////////48 ////////// constructors /////////////////////////////////////////////////////
4849
49 Decimal( char c );50 explicit Decimal( char c );
50 Decimal( signed char c );51 explicit Decimal( signed char c );
51 Decimal( short n );52 explicit Decimal( short n );
52 Decimal( int n = 0 );53 explicit Decimal( int n = 0 );
53 Decimal( long n );54 explicit Decimal( long n );
54 Decimal( long long n );55 explicit Decimal( long long n );
55 Decimal( unsigned char c );56 explicit Decimal( unsigned char c );
56 Decimal( unsigned short n );57 explicit Decimal( unsigned short n );
57 Decimal( unsigned int n );58 explicit Decimal( unsigned int n );
58 Decimal( unsigned long n );59 explicit Decimal( unsigned long n );
59 Decimal( unsigned long long n );60 explicit Decimal( unsigned long long n );
60 Decimal( float n );61 explicit Decimal( float n );
61 Decimal( double n );62 explicit Decimal( double n );
62 Decimal( Decimal const &d );
6363
64 TEMPLATE_DECL(T)64 TEMPLATE_DECL(I)
65 Decimal( INTEGER_IMPL(T) const &i );65 explicit Decimal( INTEGER_IMPL(I) const &i );
6666
67 /**67 /**
68 * Constructs a %Decimal from a C string.68 * Constructs a %Decimal from a C string.
@@ -71,7 +71,7 @@
71 * whitespace is ignored.71 * whitespace is ignored.
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.
73 */73 */
74 Decimal( char const *s );74 explicit Decimal( char const *s );
7575
76 /**76 /**
77 * Constructs a %Decimal from a Double.77 * Constructs a %Decimal from a Double.
@@ -79,7 +79,7 @@
79 * @param n The Double.79 * @param n The Double.
80 * @throw std::invalid_argument if \a n is not finite.80 * @throw std::invalid_argument if \a n is not finite.
81 */81 */
82 Decimal( Double const &n );82 explicit Decimal( Double const &n );
8383
84 /**84 /**
85 * Constructs a %Decimal from a Float.85 * Constructs a %Decimal from a Float.
@@ -87,30 +87,46 @@
87 * @param n The Float.87 * @param n The Float.
88 * @throw std::invalid_argument if \a n is not finite.88 * @throw std::invalid_argument if \a n is not finite.
89 */89 */
90 Decimal( Float const &n );90 explicit Decimal( Float const &n );
91
92 /**
93 * Conventional copy constructor.
94 *
95 * @param d The %Decimal to copy from.
96 */
97 Decimal( Decimal const &d );
9198
92 ////////// assignment operators /////////////////////////////////////////////99 ////////// assignment operators /////////////////////////////////////////////
93100
94 Decimal& operator=( char c );101 /**
95 Decimal& operator=( signed char c );102 * Conventional assignment operator.
96 Decimal& operator=( short n );103 *
97 Decimal& operator=( int n );104 * @param d The %Decimal to assign from.
98 Decimal& operator=( long n );105 * @return Returns \c *this.
106 */
107 Decimal& operator=( Decimal const &d );
108
109 /**
110 * For every built-in arithmetic type A, assign to this %Decimal.
111 *
112 * @tparam A The built-in arithmetic type.
113 * @param n The arithmetic value to assign.
114 * @return Returns \c *this.
115 */
116 template<typename A>
117 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,Decimal&>::type
118 operator=( A n );
119
120 // These arithmetic types have to be special-cased.
99 Decimal& operator=( long long n );121 Decimal& operator=( long long n );
100 Decimal& operator=( unsigned char c );
101 Decimal& operator=( unsigned short n );
102 Decimal& operator=( unsigned int n );
103 Decimal& operator=( unsigned long n );
104 Decimal& operator=( unsigned long long n );122 Decimal& operator=( unsigned long long n );
105 Decimal& operator=( float n );123
106 Decimal& operator=( double n );
107 Decimal& operator=( char const *s );124 Decimal& operator=( char const *s );
108 Decimal& operator=( Decimal const &d );
109 Decimal& operator=( Double const &d );125 Decimal& operator=( Double const &d );
110 Decimal& operator=( Float const &f );126 Decimal& operator=( Float const &f );
111127
112 TEMPLATE_DECL(T)128 TEMPLATE_DECL(I)
113 Decimal& operator=( INTEGER_IMPL(T) const &i );129 Decimal& operator=( INTEGER_IMPL(I) const &i );
114130
115 ////////// arithmetic operators /////////////////////////////////////////////131 ////////// arithmetic operators /////////////////////////////////////////////
116132
@@ -121,10 +137,11 @@
121 friend Decimal operator%( Decimal const&, Decimal const& );137 friend Decimal operator%( Decimal const&, Decimal const& );
122138
123#define ZORBA_DECIMAL_OP(OP) \139#define ZORBA_DECIMAL_OP(OP) \
124 TEMPLATE_DECL(T) \140 TEMPLATE_DECL(I) \
125 friend Decimal operator OP( Decimal const&, INTEGER_IMPL(T) const& ); \141 friend Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \
126 TEMPLATE_DECL(T) \142 \
127 friend Decimal operator OP( INTEGER_IMPL(T) const&, Decimal const& )143 TEMPLATE_DECL(I) \
144 friend Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& )
128145
129 ZORBA_DECIMAL_OP(+);146 ZORBA_DECIMAL_OP(+);
130 ZORBA_DECIMAL_OP(-);147 ZORBA_DECIMAL_OP(-);
@@ -140,7 +157,7 @@
140 Decimal& operator%=( Decimal const& );157 Decimal& operator%=( Decimal const& );
141158
142#define ZORBA_DECIMAL_OP(OP) \159#define ZORBA_DECIMAL_OP(OP) \
143 TEMPLATE_DECL(T) Decimal& operator OP( INTEGER_IMPL(T) const& )160 TEMPLATE_DECL(I) Decimal& operator OP( INTEGER_IMPL(I) const& )
144161
145 ZORBA_DECIMAL_OP(+=);162 ZORBA_DECIMAL_OP(+=);
146 ZORBA_DECIMAL_OP(-=);163 ZORBA_DECIMAL_OP(-=);
@@ -155,10 +172,10 @@
155172
156#define ZORBA_DECIMAL_OP(OP) \173#define ZORBA_DECIMAL_OP(OP) \
157 friend bool operator OP( Decimal const&, Decimal const& ); \174 friend bool operator OP( Decimal const&, Decimal const& ); \
158 TEMPLATE_DECL(T) \175 TEMPLATE_DECL(I) \
159 friend bool operator OP( Decimal const&, INTEGER_IMPL(T) const& ); \176 friend bool operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \
160 TEMPLATE_DECL(T) \177 TEMPLATE_DECL(I) \
161 friend bool operator OP( INTEGER_IMPL(T) const&, Decimal const& )178 friend bool operator OP( INTEGER_IMPL(I) const&, Decimal const& )
162179
163 ZORBA_DECIMAL_OP(==);180 ZORBA_DECIMAL_OP(==);
164 ZORBA_DECIMAL_OP(!=);181 ZORBA_DECIMAL_OP(!=);
@@ -176,11 +193,11 @@
176 Decimal floor() const;193 Decimal floor() const;
177 Decimal round() const;194 Decimal round() const;
178195
179 TEMPLATE_DECL(T)196 TEMPLATE_DECL(I)
180 Decimal round( INTEGER_IMPL(T) const &precision ) const;197 Decimal round( INTEGER_IMPL(I) const &precision ) const;
181198
182 TEMPLATE_DECL(T)199 TEMPLATE_DECL(I)
183 Decimal roundHalfToEven( INTEGER_IMPL(T) const &precision ) const;200 Decimal roundHalfToEven( INTEGER_IMPL(I) const &precision ) const;
184201
185 Decimal sqrt() const;202 Decimal sqrt() const;
186203
@@ -223,16 +240,16 @@
223240
224 static void reduce( char *s );241 static void reduce( char *s );
225242
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 );
227244
228 static value_type roundHalfToEven( value_type const &v,245 static value_type roundHalfToEven2( value_type const &v,
229 value_type const &precision );246 value_type const &precision );
230247
231 static zstring toString( value_type const&,248 static zstring toString( value_type const&,
232 int precision = ZORBA_FLOAT_POINT_PRECISION );249 int precision = ZORBA_FLOAT_POINT_PRECISION );
233250
234 TEMPLATE_DECL(T) friend class IntegerImpl;251 TEMPLATE_DECL(I) friend class IntegerImpl;
235 template<typename T> friend class FloatImpl;252 template<typename F> friend class FloatImpl;
236253
237 friend xs_long to_xs_long( Decimal const& );254 friend xs_long to_xs_long( Decimal const& );
238};255};
@@ -274,112 +291,49 @@
274291
275////////// assignment operators ///////////////////////////////////////////////292////////// assignment operators ///////////////////////////////////////////////
276293
277inline Decimal& Decimal::operator=( char c ) {
278 value_ = static_cast<long>( c );
279 return *this;
280}
281
282inline Decimal& Decimal::operator=( signed char c ) {
283 value_ = static_cast<long>( c );
284 return *this;
285}
286
287inline Decimal& Decimal::operator=( short n ) {
288 value_ = static_cast<long>( n );
289 return *this;
290}
291
292inline Decimal& Decimal::operator=( int n ) {
293 value_ = static_cast<long>( n );
294 return *this;
295}
296
297inline Decimal& Decimal::operator=( long n ) {
298 value_ = n;
299 return *this;
300}
301
302inline Decimal& Decimal::operator=( unsigned char c ) {
303 value_ = static_cast<long>( c );
304 return *this;
305}
306
307inline Decimal& Decimal::operator=( unsigned short n ) {
308 value_ = static_cast<long>( n );
309 return *this;
310}
311
312inline Decimal& Decimal::operator=( unsigned int n ) {
313 value_ = static_cast<long>( n );
314 return *this;
315}
316
317inline Decimal& Decimal::operator=( float n ) {
318 value_ = n;
319 return *this;
320}
321
322inline Decimal& Decimal::operator=( double n ) {
323 value_ = n;
324 return *this;
325}
326
327inline Decimal& Decimal::operator=( char const *s ) {
328 parse( s, &value_ );
329 return *this;
330}
331
332inline Decimal& Decimal::operator=( Decimal const &d ) {294inline Decimal& Decimal::operator=( Decimal const &d ) {
333 value_ = d.value_;295 value_ = d.value_;
334 return *this;296 return *this;
335}297}
336298
299template<typename A> inline
300typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,Decimal&>::type
301Decimal::operator=( A n ) {
302 value_ = static_cast<long>( n );
303 return *this;
304}
305
306inline Decimal& Decimal::operator=( char const *s ) {
307 parse( s, &value_ );
308 return *this;
309}
310
337////////// arithmetic operators ///////////////////////////////////////////////311////////// arithmetic operators ///////////////////////////////////////////////
338312
339inline Decimal operator+( Decimal const &d1, Decimal const &d2 ) {313#define ZORBA_DECIMAL_OP(OP) \
340 return d1.value_ + d2.value_;314 inline Decimal operator OP( Decimal const &d1, Decimal const &d2 ) { \
341}315 return d1.value_ OP d2.value_; \
342316 }
343inline Decimal operator-( Decimal const &d1, Decimal const &d2 ) {317
344 return d1.value_ - d2.value_;318ZORBA_DECIMAL_OP(+)
345}319ZORBA_DECIMAL_OP(-)
346320ZORBA_DECIMAL_OP(*)
347inline Decimal operator*( Decimal const &d1, Decimal const &d2 ) {321ZORBA_DECIMAL_OP(/)
348 return d1.value_ * d2.value_;322ZORBA_DECIMAL_OP(%)
349}323#undef ZORBA_DECIMAL_OP
350324
351inline Decimal operator/( Decimal const &d1, Decimal const &d2 ) {325#define ZORBA_DECIMAL_OP(OP) \
352 return d1.value_ / d2.value_;326 inline Decimal& Decimal::operator OP( Decimal const &d ) { \
353}327 value_ OP d.value_; \
354328 return *this; \
355inline Decimal operator%( Decimal const &d1, Decimal const &d2 ) {329 }
356 return d1.value_ % d2.value_;330
357}331ZORBA_DECIMAL_OP(+=)
358332ZORBA_DECIMAL_OP(-=)
359inline Decimal& Decimal::operator+=( Decimal const &d ) {333ZORBA_DECIMAL_OP(*=)
360 value_ += d.value_;334ZORBA_DECIMAL_OP(/=)
361 return *this;335ZORBA_DECIMAL_OP(%=)
362}336#undef ZORBA_DECIMAL_OP
363
364inline Decimal& Decimal::operator-=( Decimal const &d ) {
365 value_ -= d.value_;
366 return *this;
367}
368
369inline Decimal& Decimal::operator*=( Decimal const &d ) {
370 value_ *= d.value_;
371 return *this;
372}
373
374inline Decimal& Decimal::operator/=( Decimal const &d ) {
375 value_ /= d.value_;
376 return *this;
377}
378
379inline Decimal& Decimal::operator%=( Decimal const &d ) {
380 value_ %= d.value_;
381 return *this;
382}
383337
384inline Decimal Decimal::operator-() const {338inline Decimal Decimal::operator-() const {
385 return -value_;339 return -value_;
386340
=== modified file 'src/zorbatypes/floatimpl.cpp'
--- src/zorbatypes/floatimpl.cpp 2012-04-12 02:08:10 +0000
+++ src/zorbatypes/floatimpl.cpp 2012-04-16 15:38:09 +0000
@@ -169,22 +169,54 @@
169template FloatImpl<double>::FloatImpl( INTEGER_IMPL_ULL const& );169template FloatImpl<double>::FloatImpl( INTEGER_IMPL_ULL const& );
170#endif /* ZORBA_WITH_BIG_INTEGER */170#endif /* ZORBA_WITH_BIG_INTEGER */
171171
172////////// assignment operators ///////////////////////////////////////////////
173
174template<typename FloatType>
175FloatImpl<FloatType>& FloatImpl<FloatType>::operator=( Decimal const &d ) {
176 zstring const temp( d.toString() );
177 parse( temp.c_str() );
178 return *this;
179}
180
181template<typename FloatType>
182TEMPLATE_DECL(IntType)
183FloatImpl<FloatType>&
184FloatImpl<FloatType>::operator=( INTEGER_IMPL(IntType) const &i ) {
185 zstring const temp( i.toString() );
186 parse( temp.c_str() );
187 return *this;
188}
189
190#ifndef ZORBA_WITH_BIG_INTEGER
191template
192FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_LL const& );
193
194template
195FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_ULL const& );
196
197template
198FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_LL const& );
199
200template
201FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_ULL const& );
202#endif /* ZORBA_WITH_BIG_INTEGER */
203
172////////// math functions /////////////////////////////////////////////////////204////////// math functions /////////////////////////////////////////////////////
173205
174template<typename FloatType>206template<typename FloatType>
175FloatImpl<FloatType> FloatImpl<FloatType>::acos() const {207FloatImpl<FloatType> FloatImpl<FloatType>::acos() const {
176 if ( *this < neg_one() || *this > one() )208 if ( *this < neg_one() || *this > one() )
177 return nan();209 return nan();
178 if ( !isNegZero() )210 return FloatImpl<FloatType>(
179 return std::acos( value_ );211 isNegZero() ? -std::acos( value_ ): std::acos( value_ )
180 return -std::acos( value_ );212 );
181}213}
182214
183template<typename FloatType>215template<typename FloatType>
184FloatImpl<FloatType> FloatImpl<FloatType>::asin() const {216FloatImpl<FloatType> FloatImpl<FloatType>::asin() const {
185 if ( *this < neg_one() || *this > one() )217 if ( *this < neg_one() || *this > one() )
186 return nan();218 return nan();
187 return std::asin( value_ );219 return FloatImpl<FloatType>( std::asin( value_ ) );
188}220}
189221
190template<typename FloatType>222template<typename FloatType>
@@ -220,8 +252,13 @@
220FloatImpl<FloatType> FloatImpl<FloatType>::round( Integer const &precision ) const {252FloatImpl<FloatType> FloatImpl<FloatType>::round( Integer const &precision ) const {
221 FloatImpl result;253 FloatImpl result;
222 if ( isFinite() && !isZero() ) {254 if ( isFinite() && !isZero() ) {
223 MAPM m = Decimal::round( value_, precision.itod() );255 MAPM m(
224 if ( value_ < 0 && m == 0 )256 Decimal::round2(
257 Decimal::value_type( value_ ),
258 Decimal::value_type( precision.itod() )
259 )
260 );
261 if ( value_ < 0 && m.sign() == 0 )
225 result = neg_zero();262 result = neg_zero();
226 else {263 else {
227 char buf[200];264 char buf[200];
@@ -234,12 +271,17 @@
234 return result;271 return result;
235}272}
236273
237template<typename FloatType>274template<typename FloatType> FloatImpl<FloatType>
238FloatImpl<FloatType> FloatImpl<FloatType>::roundHalfToEven( Integer const &precision) const {275FloatImpl<FloatType>::roundHalfToEven( Integer const &precision) const {
239 FloatImpl result;276 FloatImpl result;
240 if ( isFinite() && !isZero() ) {277 if ( isFinite() && !isZero() ) {
241 MAPM m = Decimal::roundHalfToEven( value_, precision.itod() );278 MAPM m(
242 if ( value_ < 0 && m == 0 )279 Decimal::roundHalfToEven2(
280 Decimal::value_type( value_ ),
281 Decimal::value_type( precision.itod() )
282 )
283 );
284 if ( value_ < 0 && m.sign() == 0 )
243 result = neg_zero();285 result = neg_zero();
244 else {286 else {
245 char buf[200];287 char buf[200];
@@ -353,8 +395,8 @@
353#if 1395#if 1
354 // This is the "spec" implementation, i.e., it is an exact application of396 // This is the "spec" implementation, i.e., it is an exact application of
355 // the spec in http://www.w3.org/TR/xpath-functions/#casting397 // the spec in http://www.w3.org/TR/xpath-functions/#casting
356 MAPM decimal_mapm = value_;398 MAPM decimal_mapm( value_ );
357 decimal_mapm = decimal_mapm.round(precision_);399 decimal_mapm = decimal_mapm.round( precision_ );
358 return Decimal::toString(decimal_mapm, max_precision());400 return Decimal::toString(decimal_mapm, max_precision());
359#else401#else
360 std::stringstream stream;402 std::stringstream stream;
361403
=== modified file 'src/zorbatypes/floatimpl.h'
--- src/zorbatypes/floatimpl.h 2012-03-30 19:03:09 +0000
+++ src/zorbatypes/floatimpl.h 2012-04-16 15:38:09 +0000
@@ -30,11 +30,11 @@
30#include "zorbatypes_decl.h"30#include "zorbatypes_decl.h"
3131
32#ifdef ZORBA_WITH_BIG_INTEGER32#ifdef ZORBA_WITH_BIG_INTEGER
33# define TEMPLATE_DECL(T) /* nothing */33# define TEMPLATE_DECL(I) /* nothing */
34# define INTEGER_IMPL(T) IntegerImpl34# define INTEGER_IMPL(I) IntegerImpl
35#else35#else
36# define TEMPLATE_DECL(T) template<typename T>36# define TEMPLATE_DECL(I) template<typename I>
37# define INTEGER_IMPL(T) IntegerImpl<T>37# define INTEGER_IMPL(I) IntegerImpl<I>
38#endif /* ZORBA_WITH_BIG_INTEGER */38#endif /* ZORBA_WITH_BIG_INTEGER */
3939
40namespace zorba {40namespace zorba {
@@ -56,23 +56,23 @@
5656
57 ////////// constructors /////////////////////////////////////////////////////57 ////////// constructors /////////////////////////////////////////////////////
5858
59 FloatImpl( char );59 explicit FloatImpl( char );
60 FloatImpl( signed char c );60 explicit FloatImpl( signed char c );
61 FloatImpl( short n );61 explicit FloatImpl( short n );
62 FloatImpl( int n = 0 );62 explicit FloatImpl( int n = 0 );
63 FloatImpl( long n );63 explicit FloatImpl( long n );
64 FloatImpl( long long n );64 explicit FloatImpl( long long n );
65 FloatImpl( unsigned char c );65 explicit FloatImpl( unsigned char c );
66 FloatImpl( unsigned short n );66 explicit FloatImpl( unsigned short n );
67 FloatImpl( unsigned int n );67 explicit FloatImpl( unsigned int n );
68 FloatImpl( unsigned long n );68 explicit FloatImpl( unsigned long n );
69 FloatImpl( unsigned long long n );69 explicit FloatImpl( unsigned long long n );
70 FloatImpl( float n );70 explicit FloatImpl( float n );
71 FloatImpl( double n );71 explicit FloatImpl( double n );
72 FloatImpl( Decimal const &d );72 explicit FloatImpl( Decimal const &d );
7373
74 TEMPLATE_DECL(T)74 TEMPLATE_DECL(IntType)
75 FloatImpl( INTEGER_IMPL(T) const &i );75 explicit FloatImpl( INTEGER_IMPL(IntType) const &i );
7676
77 /**77 /**
78 * Constructs a %FloatImpl from a C string.78 * Constructs a %FloatImpl from a C string.
@@ -84,62 +84,74 @@
84 * @throw std::range_error if \a s contains a number that either underflows84 * @throw std::range_error if \a s contains a number that either underflows
85 * or overflows the smallest or largest representable floating point number.85 * or overflows the smallest or largest representable floating point number.
86 */86 */
87 FloatImpl( char const *s );87 explicit FloatImpl( char const *s );
8888
89 /**
90 * Constructs from another %FloatImpl even if its \c FloatType is different.
91 * (This subsumes the conventional copy constructor.)
92 *
93 * @tparam FloatType2 the floating-point type of \a f.
94 * @param f The %FloatImpl to copy from.
95 */
89 template<typename FloatType2>96 template<typename FloatType2>
90 FloatImpl( FloatImpl<FloatType2> const &f );97 FloatImpl( FloatImpl<FloatType2> const &f );
9198
92 ////////// assignment operators /////////////////////////////////////////////99 ////////// assignment operators /////////////////////////////////////////////
93100
101 /**
102 * Assign from a %FloatImpl even if its \c FloatType is different.
103 * (This subsumes the conventional assignment operator.)
104 *
105 * @tparam FloatType2 the floating-point type of \a f.
106 * @param f The %FloatImpl to assign from.
107 * @return Returns \c *this.
108 */
109 template<typename FloatType2>
110 FloatImpl& operator=( FloatImpl<FloatType2> const &f );
111
112 /**
113 * For every built-in arithmetic type A, assign to this %FloatImpl.
114 *
115 * @tparam A The built-in arithmetic type.
116 * @param n The arithmetic value to assign.
117 * @return Returns \c *this.
118 */
94 template<typename A>119 template<typename A>
95 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,120 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
96 FloatImpl&>::type121 FloatImpl&>::type
97 operator=( A n );122 operator=( A n );
98123
99 template<typename FloatType2>124 FloatImpl& operator=( char const *s );
100 FloatImpl& operator=( FloatImpl<FloatType2> const &f );125 FloatImpl& operator=( Decimal const &d );
126
127 TEMPLATE_DECL(I)
128 FloatImpl& operator=( INTEGER_IMPL(I) const &i );
101129
102 ////////// arithmetic operators /////////////////////////////////////////////130 ////////// arithmetic operators /////////////////////////////////////////////
103131
104 template<typename A>132#define ZORBA_FLOAT_OP(OP) \
105 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,133 template<typename A> \
106 FloatImpl&>::type134 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
107 operator+=( A n );135 FloatImpl&>::type \
108136 operator OP( A n )
109 template<typename A>137
110 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,138 ZORBA_FLOAT_OP(+=);
111 FloatImpl&>::type139 ZORBA_FLOAT_OP(-=);
112 operator-=( A n );140 ZORBA_FLOAT_OP(*=);
113141 ZORBA_FLOAT_OP(/=);
114 template<typename A>142 ZORBA_FLOAT_OP(%=);
115 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,143#undef ZORBA_FLOAT_OP
116 FloatImpl&>::type144
117 operator*=( A n );145#define ZORBA_FLOAT_OP(OP) \
118146 template<typename FloatType2> \
119 template<typename A>147 FloatImpl& operator OP( FloatImpl<FloatType2> const &f )
120 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,148
121 FloatImpl&>::type149 ZORBA_FLOAT_OP(+=);
122 operator/=( A n );150 ZORBA_FLOAT_OP(-=);
123151 ZORBA_FLOAT_OP(*=);
124 template<typename A>152 ZORBA_FLOAT_OP(/=);
125 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,153 ZORBA_FLOAT_OP(%=);
126 FloatImpl&>::type154#undef ZORBA_FLOAT_OP
127 operator%=( A n );
128
129 template<typename FloatType2>
130 FloatImpl& operator+=( FloatImpl<FloatType2> const &f );
131
132 template<typename FloatType2>
133 FloatImpl& operator-=( FloatImpl<FloatType2> const &f );
134
135 template<typename FloatType2>
136 FloatImpl& operator*=( FloatImpl<FloatType2> const &f );
137
138 template<typename FloatType2>
139 FloatImpl& operator/=( FloatImpl<FloatType2> const &f );
140
141 template<typename FloatType2>
142 FloatImpl& operator%=( FloatImpl<FloatType2> const &f );
143155
144 FloatImpl operator-() const;156 FloatImpl operator-() const;
145157
@@ -231,7 +243,7 @@
231 void parse( char const* );243 void parse( char const* );
232 bool parse_etc( char const* );244 bool parse_etc( char const* );
233245
234 TEMPLATE_DECL(T) friend class IntegerImpl;246 TEMPLATE_DECL(I) friend class IntegerImpl;
235 friend class Decimal;247 friend class Decimal;
236248
237 friend class FloatImpl<float>;249 friend class FloatImpl<float>;
@@ -255,528 +267,524 @@
255267
256////////// constructors ///////////////////////////////////////////////////////268////////// constructors ///////////////////////////////////////////////////////
257269
258template<typename FloatType> inline270template<typename F>
259FloatImpl<FloatType>::FloatImpl( char c ) :271inline FloatImpl<F>::FloatImpl( char c ) :
260 value_( static_cast<value_type>( c ) ), precision_( max_precision() )272 value_( static_cast<F>( c ) ), precision_( max_precision() )
261{273{
262}274}
263275
264template<typename FloatType> inline276template<typename F>
265FloatImpl<FloatType>::FloatImpl( signed char c ) :277inline FloatImpl<F>::FloatImpl( signed char c ) :
266 value_( static_cast<value_type>( c ) ), precision_( max_precision() )278 value_( static_cast<F>( c ) ), precision_( max_precision() )
267{279{
268}280}
269281
270template<typename FloatType> inline282template<typename F>
271FloatImpl<FloatType>::FloatImpl( short n ) :283inline FloatImpl<F>::FloatImpl( short n ) :
272 value_( static_cast<value_type>( n ) ), precision_( max_precision() )284 value_( static_cast<F>( n ) ), precision_( max_precision() )
273{285{
274}286}
275287
276template<typename FloatType> inline288template<typename F>
277FloatImpl<FloatType>::FloatImpl( int n ) :289inline FloatImpl<F>::FloatImpl( int n ) :
278 value_( static_cast<value_type>( n ) ), precision_( max_precision() )290 value_( static_cast<F>( n ) ), precision_( max_precision() )
279{291{
280}292}
281293
282template<typename FloatType> inline294template<typename F>
283FloatImpl<FloatType>::FloatImpl( long n ) :295inline FloatImpl<F>::FloatImpl( long n ) :
284 value_( static_cast<value_type>( n ) ), precision_( max_precision() )296 value_( static_cast<F>( n ) ), precision_( max_precision() )
285{297{
286}298}
287299
288template<typename FloatType> inline300template<typename F>
289FloatImpl<FloatType>::FloatImpl( long long n ) :301inline FloatImpl<F>::FloatImpl( long long n ) :
290 value_( static_cast<value_type>( n ) ), precision_( max_precision() )302 value_( static_cast<F>( n ) ), precision_( max_precision() )
291{303{
292}304}
293305
294template<typename FloatType> inline306template<typename F>
295FloatImpl<FloatType>::FloatImpl( unsigned char c ) :307inline FloatImpl<F>::FloatImpl( unsigned char c ) :
296 value_( static_cast<value_type>( c ) ), precision_( max_precision() )308 value_( static_cast<F>( c ) ), precision_( max_precision() )
297{309{
298}310}
299311
300template<typename FloatType> inline312template<typename F>
301FloatImpl<FloatType>::FloatImpl( unsigned short n ) :313inline FloatImpl<F>::FloatImpl( unsigned short n ) :
302 value_( static_cast<value_type>( n ) ), precision_( max_precision() )314 value_( static_cast<F>( n ) ), precision_( max_precision() )
303{315{
304}316}
305317
306template<typename FloatType> inline318template<typename F>
307FloatImpl<FloatType>::FloatImpl( unsigned int n ) :319inline FloatImpl<F>::FloatImpl( unsigned int n ) :
308 value_( static_cast<value_type>( n ) ), precision_( max_precision() )320 value_( static_cast<F>( n ) ), precision_( max_precision() )
309{321{
310}322}
311323
312template<typename FloatType> inline324template<typename F>
313FloatImpl<FloatType>::FloatImpl( unsigned long n ) :325inline FloatImpl<F>::FloatImpl( unsigned long n ) :
314 value_( static_cast<value_type>( n ) ), precision_( max_precision() )326 value_( static_cast<F>( n ) ), precision_( max_precision() )
315{327{
316}328}
317329
318template<typename FloatType> inline330template<typename F>
319FloatImpl<FloatType>::FloatImpl( unsigned long long n ) :331inline FloatImpl<F>::FloatImpl( unsigned long long n ) :
320 value_( static_cast<value_type>( n ) ), precision_( max_precision() )332 value_( static_cast<F>( n ) ), precision_( max_precision() )
321{333{
322}334}
323335
324template<typename FloatType> inline336template<typename F>
325FloatImpl<FloatType>::FloatImpl( float n ) :337inline FloatImpl<F>::FloatImpl( float n ) :
326 value_( static_cast<value_type>( n ) ), precision_( max_precision() )338 value_( static_cast<F>( n ) ), precision_( max_precision() )
327{339{
328}340}
329341
330template<typename FloatType> inline342template<typename F>
331FloatImpl<FloatType>::FloatImpl( double n ) :343inline FloatImpl<F>::FloatImpl( double n ) :
332 value_( static_cast<value_type>( n ) ), precision_( max_precision() )344 value_( static_cast<F>( n ) ), precision_( max_precision() )
333{345{
334}346}
335347
336template<typename FloatType> inline348template<typename F>
337FloatImpl<FloatType>::FloatImpl( char const *s ) {349inline FloatImpl<F>::FloatImpl( char const *s ) {
338 parse( s );350 parse( s );
339}351}
340352
341template<typename FloatType>353template<typename F> template<typename G>
342template<typename FloatType2>354inline FloatImpl<F>::FloatImpl( FloatImpl<G> const &f ) :
343inline FloatImpl<FloatType>::FloatImpl( FloatImpl<FloatType2> const &f ) :355 value_( static_cast<F>( f.value_ ) ), precision_( max_precision() )
344 value_( static_cast<value_type>( f.value_ ) ), precision_( max_precision() )
345{356{
346}357}
347358
348template<typename FloatType>359template<typename F>
349inline FloatImpl<FloatType>::FloatImpl( value_type v, precision_type p ) :360inline FloatImpl<F>::FloatImpl( value_type v, precision_type p ) :
350 value_( v ), precision_( p )361 value_( v ), precision_( p )
351{362{
352}363}
353364
354////////// assignment operators ///////////////////////////////////////////////365////////// assignment operators ///////////////////////////////////////////////
355366
356template<typename T>367template<typename F> template<typename G>
357template<typename A> inline368inline FloatImpl<F>& FloatImpl<F>::operator=( FloatImpl<G> const &f ) {
369 value_ = static_cast<F>( f.value_ );
370 precision_ = max_precision();
371 return *this;
372}
373
374template<typename F> template<typename A> inline
358typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,375typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
359 FloatImpl<T>&>::type376 FloatImpl<F>&>::type
360FloatImpl<T>::operator=( A n ) {377FloatImpl<F>::operator=( A n ) {
361 value_ = static_cast<value_type>( n );378 value_ = static_cast<F>( n );
362 precision_ = max_precision();379 precision_ = max_precision();
363 return *this;380 return *this;
364}381}
365382
366template<typename T>383template<typename F>
367template<typename U>384inline FloatImpl<F>& FloatImpl<F>::operator=( char const *s ) {
368inline FloatImpl<T>& FloatImpl<T>::operator=( FloatImpl<U> const &f ) {385 parse( s );
369 value_ = static_cast<value_type>( f.value_ );
370 precision_ = max_precision();
371 return *this;386 return *this;
372}387}
373388
374////////// arithmetic operators ///////////////////////////////////////////////389////////// arithmetic operators ///////////////////////////////////////////////
375390
376#define ZORBA_DEF_FLOATIMPL_OP(OP) \391#define ZORBA_FLOAT_OP(OP) \
377 template<typename T,typename A> inline \392 template<typename F,typename A> inline \
378 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \393 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
379 FloatImpl<T> >::type \394 FloatImpl<F> >::type \
380 operator OP( FloatImpl<T> const &f, A n ) { \395 operator OP( FloatImpl<F> const &f, A n ) { \
381 return FloatImpl<T>( f.getNumber() OP static_cast<T>( n ) ); \396 return FloatImpl<F>( f.getNumber() OP static_cast<F>( n ) ); \
382 } \397 } \
383 template<typename T,typename A> inline \398 \
384 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \399 template<typename F,typename A> inline \
385 FloatImpl<T> >::type \400 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
386 operator OP( A n, FloatImpl<T> const &f ) { \401 FloatImpl<F> >::type \
387 return FloatImpl<T>( static_cast<T>( n ) OP f.getNumber() ); \402 operator OP( A n, FloatImpl<F> const &f ) { \
388 }403 return FloatImpl<F>( static_cast<F>( n ) OP f.getNumber() ); \
389404 }
390ZORBA_DEF_FLOATIMPL_OP( + )405
391ZORBA_DEF_FLOATIMPL_OP( - )406ZORBA_FLOAT_OP(+)
392ZORBA_DEF_FLOATIMPL_OP( * )407ZORBA_FLOAT_OP(-)
393ZORBA_DEF_FLOATIMPL_OP( / )408ZORBA_FLOAT_OP(*)
394409ZORBA_FLOAT_OP(/)
395#undef ZORBA_DEF_FLOATIMPL_OP410#undef ZORBA_FLOAT_OP
396411
397template<typename T,typename A> inline412template<typename F,typename A> inline
398typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,413typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
399 FloatImpl<T> >::type414 FloatImpl<F> >::type
400operator%( FloatImpl<T> const &f, A n ) {415operator%( FloatImpl<F> const &f, A n ) {
401 return FloatImpl<T>( std::fmod( f.getNumber(), static_cast<T>( n ) ) );416 return FloatImpl<F>( std::fmod( f.getNumber(), static_cast<F>( n ) ) );
402}417}
403418
404template<typename T,typename A> inline419template<typename F,typename A> inline
405typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,420typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
406 FloatImpl<T> >::type421 FloatImpl<F> >::type
407operator%( A n, FloatImpl<T> const &f ) {422operator%( A n, FloatImpl<F> const &f ) {
408 return FloatImpl<T>( std::fmod( static_cast<T>( n ), f.getNumber() ) );423 return FloatImpl<F>( std::fmod( static_cast<F>( n ), f.getNumber() ) );
409}424}
410425
411#define ZORBA_DEF_FLOATIMPL_OP(OP) \426#define ZORBA_FLOAT_OP(OP) \
412 template<typename T> inline \427 template<typename F> inline \
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 ) { \
414 return FloatImpl<T>( f.getNumber() OP g.getNumber() ); \429 return FloatImpl<F>( f.getNumber() OP g.getNumber() ); \
415 }430 }
416431
417ZORBA_DEF_FLOATIMPL_OP( + )432ZORBA_FLOAT_OP(+)
418ZORBA_DEF_FLOATIMPL_OP( - )433ZORBA_FLOAT_OP(-)
419ZORBA_DEF_FLOATIMPL_OP( * )434ZORBA_FLOAT_OP(*)
420ZORBA_DEF_FLOATIMPL_OP( / )435ZORBA_FLOAT_OP(/)
421436#undef ZORBA_FLOAT_OP
422#undef ZORBA_DEF_FLOATIMPL_OP437
423438template<typename F>
424template<typename T> inline439inline FloatImpl<F> operator%( FloatImpl<F> const &f, FloatImpl<F> const &g ) {
425FloatImpl<T> operator%( FloatImpl<T> const &f, FloatImpl<T> const &g ) {440 return FloatImpl<F>( std::fmod( f.getNumber(), g.getNumber() ) );
426 return FloatImpl<T>( std::fmod( f.getNumber(), g.getNumber() ) );441}
427}442
428443#define ZORBA_FLOAT_OP(OP) \
429#define ZORBA_DEF_FLOATIMPL_OP(OP) \444 template<typename F> template<typename A> inline \
430 template<typename T> \445 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
431 template<typename A> inline \446 FloatImpl<F>&>::type \
432 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \447 FloatImpl<F>::operator OP( A n ) { \
433 FloatImpl<T>&>::type \448 value_ OP static_cast<F>( n ); \
434 FloatImpl<T>::operator OP( A n ) { \
435 value_ OP static_cast<value_type>( n ); \
436 return *this; \449 return *this; \
437 }450 }
438451
439ZORBA_DEF_FLOATIMPL_OP( += )452ZORBA_FLOAT_OP(+=)
440ZORBA_DEF_FLOATIMPL_OP( -= )453ZORBA_FLOAT_OP(-=)
441ZORBA_DEF_FLOATIMPL_OP( *= )454ZORBA_FLOAT_OP(*=)
442ZORBA_DEF_FLOATIMPL_OP( /= )455ZORBA_FLOAT_OP(/=)
443ZORBA_DEF_FLOATIMPL_OP( %= )456ZORBA_FLOAT_OP(%=)
444457#undef ZORBA_FLOAT_OP
445#undef ZORBA_DEF_FLOATIMPL_OP458
446459#define ZORBA_FLOAT_OP(OP) \
447#define ZORBA_DEF_FLOATIMPL_OP(OP) \460 template<typename F> template<typename G> \
448 template<typename T> \461 inline FloatImpl<F>& FloatImpl<F>::operator OP( FloatImpl<G> const &f ) { \
449 template<typename U> \462 value_ OP static_cast<F>( f.value_ ); \
450 inline FloatImpl<T>& FloatImpl<T>::operator OP( FloatImpl<U> const &f ) { \
451 value_ OP static_cast<value_type>( f.value_ ); \
452 return *this; \463 return *this; \
453 }464 }
454465
455ZORBA_DEF_FLOATIMPL_OP( += )466ZORBA_FLOAT_OP(+=)
456ZORBA_DEF_FLOATIMPL_OP( -= )467ZORBA_FLOAT_OP(-=)
457ZORBA_DEF_FLOATIMPL_OP( *= )468ZORBA_FLOAT_OP(*=)
458ZORBA_DEF_FLOATIMPL_OP( /= )469ZORBA_FLOAT_OP(/=)
459ZORBA_DEF_FLOATIMPL_OP( %= )470#undef ZORBA_FLOAT_OP
460471
461#undef ZORBA_DEF_FLOATIMPL_OP472template<typename F> template<typename G>
462473inline FloatImpl<F>& FloatImpl<F>::operator%=( FloatImpl<G> const &f ) {
463template<typename FloatType>474 value_ = std::fmod( value_, static_cast<F>( f.value_ ) );
464inline FloatImpl<FloatType> FloatImpl<FloatType>::operator-() const {475 return *this;
465 return FloatImpl<FloatType>( -value_, precision_ );476}
466}477
467478template<typename F>
468inline Double operator+( Double const &d, Float const &f ) {479inline FloatImpl<F> FloatImpl<F>::operator-() const {
469 return d.getNumber() + f.getNumber();480 return FloatImpl<F>( -value_, precision_ );
470}481}
471482
472inline Double operator+( Float const &f, Double const &d ) {483#define ZORBA_FLOAT_OP(OP) \
473 return f.getNumber() + d.getNumber();484 inline Double operator OP( Double const &d, Float const &f ) { \
474}485 return Double( d.getNumber() OP f.getNumber() ); \
475486 } \
476inline Double operator-( Double const &d, Float const &f ) {487 inline Double operator OP( Float const &f, Double const &d ) { \
477 return d.getNumber() - f.getNumber();488 return Double( f.getNumber() OP d.getNumber() ); \
478}489 }
479490
480inline Double operator-( Float const &f, Double const &d ) {491ZORBA_FLOAT_OP(+)
481 return f.getNumber() - d.getNumber();492ZORBA_FLOAT_OP(-)
482}493ZORBA_FLOAT_OP(*)
483494ZORBA_FLOAT_OP(/)
484inline Double operator*( Double const &d, Float const &f ) {495#undef ZORBA_FLOAT_OP
485 return d.getNumber() * f.getNumber();
486}
487
488inline Double operator*( Float const &f, Double const &d ) {
489 return f.getNumber() * d.getNumber();
490}
491
492inline Double operator/( Double const &d, Float const &f ) {
493 return d.getNumber() / f.getNumber();
494}
495
496inline Double operator/( Float const &f, Double const &d ) {
497 return f.getNumber() / d.getNumber();
498}
499496
500inline Double operator%( Double const &d, Float const &f ) {497inline Double operator%( Double const &d, Float const &f ) {
501 return std::fmod( d.getNumber(), static_cast<double>( f.getNumber() ) );498 return Double(
499 std::fmod( d.getNumber(), static_cast<double>( f.getNumber() ) )
500 );
502}501}
503502
504inline Double operator%( Float const &f, Double const &d ) {503inline Double operator%( Float const &f, Double const &d ) {
505 return std::fmod( static_cast<double>( f.getNumber() ), d.getNumber() );504 return Double(
505 std::fmod( static_cast<double>( f.getNumber() ), d.getNumber() )
506 );
506}507}
507508
508////////// relational operators ///////////////////////////////////////////////509////////// relational operators ///////////////////////////////////////////////
509510
510template<typename T,typename U>511template<typename F,typename G>
511inline bool operator==( FloatImpl<T> const &f, FloatImpl<U> const &g ) {512inline bool operator==( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
512 return f.getNumber() == g.getNumber();513 return f.getNumber() == g.getNumber();
513}514}
514515
515template<typename T,typename U>516template<typename F,typename G>
516inline bool operator!=( FloatImpl<T> const &f, FloatImpl<U> const &g ) {517inline bool operator!=( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
517 return f.getNumber() != g.getNumber();518 return f.getNumber() != g.getNumber();
518}519}
519520
520template<typename T,typename U>521template<typename F,typename G>
521inline bool operator<( FloatImpl<T> const &f, FloatImpl<U> const &g ) {522inline bool operator<( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
522 return f.getNumber() < g.getNumber();523 return f.getNumber() < g.getNumber();
523}524}
524525
525template<typename T,typename U>526template<typename F,typename G>
526inline bool operator<=( FloatImpl<T> const &f, FloatImpl<U> const &g ) {527inline bool operator<=( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
527 return !f.isNaN() && !g.isNaN() && f.getNumber() <= g.getNumber();528 return !f.isNaN() && !g.isNaN() && f.getNumber() <= g.getNumber();
528}529}
529530
530template<typename T,typename U>531template<typename F,typename G>
531inline bool operator>( FloatImpl<T> const &f, FloatImpl<U> const &g ) {532inline bool operator>( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
532 return f.getNumber() > g.getNumber();533 return f.getNumber() > g.getNumber();
533}534}
534535
535template<typename T,typename U>536template<typename F,typename G>
536inline bool operator>=( FloatImpl<T> const &f, FloatImpl<U> const &g ) {537inline bool operator>=( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
537 return !f.isNaN() && !g.isNaN() && f.getNumber() >= g.getNumber();538 return !f.isNaN() && !g.isNaN() && f.getNumber() >= g.getNumber();
538}539}
539540
540template<typename T>541template<typename F>
541inline bool operator==( FloatImpl<T> const &f, double d ) {542inline bool operator==( FloatImpl<F> const &f, double d ) {
542 return f.getNumber() == d;543 return f.getNumber() == d;
543}544}
544545
545template<typename T>546template<typename F>
546inline bool operator==( double d, FloatImpl<T> const &f ) {547inline bool operator==( double d, FloatImpl<F> const &f ) {
547 return d = f.getNumber();548 return d = f.getNumber();
548}549}
549550
550template<typename T>551template<typename F>
551inline bool operator!=( FloatImpl<T> const &f, double d ) {552inline bool operator!=( FloatImpl<F> const &f, double d ) {
552 return f.getNumber() != d;553 return f.getNumber() != d;
553}554}
554555
555template<typename T>556template<typename F>
556inline bool operator!=( double d, FloatImpl<T> const &f ) {557inline bool operator!=( double d, FloatImpl<F> const &f ) {
557 return f.getNumber() != d;558 return f.getNumber() != d;
558}559}
559560
560template<typename T>561template<typename F>
561inline bool operator<( FloatImpl<T> const &f, double d ) {562inline bool operator<( FloatImpl<F> const &f, double d ) {
562 return f.getNumber() < d;563 return f.getNumber() < d;
563}564}
564565
565template<typename T>566template<typename F>
566inline bool operator<( double d, FloatImpl<T> const &f ) {567inline bool operator<( double d, FloatImpl<F> const &f ) {
567 return d < f.getNumber();568 return d < f.getNumber();
568}569}
569570
570template<typename T>571template<typename F>
571inline bool operator<=( FloatImpl<T> const &f, double d ) {572inline bool operator<=( FloatImpl<F> const &f, double d ) {
572 return !f.isNaN() && d == d && f.getNumber() <= d;573 return !f.isNaN() && d == d && f.getNumber() <= d;
573}574}
574575
575template<typename T>576template<typename F>
576inline bool operator<=( double d, FloatImpl<T> const &f ) {577inline bool operator<=( double d, FloatImpl<F> const &f ) {
577 return d == d && !f.isNaN() && d <= f.getNumber();578 return d == d && !f.isNaN() && d <= f.getNumber();
578}579}
579580
580template<typename T>581template<typename F>
581inline bool operator>( FloatImpl<T> const &f, double d ) {582inline bool operator>( FloatImpl<F> const &f, double d ) {
582 return f.getNumber() > d;583 return f.getNumber() > d;
583}584}
584585
585template<typename T>586template<typename F>
586inline bool operator>( double d, FloatImpl<T> const &f ) {587inline bool operator>( double d, FloatImpl<F> const &f ) {
587 return d > f.getNumber();588 return d > f.getNumber();
588}589}
589590
590template<typename T>591template<typename F>
591inline bool operator>=( FloatImpl<T> const &f, double d ) {592inline bool operator>=( FloatImpl<F> const &f, double d ) {
592 return !f.isNaN() && d == d && f.getNumber() >= d;593 return !f.isNaN() && d == d && f.getNumber() >= d;
593}594}
594595
595template<typename T>596template<typename F>
596inline bool operator>=( double d, FloatImpl<T> const &f ) {597inline bool operator>=( double d, FloatImpl<F> const &f ) {
597 return d == d && !f.isNaN() && d >= f.getNumber();598 return d == d && !f.isNaN() && d >= f.getNumber();
598}599}
599600
600////////// math functions /////////////////////////////////////////////////////601////////// math functions /////////////////////////////////////////////////////
601602
602template<typename FloatType> inline FloatImpl<FloatType>603template<typename F>
603FloatImpl<FloatType>::acosh() const {604inline FloatImpl<F> FloatImpl<F>::acosh() const {
604 // formula from www.mathworks.com605 // formula from www.mathworks.com
605 return std::log( value_ + std::sqrt( value_ * value_ - 1 ) );606 return FloatImpl<F>(
606}607 std::log( value_ + std::sqrt( value_ * value_ - 1 ) )
607608 );
608template<typename FloatType> inline FloatImpl<FloatType>609}
609FloatImpl<FloatType>::asinh() const {610
610 // formula from www.mathworks.com611template<typename F>
611 return std::log( value_ + std::sqrt( value_ * value_ + 1 ) );612inline FloatImpl<F> FloatImpl<F>::asinh() const {
612}613 // formula from www.mathworks.com
613614 return FloatImpl<F>(
614template<typename FloatType> inline FloatImpl<FloatType>615 std::log( value_ + std::sqrt( value_ * value_ + 1 ) )
615FloatImpl<FloatType>::atan() const {616 );
616 return std::atan( value_ );617}
617}618
618619template<typename F>
619template<typename FloatType> inline FloatImpl<FloatType>620inline FloatImpl<F> FloatImpl<F>::atan() const {
620FloatImpl<FloatType>::atanh() const {621 return FloatImpl<F>( std::atan( value_ ) );
621 // formula from www.mathworks.com622}
622 return 0.5 * std::log( (1 + value_) / (1 - value_) );623
623}624template<typename F>
624625inline FloatImpl<F> FloatImpl<F>::atanh() const {
625template<typename FloatType> inline FloatImpl<FloatType>626 // formula from www.mathworks.com
626FloatImpl<FloatType>::atan2( double x ) const {627 return FloatImpl<F>( 0.5 * std::log( (1 + value_) / (1 - value_) ) );
627 return std::atan2( value_, static_cast<value_type>( x ) );628}
628}629
629630template<typename F>
630template<typename FloatType> inline FloatImpl<FloatType>631inline FloatImpl<F> FloatImpl<F>::atan2( double x ) const {
631FloatImpl<FloatType>::atan2( FloatImpl<FloatType> const &x ) const {632 return FloatImpl<F>( std::atan2( value_, static_cast<F>( x ) ) );
632 return atan2( x.value_ );633}
633}634
634635template<typename F>
635template<typename FloatType> inline FloatImpl<FloatType>636inline FloatImpl<F> FloatImpl<F>::atan2( FloatImpl<F> const &x ) const {
636FloatImpl<FloatType>::ceil() const {637 return FloatImpl<F>( atan2( x.value_ ) );
637 return std::ceil( value_ );638}
638}639
639640template<typename F>
640template<typename FloatType> inline FloatImpl<FloatType>641inline FloatImpl<F> FloatImpl<F>::ceil() const {
641FloatImpl<FloatType>::cos() const {642 return FloatImpl<F>( std::ceil( value_ ) );
642 return std::cos( value_ );643}
643}644
644645template<typename F>
645template<typename FloatType> inline FloatImpl<FloatType>646inline FloatImpl<F> FloatImpl<F>::cos() const {
646FloatImpl<FloatType>::cosh() const {647 return FloatImpl<F>( std::cos( value_ ) );
647 return std::cosh( value_ );648}
648}649
649650template<typename F>
650template<typename FloatType> inline FloatImpl<FloatType>651inline FloatImpl<F> FloatImpl<F>::cosh() const {
651FloatImpl<FloatType>::exp() const {652 return FloatImpl<F>( std::cosh( value_ ) );
652 return std::exp( value_ );653}
653}654
654655template<typename F>
655template<typename FloatType> inline FloatImpl<FloatType>656inline FloatImpl<F> FloatImpl<F>::exp() const {
656FloatImpl<FloatType>::exp10() const {657 return FloatImpl<F>( std::exp( value_ ) );
657 return std::pow( 10, value_ );658}
658}659
659660template<typename F>
660template<typename FloatType> inline FloatImpl<FloatType>661inline FloatImpl<F> FloatImpl<F>::exp10() const {
661FloatImpl<FloatType>::floor() const {662 return FloatImpl<F>( std::pow( 10, value_ ) );
662 return std::floor( value_ );663}
663}664
664665template<typename F>
665template<typename FloatType> inline FloatImpl<FloatType>666inline FloatImpl<F> FloatImpl<F>::floor() const {
666FloatImpl<FloatType>::fmod( double d ) const {667 return FloatImpl<F>( std::floor( value_ ) );
667 return std::fmod( value_, static_cast<value_type>( d ) );668}
668}669
669670template<typename F>
670template<typename FloatType> inline FloatImpl<FloatType>671inline FloatImpl<F> FloatImpl<F>::fmod( double d ) const {
671FloatImpl<FloatType>::fmod( FloatImpl<FloatType> const &f ) const {672 return FloatImpl<F>( std::fmod( value_, static_cast<F>( d ) ) );
672 return fmod( f.value_ );673}
673}674
674675template<typename F>
675template<typename FloatType>676inline FloatImpl<F>
676FloatImpl<FloatType> FloatImpl<FloatType>::log() const {677FloatImpl<F>::fmod( FloatImpl<F> const &f ) const {
677 return value_ < 0 ? nan() : FloatImpl<FloatType>( std::log( value_ ) );678 return FloatImpl<F>( fmod( f.value_ ) );
678}679}
679680
680template<typename FloatType>681template<typename F>
681FloatImpl<FloatType> FloatImpl<FloatType>::log10() const {682FloatImpl<F> FloatImpl<F>::log() const {
682 return value_ < 0 ? nan() : FloatImpl<FloatType>( std::log10( value_ ) );683 return value_ < 0 ? nan() : FloatImpl<F>( std::log( value_ ) );
683}684}
684685
685template<typename FloatType> inline FloatImpl<FloatType>686template<typename F>
686FloatImpl<FloatType>::pow( int p ) const {687FloatImpl<F> FloatImpl<F>::log10() const {
687 return std::pow( value_, p );688 return value_ < 0 ? nan() : FloatImpl<F>( std::log10( value_ ) );
688}689}
689690
690template<typename FloatType> inline FloatImpl<FloatType>691template<typename F>
691FloatImpl<FloatType>::pow( FloatImpl<FloatType> const &p ) const {692inline FloatImpl<F> FloatImpl<F>::pow( int p ) const {
692 return p.isNaN() ? value_ : std::pow( value_, p.value_ );693 return FloatImpl<F>( std::pow( value_, p ) );
693}694}
694695
695template<typename FloatType> inline FloatImpl<FloatType>696template<typename F>
696FloatImpl<FloatType>::sin() const {697inline FloatImpl<F>
697 return std::sin( value_ );698FloatImpl<F>::pow( FloatImpl<F> const &p ) const {
698}699 return FloatImpl<F>(
699700 p.isNaN() ? value_ : std::pow( value_, p.value_ )
700template<typename FloatType> inline FloatImpl<FloatType>701 );
701FloatImpl<FloatType>::sinh() const {702}
702 return std::sinh( value_ );703
703}704template<typename F>
704705inline FloatImpl<F> FloatImpl<F>::sin() const {
705template<typename FloatType> inline FloatImpl<FloatType>706 return FloatImpl<F>( std::sin( value_ ) );
706FloatImpl<FloatType>::sqrt() const {707}
708
709template<typename F>
710inline FloatImpl<F> FloatImpl<F>::sinh() const {
711 return FloatImpl<F>( std::sinh( value_ ) );
712}
713
714template<typename F>
715inline FloatImpl<F> FloatImpl<F>::sqrt() const {
707 return value_ < 0 ? nan() : FloatImpl( std::sqrt( value_ ) );716 return value_ < 0 ? nan() : FloatImpl( std::sqrt( value_ ) );
708}717}
709718
710template<typename FloatType> inline FloatImpl<FloatType>719template<typename F>
711FloatImpl<FloatType>::tan() const {720inline FloatImpl<F> FloatImpl<F>::tan() const {
712 return std::tan( value_ );721 return FloatImpl<F>( std::tan( value_ ) );
713}722}
714723
715template<typename FloatType> inline FloatImpl<FloatType>724template<typename F>
716FloatImpl<FloatType>::tanh() const {725inline FloatImpl<F> FloatImpl<F>::tanh() const {
717 return std::tanh( value_ );726 return FloatImpl<F>( std::tanh( value_ ) );
718}727}
719728
720////////// miscellaneous //////////////////////////////////////////////////////729////////// miscellaneous //////////////////////////////////////////////////////
721730
722template<typename T>731template<typename F> template<typename G>
723template<typename U>732inline int FloatImpl<F>::compare( FloatImpl<G> const &f ) const {
724inline int FloatImpl<T>::compare( FloatImpl<U> const &f ) const {
725 return value_ < f.value_ ? -1 : value_ > f.value_ ? 1 : 0;733 return value_ < f.value_ ? -1 : value_ > f.value_ ? 1 : 0;
726}734}
727735
728template<typename FloatType>736template<typename F>
729inline uint32_t FloatImpl<FloatType>::hash() const {737inline uint32_t FloatImpl<F>::hash() const {
730 return static_cast<uint32_t>( value_ );738 return static_cast<uint32_t>( value_ );
731}739}
732740
733template<typename FloatType>741template<typename F>
734inline bool FloatImpl<FloatType>::isNeg() const {742inline bool FloatImpl<F>::isNeg() const {
735 return value_ < 0;743 return value_ < 0;
736}744}
737745
738template<typename FloatType>746template<typename F>
739inline bool FloatImpl<FloatType>::isPos() const {747inline bool FloatImpl<F>::isPos() const {
740 return value_ > 0;748 return value_ > 0;
741}749}
742750
743template<typename FloatType>751template<typename F>
744inline bool FloatImpl<FloatType>::isPosZero() const {752inline bool FloatImpl<F>::isPosZero() const {
745 return value_ == 0 && !isNegZero();753 return value_ == 0 && !isNegZero();
746}754}
747755
748template<typename FloatType>756template<typename F>
749inline bool FloatImpl<FloatType>::isNaN() const {757inline bool FloatImpl<F>::isNaN() const {
750 return value_ != value_;758 return value_ != value_;
751}759}
752760
753template<typename FloatType>761template<typename F>
754inline bool FloatImpl<FloatType>::isNegInf() const {762inline bool FloatImpl<F>::isNegInf() const {
755 return value_ == -std::numeric_limits<FloatType>::infinity();763 return value_ == -std::numeric_limits<F>::infinity();
756}764}
757765
758template<typename FloatType>766template<typename F>
759inline bool FloatImpl<FloatType>::isPosInf() const {767inline bool FloatImpl<F>::isPosInf() const {
760 return value_ == std::numeric_limits<FloatType>::infinity();768 return value_ == std::numeric_limits<F>::infinity();
761}769}
762770
763template<typename FloatType>771template<typename F>
764inline bool FloatImpl<FloatType>::isFinite() const {772inline bool FloatImpl<F>::isFinite() const {
765 return !isNaN() && !isPosInf() && !isNegInf();773 return !isNaN() && !isPosInf() && !isNegInf();
766}774}
767775
768template<typename FloatType>776template<typename F>
769inline bool FloatImpl<FloatType>::isInteger() const {777inline bool FloatImpl<F>::isInteger() const {
770 return isFinite() && ::floor( value_ ) == value_;778 return isFinite() && ::floor( value_ ) == value_;
771}779}
772780
773template <typename FloatType>781template <typename F>
774inline bool FloatImpl<FloatType>::isZero() const {782inline bool FloatImpl<F>::isZero() const {
775 return value_ == 0;783 return value_ == 0;
776}784}
777785
778template<typename FloatType> inline786template<typename F>
779std::ostream& operator<<( std::ostream &os, FloatImpl<FloatType> const &f ) {787inline std::ostream& operator<<( std::ostream &os, FloatImpl<F> const &f ) {
780 return os << f.toString();788 return os << f.toString();
781}789}
782790
783791
=== modified file 'src/zorbatypes/integer.cpp'
--- src/zorbatypes/integer.cpp 2012-03-30 19:03:09 +0000
+++ src/zorbatypes/integer.cpp 2012-04-16 15:38:09 +0000
@@ -230,13 +230,13 @@
230230
231TEMPLATE_DECL(T)231TEMPLATE_DECL(T)
232INTEGER_IMPL(T) INTEGER_IMPL(T)::round( IntegerImpl const &precision ) const {232INTEGER_IMPL(T) INTEGER_IMPL(T)::round( IntegerImpl const &precision ) const {
233 return IntegerImpl( Decimal::round( itod(), precision.itod() ) );233 return IntegerImpl( Decimal::round2( itod(), precision.itod() ) );
234}234}
235235
236TEMPLATE_DECL(T)236TEMPLATE_DECL(T)
237INTEGER_IMPL(T)237INTEGER_IMPL(T)
238INTEGER_IMPL(T)::roundHalfToEven( IntegerImpl const &precision ) const {238INTEGER_IMPL(T)::roundHalfToEven( IntegerImpl const &precision ) const {
239 return IntegerImpl( Decimal::roundHalfToEven( itod(), precision.itod() ) );239 return IntegerImpl( Decimal::roundHalfToEven2( itod(), precision.itod() ) );
240}240}
241241
242////////// miscellaneous //////////////////////////////////////////////////////242////////// miscellaneous //////////////////////////////////////////////////////
243243
=== modified file 'src/zorbatypes/integer.h'
--- src/zorbatypes/integer.h 2012-04-12 02:08:10 +0000
+++ src/zorbatypes/integer.h 2012-04-16 15:38:09 +0000
@@ -22,8 +22,8 @@
22#include <limits>22#include <limits>
2323
24#include <zorba/config.h>24#include <zorba/config.h>
25
25#include "common/common.h"26#include "common/common.h"
26
27#include "util/stl_util.h"27#include "util/stl_util.h"
2828
29#include "m_apm.h"29#include "m_apm.h"
@@ -32,25 +32,25 @@
32#include "zstring.h"32#include "zstring.h"
3333
34#ifdef ZORBA_WITH_BIG_INTEGER34#ifdef ZORBA_WITH_BIG_INTEGER
35# define TEMPLATE_DECL(T) /* nothing */35# define TEMPLATE_DECL(I) /* nothing */
36# define INTEGER_IMPL(T) IntegerImpl36# define TEMPLATE_DECL2(I,A) template<typename A>
37# define INTEGER_IMPL(I) IntegerImpl
37#else38#else
38# define TEMPLATE_DECL(T) template<typename T>39# define TEMPLATE_DECL(I) template<typename I>
39# define INTEGER_IMPL(T) IntegerImpl<T>40# define TEMPLATE_DECL2(I,A) template<typename I,typename A>
41# define INTEGER_IMPL(I) IntegerImpl<I>
40#endif /* ZORBA_WITH_BIG_INTEGER */42#endif /* ZORBA_WITH_BIG_INTEGER */
41#define INTEGER_IMPL_LL INTEGER_IMPL(long long)43#define INTEGER_IMPL_LL INTEGER_IMPL(long long)
42#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)44#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
4345
44namespace zorba {46namespace zorba {
4547
46TEMPLATE_DECL(T)48TEMPLATE_DECL(I)
47class IntegerImpl;49class IntegerImpl;
4850
49namespace serialization 51namespace serialization {
50{
51 class Archiver;52 class Archiver;
5253 TEMPLATE_DECL(I) void operator&( Archiver&, INTEGER_IMPL(I)& );
53 TEMPLATE_DECL(T) void operator&( Archiver&, INTEGER_IMPL(T)& );
54}54}
5555
56///////////////////////////////////////////////////////////////////////////////56///////////////////////////////////////////////////////////////////////////////
@@ -61,23 +61,20 @@
6161
62 ////////// constructors /////////////////////////////////////////////////////62 ////////// constructors /////////////////////////////////////////////////////
6363
64 IntegerImpl( char c );64 explicit IntegerImpl( char c );
65 IntegerImpl( signed char c );65 explicit IntegerImpl( signed char c );
66 IntegerImpl( short n );66 explicit IntegerImpl( short n );
67 IntegerImpl( int n = 0 );67 explicit IntegerImpl( int n = 0 );
68 IntegerImpl( long n );68 explicit IntegerImpl( long n );
69 IntegerImpl( long long n );69 explicit IntegerImpl( long long n );
70 IntegerImpl( unsigned char c );70 explicit IntegerImpl( unsigned char c );
71 IntegerImpl( unsigned short n );71 explicit IntegerImpl( unsigned short n );
72 IntegerImpl( unsigned int n );72 explicit IntegerImpl( unsigned int n );
73 IntegerImpl( unsigned long n );73 explicit IntegerImpl( unsigned long n );
74 IntegerImpl( unsigned long long n );74 explicit IntegerImpl( unsigned long long n );
75 IntegerImpl( float n );75 explicit IntegerImpl( float n );
76 IntegerImpl( double n );76 explicit IntegerImpl( double n );
77 IntegerImpl( Decimal const &d );77 explicit IntegerImpl( Decimal const &d );
78
79 TEMPLATE_DECL(U)
80 IntegerImpl( INTEGER_IMPL(U) const &i );
8178
82 /**79 /**
83 * Constructs an %IntegerImpl from a C string.80 * Constructs an %IntegerImpl from a C string.
@@ -89,7 +86,7 @@
89 * or overflows the smallest or largest representable integer (only when not86 * or overflows the smallest or largest representable integer (only when not
90 * compiled with ZORBA_WITH_BIG_INTEGER).87 * compiled with ZORBA_WITH_BIG_INTEGER).
91 */88 */
92 IntegerImpl( char const *s );89 explicit IntegerImpl( char const *s );
9390
94 /**91 /**
95 * Constructs an %IntegerImpl from a Double.92 * Constructs an %IntegerImpl from a Double.
@@ -97,7 +94,7 @@
97 * @param d The Double.94 * @param d The Double.
98 * @throw std::invalid_argument if \a d is not finite.95 * @throw std::invalid_argument if \a d is not finite.
99 */96 */
100 IntegerImpl( Double const &d );97 explicit IntegerImpl( Double const &d );
10198
102 /**99 /**
103 * Constructs an %IntegerImpl from a Float.100 * Constructs an %IntegerImpl from a Float.
@@ -105,54 +102,113 @@
105 * @param f The Float.102 * @param f The Float.
106 * @throw std::invalid_argument if \a f is not finite.103 * @throw std::invalid_argument if \a f is not finite.
107 */104 */
108 IntegerImpl( Float const &f );105 explicit IntegerImpl( Float const &f );
106
107 /**
108 * Constructs from another %IntegerImpl even if its \c IntType is different.
109 * (This subsumes the conventional copy constructor.)
110 *
111 * @tparam IntType2 the integer type of \a i.
112 * @param i The %IntegerImpl to copy from.
113 */
114 TEMPLATE_DECL(IntType2)
115 IntegerImpl( INTEGER_IMPL(IntType2) const &i );
109116
110 ////////// assignment operators /////////////////////////////////////////////117 ////////// assignment operators /////////////////////////////////////////////
111118
112 IntegerImpl& operator=( char c );119 /**
113 IntegerImpl& operator=( signed char c );120 * Assign from an %IntegerImpl even if its \c IntType is different.
114 IntegerImpl& operator=( short n );121 * (This subsumes the conventional assignment operator.)
115 IntegerImpl& operator=( int n );122 *
116 IntegerImpl& operator=( long n );123 * @tparam IntType2 the integer type of \a i.
117 IntegerImpl& operator=( long long n );124 * @param i The %IntegerImpl to assign from.
118 IntegerImpl& operator=( unsigned char c );125 * @return Returns \c *this.
119 IntegerImpl& operator=( unsigned short n );126 */
120 IntegerImpl& operator=( unsigned int n );127 TEMPLATE_DECL(IntType2)
121 IntegerImpl& operator=( unsigned long n );128 IntegerImpl& operator=( INTEGER_IMPL(IntType2) const &i );
122 IntegerImpl& operator=( unsigned long long n );129
123 IntegerImpl& operator=( float n );130 /**
124 IntegerImpl& operator=( double n );131 * For every built-in arithmetic type A, assign to this %IntegerImpl.
132 *
133 * @tparam A The built-in arithmetic type.
134 * @param n The arithmetic value to assign.
135 * @return Returns \c *this.
136 */
137 template<typename A>
138 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
139 IntegerImpl&>::type
140 operator=( A n );
141
142 // These arithmetic types have to be special-cased.
143 IntegerImpl& operator=( long long );
144 IntegerImpl& operator=( unsigned long );
145 IntegerImpl& operator=( unsigned long long );
146
125 IntegerImpl& operator=( char const *s );147 IntegerImpl& operator=( char const *s );
126 IntegerImpl& operator=( Decimal const &d );148 IntegerImpl& operator=( Decimal const &d );
127 IntegerImpl& operator=( Double const &d );149 IntegerImpl& operator=( Double const &d );
128 IntegerImpl& operator=( Float const &f );150 IntegerImpl& operator=( Float const &f );
129151
130 TEMPLATE_DECL(U)
131 IntegerImpl& operator=( INTEGER_IMPL(U) const &i );
132
133 ////////// arithmetic operators /////////////////////////////////////////////152 ////////// arithmetic operators /////////////////////////////////////////////
134153
135#define ZORBA_INTEGER_OP(OP) \154#define ZORBA_INTEGER_OP(OP) \
136 TEMPLATE_DECL(T) friend \155 TEMPLATE_DECL(I) friend \
137 INTEGER_IMPL(T) operator OP( INTEGER_IMPL(T) const&, \156 INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const&, \
138 INTEGER_IMPL(T) const& ); \157 INTEGER_IMPL(I) const& ); \
139 TEMPLATE_DECL(T) friend \158 \
140 Decimal operator OP( INTEGER_IMPL(T) const&, Decimal const& ); \159 TEMPLATE_DECL(I) friend \
141 TEMPLATE_DECL(T) friend \160 Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \
142 Decimal operator OP( Decimal const&, INTEGER_IMPL(T) const& )161 \
143162 TEMPLATE_DECL(I) friend \
144 ZORBA_INTEGER_OP(+);163 Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& )
145 ZORBA_INTEGER_OP(-);164
146 ZORBA_INTEGER_OP(*);165 ZORBA_INTEGER_OP(+);
147 ZORBA_INTEGER_OP(/);166 ZORBA_INTEGER_OP(-);
148 ZORBA_INTEGER_OP(%);167 ZORBA_INTEGER_OP(*);
149#undef ZORBA_INTEGER_OP168 ZORBA_INTEGER_OP(/);
150169 ZORBA_INTEGER_OP(%);
151 IntegerImpl& operator+=( IntegerImpl const& );170#undef ZORBA_INTEGER_OP
152 IntegerImpl& operator-=( IntegerImpl const& );171
153 IntegerImpl& operator*=( IntegerImpl const& );172#define ZORBA_INTEGER_OP(OP) \
154 IntegerImpl& operator/=( IntegerImpl const& );173 TEMPLATE_DECL2(I,A) friend \
155 IntegerImpl& operator%=( IntegerImpl const& );174 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
175 INTEGER_IMPL(I)>::type \
176 operator OP( INTEGER_IMPL(I) const&, A ); \
177 \
178 TEMPLATE_DECL2(I,A) friend \
179 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
180 INTEGER_IMPL(I)>::type \
181 operator OP( A, INTEGER_IMPL(I) const& )
182
183 ZORBA_INTEGER_OP(+);
184 ZORBA_INTEGER_OP(-);
185 ZORBA_INTEGER_OP(*);
186 ZORBA_INTEGER_OP(/);
187 ZORBA_INTEGER_OP(%);
188#undef ZORBA_INTEGER_OP
189
190#define ZORBA_INTEGER_OP(OP,TYPE) \
191 IntegerImpl& operator OP( TYPE )
192
193 ZORBA_INTEGER_OP(+=,IntegerImpl const&);
194 ZORBA_INTEGER_OP(-=,IntegerImpl const&);
195 ZORBA_INTEGER_OP(*=,IntegerImpl const&);
196 ZORBA_INTEGER_OP(/=,IntegerImpl const&);
197 ZORBA_INTEGER_OP(%=,IntegerImpl const&);
198#undef ZORBA_INTEGER_OP
199
200#define ZORBA_INTEGER_OP(OP) \
201 template<typename A> \
202 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
203 IntegerImpl&>::type \
204 operator OP( A )
205
206 ZORBA_INTEGER_OP(+=);
207 ZORBA_INTEGER_OP(-=);
208 ZORBA_INTEGER_OP(*=);
209 ZORBA_INTEGER_OP(/=);
210 ZORBA_INTEGER_OP(%=);
211#undef ZORBA_INTEGER_OP
156212
157 IntegerImpl operator-() const;213 IntegerImpl operator-() const;
158214
@@ -164,12 +220,31 @@
164 ////////// relational operators /////////////////////////////////////////////220 ////////// relational operators /////////////////////////////////////////////
165221
166#define ZORBA_INTEGER_OP(OP) \222#define ZORBA_INTEGER_OP(OP) \
167 TEMPLATE_DECL(T) friend \223 TEMPLATE_DECL(I) friend \
168 bool operator OP( INTEGER_IMPL(T) const&, INTEGER_IMPL(T) const& ); \224 bool operator OP( INTEGER_IMPL(I) const&, INTEGER_IMPL(I) const& ); \
169 TEMPLATE_DECL(T) friend \225 \
170 bool operator OP( INTEGER_IMPL(T) const&, Decimal const& ); \226 TEMPLATE_DECL(I) friend \
171 TEMPLATE_DECL(T) friend \227 bool operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \
172 bool operator OP( Decimal const&, INTEGER_IMPL(T) const& )228 \
229 TEMPLATE_DECL(I) friend \
230 bool operator OP( Decimal const&, INTEGER_IMPL(I) const& )
231
232 ZORBA_INTEGER_OP(==);
233 ZORBA_INTEGER_OP(!=);
234 ZORBA_INTEGER_OP(< );
235 ZORBA_INTEGER_OP(<=);
236 ZORBA_INTEGER_OP(> );
237 ZORBA_INTEGER_OP(>=);
238#undef ZORBA_INTEGER_OP
239
240#define ZORBA_INTEGER_OP(OP) \
241 TEMPLATE_DECL2(I,A) friend \
242 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \
243 operator OP( INTEGER_IMPL(I) const&, A ); \
244 \
245 TEMPLATE_DECL2(I,A) friend \
246 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \
247 operator OP( A, INTEGER_IMPL(I) const& )
173248
174 ZORBA_INTEGER_OP(==);249 ZORBA_INTEGER_OP(==);
175 ZORBA_INTEGER_OP(!=);250 ZORBA_INTEGER_OP(!=);
@@ -214,6 +289,11 @@
214 }289 }
215290
216#ifdef ZORBA_WITH_BIG_INTEGER291#ifdef ZORBA_WITH_BIG_INTEGER
292 template<typename T>
293 static value_type cast( T n ) {
294 return value_type( static_cast<long>( n ) );
295 }
296
217 static value_type ftoi( MAPM const &d ) {297 static value_type ftoi( MAPM const &d ) {
218 return d.sign() >= 0 ? d.floor() : d.ceil();298 return d.sign() >= 0 ? d.floor() : d.ceil();
219 }299 }
@@ -222,6 +302,11 @@
222 return value_; // intentional no-op302 return value_; // intentional no-op
223 }303 }
224#else304#else
305 template<typename T>
306 static value_type cast( T n ) {
307 return static_cast<value_type>( n );
308 }
309
225 bool is_long() const;310 bool is_long() const;
226311
227 static value_type ftoi( value_type v ) {312 static value_type ftoi( value_type v ) {
@@ -239,7 +324,7 @@
239 template<typename T> friend class FloatImpl;324 template<typename T> friend class FloatImpl;
240325
241#ifndef ZORBA_WITH_BIG_INTEGER326#ifndef ZORBA_WITH_BIG_INTEGER
242 template<typename U> friend class IntegerImpl;327 template<typename T> friend class IntegerImpl;
243#endif /* ZORBA_WITH_BIG_INTEGER */328#endif /* ZORBA_WITH_BIG_INTEGER */
244329
245 friend xs_int to_xs_int( INTEGER_IMPL_LL const& );330 friend xs_int to_xs_int( INTEGER_IMPL_LL const& );
@@ -247,8 +332,8 @@
247 friend xs_unsignedInt to_xs_unsignedInt( INTEGER_IMPL_LL const& );332 friend xs_unsignedInt to_xs_unsignedInt( INTEGER_IMPL_LL const& );
248 friend xs_unsignedLong to_xs_unsignedLong( INTEGER_IMPL_LL const& );333 friend xs_unsignedLong to_xs_unsignedLong( INTEGER_IMPL_LL const& );
249334
250 TEMPLATE_DECL(T) friend335 TEMPLATE_DECL(I) friend
251 void serialization::operator&( serialization::Archiver&, INTEGER_IMPL(T)& );336 void serialization::operator&( serialization::Archiver&, INTEGER_IMPL(I)& );
252};337};
253338
254typedef INTEGER_IMPL_LL Integer;339typedef INTEGER_IMPL_LL Integer;
@@ -256,78 +341,78 @@
256341
257////////// constructors ///////////////////////////////////////////////////////342////////// constructors ///////////////////////////////////////////////////////
258343
259TEMPLATE_DECL(T)344TEMPLATE_DECL(I)
260inline INTEGER_IMPL(T)::IntegerImpl( char c ) :345inline INTEGER_IMPL(I)::IntegerImpl( char c ) :
261 value_( static_cast<long>( c ) )346 value_( static_cast<long>( c ) )
262{347{
263}348}
264349
265TEMPLATE_DECL(T)350TEMPLATE_DECL(I)
266inline INTEGER_IMPL(T)::IntegerImpl( signed char c ) :351inline INTEGER_IMPL(I)::IntegerImpl( signed char c ) :
267 value_( static_cast<long>( c ) )352 value_( static_cast<long>( c ) )
268{353{
269}354}
270355
271TEMPLATE_DECL(T)356TEMPLATE_DECL(I)
272inline INTEGER_IMPL(T)::IntegerImpl( short n ) :357inline INTEGER_IMPL(I)::IntegerImpl( short n ) :
273 value_( static_cast<long>( n ) )358 value_( static_cast<long>( n ) )
274{359{
275}360}
276361
277TEMPLATE_DECL(T)362TEMPLATE_DECL(I)
278inline INTEGER_IMPL(T)::IntegerImpl( int n ) :363inline INTEGER_IMPL(I)::IntegerImpl( int n ) :
279 value_( static_cast<long>( n ) )364 value_( static_cast<long>( n ) )
280{365{
281}366}
282367
283TEMPLATE_DECL(T)368TEMPLATE_DECL(I)
284inline INTEGER_IMPL(T)::IntegerImpl( long n ) :369inline INTEGER_IMPL(I)::IntegerImpl( long n ) :
285 value_( n )370 value_( n )
286{371{
287}372}
288373
289#ifndef ZORBA_WITH_BIG_INTEGER374#ifndef ZORBA_WITH_BIG_INTEGER
290TEMPLATE_DECL(T)375TEMPLATE_DECL(I)
291inline INTEGER_IMPL(T)::IntegerImpl( long long n ) :376inline INTEGER_IMPL(I)::IntegerImpl( long long n ) :
292 value_( n )377 value_( n )
293{378{
294}379}
295#endif /* ZORBA_WITH_BIG_INTEGER */380#endif /* ZORBA_WITH_BIG_INTEGER */
296381
297TEMPLATE_DECL(T)382TEMPLATE_DECL(I)
298inline INTEGER_IMPL(T)::IntegerImpl( unsigned char c ) :383inline INTEGER_IMPL(I)::IntegerImpl( unsigned char c ) :
299 value_( static_cast<long>( c ) )384 value_( static_cast<long>( c ) )
300{385{
301}386}
302387
303TEMPLATE_DECL(T)388TEMPLATE_DECL(I)
304inline INTEGER_IMPL(T)::IntegerImpl( unsigned short n ) :389inline INTEGER_IMPL(I)::IntegerImpl( unsigned short n ) :
305 value_( static_cast<long>( n ) )390 value_( static_cast<long>( n ) )
306{391{
307}392}
308393
309TEMPLATE_DECL(T)394TEMPLATE_DECL(I)
310inline INTEGER_IMPL(T)::IntegerImpl( unsigned int n ) :395inline INTEGER_IMPL(I)::IntegerImpl( unsigned int n ) :
311 value_( static_cast<long>( n ) )396 value_( static_cast<long>( n ) )
312{397{
313}398}
314399
315#ifndef ZORBA_WITH_BIG_INTEGER400#ifndef ZORBA_WITH_BIG_INTEGER
316TEMPLATE_DECL(T)401TEMPLATE_DECL(I)
317inline INTEGER_IMPL(T)::IntegerImpl( unsigned long n ) :402inline INTEGER_IMPL(I)::IntegerImpl( unsigned long n ) :
318 value_( static_cast<value_type>( n ) )403 value_( static_cast<value_type>( n ) )
319{404{
320}405}
321406
322TEMPLATE_DECL(T)407TEMPLATE_DECL(I)
323inline INTEGER_IMPL(T)::IntegerImpl( unsigned long long n ) :408inline INTEGER_IMPL(I)::IntegerImpl( unsigned long long n ) :
324 value_( static_cast<value_type>( n ) )409 value_( static_cast<value_type>( n ) )
325{410{
326}411}
327#endif /* ZORBA_WITH_BIG_INTEGER */412#endif /* ZORBA_WITH_BIG_INTEGER */
328413
329TEMPLATE_DECL(T)414TEMPLATE_DECL(I)
330inline INTEGER_IMPL(T)::IntegerImpl( float n ) :415inline INTEGER_IMPL(I)::IntegerImpl( float n ) :
331#ifdef ZORBA_WITH_BIG_INTEGER416#ifdef ZORBA_WITH_BIG_INTEGER
332 value_( static_cast<double>( n ) )417 value_( static_cast<double>( n ) )
333#else418#else
@@ -336,8 +421,8 @@
336{421{
337}422}
338423
339TEMPLATE_DECL(T)424TEMPLATE_DECL(I)
340inline INTEGER_IMPL(T)::IntegerImpl( double n ) :425inline INTEGER_IMPL(I)::IntegerImpl( double n ) :
341#ifdef ZORBA_WITH_BIG_INTEGER426#ifdef ZORBA_WITH_BIG_INTEGER
342 value_( n )427 value_( n )
343#else428#else
@@ -346,111 +431,56 @@
346{431{
347}432}
348433
349TEMPLATE_DECL(T)434TEMPLATE_DECL(I)
350inline INTEGER_IMPL(T)::IntegerImpl( char const *s ) {435inline INTEGER_IMPL(I)::IntegerImpl( char const *s ) {
351 parse( s );436 parse( s );
352}437}
353438
354TEMPLATE_DECL(T)439TEMPLATE_DECL(I)
355TEMPLATE_DECL(U)440TEMPLATE_DECL(J)
356inline INTEGER_IMPL(T)::IntegerImpl( INTEGER_IMPL(U) const &i ) :441inline INTEGER_IMPL(I)::IntegerImpl( INTEGER_IMPL(J) const &i ) :
357 value_( i.value_ )442 value_( i.value_ )
358{443{
359}444}
360445
361////////// assignment operators ///////////////////////////////////////////////446////////// assignment operators ///////////////////////////////////////////////
362447
363TEMPLATE_DECL(T)448TEMPLATE_DECL(I) template<typename A> inline
364inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( char c ) {449typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
365 value_ = static_cast<long>( c );450 INTEGER_IMPL(I)&>::type
366 return *this;451INTEGER_IMPL(I)::operator=( A n ) {
367}452 value_ = static_cast<long>( n );
368453 return *this;
369TEMPLATE_DECL(T)454}
370inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( signed char c ) {455
371 value_ = static_cast<long>( c );456#ifndef ZORBA_WITH_BIG_INTEGER
372 return *this;457template<typename I>
373}458inline IntegerImpl<I>& IntegerImpl<I>::operator=( long long n ) {
374459 value_ = n;
375TEMPLATE_DECL(T)460 return *this;
376inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( short n ) {461}
377 value_ = static_cast<long>( n );462
378 return *this;463template<typename I>
379}464inline IntegerImpl<I>& IntegerImpl<I>::operator=( unsigned long n ) {
380465 value_ = static_cast<long>( n );
381TEMPLATE_DECL(T)466 return *this;
382inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( int n ) {467}
383 value_ = static_cast<long>( n );468
384 return *this;469template<typename I>
385}470inline IntegerImpl<I>& IntegerImpl<I>::operator=( unsigned long long n ) {
386471 value_ = n;
387TEMPLATE_DECL(T)472 return *this;
388inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( long n ) {473}
389 value_ = n;474#endif /* ZORBA_WITH_BIG_INTEGER */
390 return *this;475
391}476TEMPLATE_DECL(I)
392477inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( char const *s ) {
393#ifndef ZORBA_WITH_BIG_INTEGER
394TEMPLATE_DECL(T)
395inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( long long n ) {
396 value_ = n;
397 return *this;
398}
399#endif /* ZORBA_WITH_BIG_INTEGER */
400
401TEMPLATE_DECL(T)
402inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned char c ) {
403 value_ = static_cast<long>( c );
404 return *this;
405}
406
407TEMPLATE_DECL(T)
408inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned short n ) {
409 value_ = static_cast<long>( n );
410 return *this;
411}
412
413TEMPLATE_DECL(T)
414inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned int n ) {
415 value_ = static_cast<long>( n );
416 return *this;
417}
418
419#ifndef ZORBA_WITH_BIG_INTEGER
420TEMPLATE_DECL(T)
421inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned long n ) {
422 value_ = static_cast<long>( n );
423 return *this;
424}
425
426TEMPLATE_DECL(T)
427inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned long long n ) {
428 value_ = n;
429 return *this;
430}
431#endif /* ZORBA_WITH_BIG_INTEGER */
432
433TEMPLATE_DECL(T)
434inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( float n ) {
435 value_ = static_cast<long>( n );
436 return *this;
437}
438
439TEMPLATE_DECL(T)
440inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( double n ) {
441 value_ = static_cast<long>( n );
442 return *this;
443}
444
445TEMPLATE_DECL(T)
446inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( char const *s ) {
447 parse( s );478 parse( s );
448 return *this;479 return *this;
449}480}
450481
451TEMPLATE_DECL(T)482TEMPLATE_DECL(I) TEMPLATE_DECL(J)
452TEMPLATE_DECL(U)483inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( INTEGER_IMPL(J) const &i ) {
453inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( INTEGER_IMPL(U) const &i ) {
454 value_ = i.value_;484 value_ = i.value_;
455 return *this;485 return *this;
456}486}
@@ -458,26 +488,66 @@
458////////// arithmetic operators ///////////////////////////////////////////////488////////// arithmetic operators ///////////////////////////////////////////////
459489
460#define ZORBA_INTEGER_OP(OP) \490#define ZORBA_INTEGER_OP(OP) \
461 TEMPLATE_DECL(T) inline \491 TEMPLATE_DECL(I) inline \
462 INTEGER_IMPL(T) operator OP( INTEGER_IMPL(T) const &i, \492 INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const &i, \
463 INTEGER_IMPL(T) const &j ) { \493 INTEGER_IMPL(I) const &j ) { \
464 return i.value_ OP j.value_; \494 return INTEGER_IMPL(I)( i.value_ OP j.value_ ); \
465 }495 }
466496
467ZORBA_INTEGER_OP(+)497ZORBA_INTEGER_OP(+)
468ZORBA_INTEGER_OP(-)498ZORBA_INTEGER_OP(-)
469ZORBA_INTEGER_OP(*)499ZORBA_INTEGER_OP(*)
470ZORBA_INTEGER_OP(%)500ZORBA_INTEGER_OP(%)
471#undef ZORBA_INTEGER_OP501#undef ZORBA_INTEGER_OP
472502
473TEMPLATE_DECL(T) inline503TEMPLATE_DECL(I) inline
474INTEGER_IMPL(T) operator/( INTEGER_IMPL(T) const &i, INTEGER_IMPL(T) const &j ) {504INTEGER_IMPL(I) operator/( INTEGER_IMPL(I) const &i,
475 return INTEGER_IMPL(T)::ftoi( i.value_ / j.value_ );505 INTEGER_IMPL(I) const &j ) {
506 return INTEGER_IMPL(I)( INTEGER_IMPL(I)::ftoi( i.value_ / j.value_ ) );
507}
508
509#define ZORBA_INTEGER_OP(OP) \
510 TEMPLATE_DECL2(I,A) inline \
511 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
512 INTEGER_IMPL(I)>::type \
513 operator OP( INTEGER_IMPL(I) const& i, A n ) { \
514 return INTEGER_IMPL(I)( i.value_ OP INTEGER_IMPL(I)::cast( n ) ); \
515 } \
516 \
517 TEMPLATE_DECL2(I,A) inline \
518 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
519 INTEGER_IMPL(I)>::type \
520 operator OP( A n, INTEGER_IMPL(I) const &i ) { \
521 return INTEGER_IMPL(I)( INTEGER_IMPL(I)::cast( n ) OP i.value_ ); \
522 }
523
524ZORBA_INTEGER_OP(+)
525ZORBA_INTEGER_OP(-)
526ZORBA_INTEGER_OP(*)
527ZORBA_INTEGER_OP(%)
528#undef ZORBA_INTEGER_OP
529
530TEMPLATE_DECL2(I,A) inline
531typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
532 INTEGER_IMPL(I)>::type
533operator/( INTEGER_IMPL(I) const &i, A n ) {
534 return INTEGER_IMPL(I)(
535 INTEGER_IMPL(I)::ftoi( i.value_ / INTEGER_IMPL(I)::cast( n ) )
536 );
537}
538
539TEMPLATE_DECL2(I,A) inline
540typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
541 INTEGER_IMPL(I)>::type
542operator/( A n, INTEGER_IMPL(I) const &i ) {
543 return INTEGER_IMPL(I)(
544 INTEGER_IMPL(I)::ftoi( INTEGER_IMPL(I)::cast( n ) / i.value_ )
545 );
476}546}
477547
478#define ZORBA_INTEGER_OP(OP) \548#define ZORBA_INTEGER_OP(OP) \
479 TEMPLATE_DECL(T) inline \549 TEMPLATE_DECL(I) inline \
480 INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator OP( IntegerImpl const &i ) { \550 INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator OP( IntegerImpl const &i ) { \
481 value_ OP i.value_; \551 value_ OP i.value_; \
482 return *this; \552 return *this; \
483 }553 }
@@ -488,39 +558,62 @@
488ZORBA_INTEGER_OP(%=)558ZORBA_INTEGER_OP(%=)
489#undef ZORBA_INTEGER_OP559#undef ZORBA_INTEGER_OP
490560
491TEMPLATE_DECL(T)561TEMPLATE_DECL(I)
492inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator/=( IntegerImpl const &i ) {562inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator/=( IntegerImpl const &i ) {
493 value_ = ftoi( value_ / i.value_ );563 value_ = ftoi( value_ / i.value_ );
494 return *this;564 return *this;
495}565}
496566
497TEMPLATE_DECL(T)567#define ZORBA_INTEGER_OP(OP) \
498inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator-() const {568 TEMPLATE_DECL(I) template<typename A> inline \
499 return -value_;569 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
500}570 INTEGER_IMPL(I)&>::type \
501571 INTEGER_IMPL(I)::operator OP( A n ) { \
502TEMPLATE_DECL(T)572 value_ OP cast( n ); \
503inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator++() {573 return *this; \
574 }
575
576ZORBA_INTEGER_OP(+=)
577ZORBA_INTEGER_OP(-=)
578ZORBA_INTEGER_OP(*=)
579ZORBA_INTEGER_OP(%=)
580#undef ZORBA_INTEGER_OP
581
582TEMPLATE_DECL(I) template<typename A> inline
583typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
584 INTEGER_IMPL(I)&>::type
585INTEGER_IMPL(I)::operator/=( A n ) {
586 value_ = ftoi( value_ / cast( n ) );
587 return *this;
588}
589
590TEMPLATE_DECL(I)
591inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator-() const {
592 return INTEGER_IMPL(I)( -value_ );
593}
594
595TEMPLATE_DECL(I)
596inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator++() {
504 ++value_;597 ++value_;
505 return *this;598 return *this;
506}599}
507600
508TEMPLATE_DECL(T)601TEMPLATE_DECL(I)
509inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator++(int) {602inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator++(int) {
510 INTEGER_IMPL(T) const result( *this );603 INTEGER_IMPL(I) const result( *this );
511 ++value_;604 ++value_;
512 return result;605 return result;
513}606}
514607
515TEMPLATE_DECL(T)608TEMPLATE_DECL(I)
516inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator--() {609inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator--() {
517 --value_;610 --value_;
518 return *this;611 return *this;
519}612}
520613
521TEMPLATE_DECL(T)614TEMPLATE_DECL(I)
522inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator--(int) {615inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator--(int) {
523 INTEGER_IMPL(T) const result( *this );616 INTEGER_IMPL(I) const result( *this );
524 --value_;617 --value_;
525 return result;618 return result;
526}619}
@@ -528,8 +621,8 @@
528////////// relational operators ///////////////////////////////////////////////621////////// relational operators ///////////////////////////////////////////////
529622
530#define ZORBA_INTEGER_OP(OP) \623#define ZORBA_INTEGER_OP(OP) \
531 TEMPLATE_DECL(T) inline \624 TEMPLATE_DECL(I) inline \
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 ) { \
533 return i.value_ OP j.value_; \626 return i.value_ OP j.value_; \
534 }627 }
535628
@@ -541,6 +634,27 @@
541ZORBA_INTEGER_OP(>=)634ZORBA_INTEGER_OP(>=)
542#undef ZORBA_INTEGER_OP635#undef ZORBA_INTEGER_OP
543636
637#define ZORBA_INTEGER_OP(OP) \
638 TEMPLATE_DECL2(I,A) inline \
639 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \
640 operator OP( INTEGER_IMPL(I) const &i, A n ) { \
641 return i.value_ OP INTEGER_IMPL(I)::cast( n ); \
642 } \
643 \
644 TEMPLATE_DECL2(I,A) inline \
645 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \
646 operator OP( A n, INTEGER_IMPL(I) const &i ) { \
647 return INTEGER_IMPL(I)::cast( n ) OP i.value_; \
648 } \
649
650 ZORBA_INTEGER_OP(==)
651 ZORBA_INTEGER_OP(!=)
652 ZORBA_INTEGER_OP(< )
653 ZORBA_INTEGER_OP(<=)
654 ZORBA_INTEGER_OP(> )
655 ZORBA_INTEGER_OP(>=)
656#undef ZORBA_INTEGER_OP
657
544////////// miscellaneous //////////////////////////////////////////////////////658////////// miscellaneous //////////////////////////////////////////////////////
545659
546#ifdef ZORBA_WITH_BIG_INTEGER660#ifdef ZORBA_WITH_BIG_INTEGER
@@ -555,31 +669,31 @@
555669
556#else670#else
557671
558template<typename IntType>672template<typename I>
559inline int IntegerImpl<IntType>::compare( IntegerImpl const &i ) const {673inline int IntegerImpl<I>::compare( IntegerImpl const &i ) const {
560 return value_ < i.value_ ? -1 : value_ > i.value_ ? 1 : 0;674 return value_ < i.value_ ? -1 : value_ > i.value_ ? 1 : 0;
561}675}
562676
563template<typename IntType>677template<typename I>
564inline uint32_t IntegerImpl<IntType>::hash() const {678inline uint32_t IntegerImpl<I>::hash() const {
565 return static_cast<uint32_t>( value_ );679 return static_cast<uint32_t>( value_ );
566}680}
567681
568template<typename IntType>682template<typename I>
569inline bool IntegerImpl<IntType>::is_long() const {683inline bool IntegerImpl<I>::is_long() const {
570 return value_ >= std::numeric_limits<long>::min() &&684 return value_ >= std::numeric_limits<long>::min() &&
571 value_ <= std::numeric_limits<long>::max();685 value_ <= std::numeric_limits<long>::max();
572}686}
573687
574template<typename IntType>688template<typename I>
575inline int IntegerImpl<IntType>::sign() const {689inline int IntegerImpl<I>::sign() const {
576 return ztd::lt0( value_ ) ? -1 : value_ > 0 ? 1 : 0;690 return ztd::lt0( value_ ) ? -1 : value_ > 0 ? 1 : 0;
577}691}
578692
579#endif /* ZORBA_WITH_BIG_INTEGER */693#endif /* ZORBA_WITH_BIG_INTEGER */
580694
581TEMPLATE_DECL(T)695TEMPLATE_DECL(I)
582inline std::ostream& operator<<( std::ostream &os, INTEGER_IMPL(T) const &i ) {696inline std::ostream& operator<<( std::ostream &os, INTEGER_IMPL(I) const &i ) {
583 return os << i.toString();697 return os << i.toString();
584}698}
585699

Subscribers

People subscribed via source and target branches