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
1=== modified file 'src/annotations/annotations.h'
2--- src/annotations/annotations.h 2012-03-30 19:03:09 +0000
3+++ src/annotations/annotations.h 2012-04-16 15:38:09 +0000
4@@ -83,7 +83,7 @@
5 };
6
7 protected:
8- typedef std::bitset<zann_end + 1> RuleBitSet;
9+ typedef std::bitset<static_cast<int>(zann_end) + 1> RuleBitSet;
10
11 protected:
12 static std::vector<store::Item_t> theAnnotId2NameMap;
13
14=== modified file 'src/compiler/rewriter/rules/flwor_rules.cpp'
15--- src/compiler/rewriter/rules/flwor_rules.cpp 2012-04-05 18:06:01 +0000
16+++ src/compiler/rewriter/rules/flwor_rules.cpp 2012-04-16 15:38:09 +0000
17@@ -1037,7 +1037,7 @@
18 err::XPTY0004);
19
20 if (TypeOps::is_subtype(tm, *valType, *rtm.INTEGER_TYPE_ONE, posLoc) &&
21- val->getIntegerValue() >= xs_integer::one())
22+ val->getIntegerValue() >= 1)
23 {
24 return true;
25 }
26
27=== modified file 'src/compiler/rewriter/rules/fold_rules.cpp'
28--- src/compiler/rewriter/rules/fold_rules.cpp 2012-03-30 19:03:09 +0000
29+++ src/compiler/rewriter/rules/fold_rules.cpp 2012-04-16 15:38:09 +0000
30@@ -928,19 +928,19 @@
31 {
32 xs_integer ival = val->getIntegerValue();
33
34- if (ival < xs_integer::zero())
35+ if (ival < 0)
36 {
37 if (!count_expr->isNonDiscardable())
38 return new const_expr(val_expr->get_sctx(), LOC(val_expr), false);
39 }
40- else if (ival == xs_integer::zero())
41+ else if (ival == 0)
42 {
43 return expr_tools::fix_annotations(
44 new fo_expr(fo.get_sctx(), fo.get_loc(),
45 GET_BUILTIN_FUNCTION(FN_EMPTY_1),
46 count_expr->get_arg(0)));
47 }
48- else if (ival == xs_integer::one())
49+ else if (ival == 1)
50 {
51 return expr_tools::fix_annotations(
52 new fo_expr(fo.get_sctx(),
53
54=== modified file 'src/compiler/translator/translator.cpp'
55--- src/compiler/translator/translator.cpp 2012-04-12 02:08:10 +0000
56+++ src/compiler/translator/translator.cpp 2012-04-16 15:38:09 +0000
57@@ -9754,8 +9754,8 @@
58 {
59 case FunctionConsts::FN_HEAD_1:
60 {
61- arguments.push_back(new const_expr(theRootSctx, loc, xs_integer(1)));
62- arguments.push_back(new const_expr(theRootSctx, loc, xs_integer(1)));
63+ arguments.push_back(new const_expr(theRootSctx, loc, xs_integer::one()));
64+ arguments.push_back(new const_expr(theRootSctx, loc, xs_integer::one()));
65 function* f = GET_BUILTIN_FUNCTION(OP_ZORBA_SUBSEQUENCE_INT_3);
66 fo_expr_t foExpr = new fo_expr(theRootSctx, loc, f, arguments);
67 normalize_fo(foExpr);
68
69=== modified file 'src/runtime/collections/collections_impl.cpp'
70--- src/runtime/collections/collections_impl.cpp 2012-04-14 06:12:29 +0000
71+++ src/runtime/collections/collections_impl.cpp 2012-04-16 15:38:09 +0000
72@@ -451,7 +451,7 @@
73 {
74 store::Collection_t collection;
75 store::Item_t node;
76- xs_integer pos = 1;
77+ xs_integer pos( 1 );
78 bool found;
79
80 PlanIteratorState* state;
81@@ -466,8 +466,7 @@
82
83 found = collection->findNode(node, pos);
84 ZORBA_ASSERT(found);
85- STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, pos+xs_integer(1)),
86- state);
87+ STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, pos+1), state);
88 }
89
90 STACK_END (state);
91@@ -1638,7 +1637,7 @@
92 const StaticallyKnownCollection* collectionDecl;
93 store::Item_t collectionName;
94 store::Item_t numNodesItem;
95- xs_integer numNodes = 1;
96+ xs_integer numNodes( 1 );
97 std::vector<store::Item_t> nodes;
98 std::auto_ptr<store::PUL> pul;
99
100@@ -1674,7 +1673,7 @@
101 // create the pul and add the primitive
102 pul.reset(GENV_ITEMFACTORY->createPendingUpdateList());
103
104- for (xs_integer i = 0; i < numNodes; ++i)
105+ for (xs_integer i( 0 ); i < numNodes; ++i)
106 nodes.push_back(collection->nodeAt(i));
107
108 pul->addDeleteFromCollection(&loc, collectionName, nodes, false, theDynamicCollection);
109@@ -1762,7 +1761,7 @@
110 const StaticallyKnownCollection* collectionDecl;
111 store::Item_t collectionName;
112 store::Item_t numNodesItem;
113- xs_integer numNodes = 1;
114+ xs_integer numNodes( 1 );
115 std::vector<store::Item_t> nodes;
116 std::auto_ptr<store::PUL> pul;
117
118@@ -1796,7 +1795,7 @@
119 // create the pul and add the primitive
120 pul.reset(GENV_ITEMFACTORY->createPendingUpdateList());
121
122- for (xs_integer i = numNodes; i > xs_integer(0); --i)
123+ for (xs_integer i = numNodes; i > 0; --i)
124 nodes.push_back(collection->nodeAt(collection->size() - i));
125
126 pul->addDeleteFromCollection(&loc, collectionName, nodes, true, theDynamicCollection);
127
128=== modified file 'src/runtime/core/gflwor/window_iterator.cpp'
129--- src/runtime/core/gflwor/window_iterator.cpp 2012-04-09 23:08:06 +0000
130+++ src/runtime/core/gflwor/window_iterator.cpp 2012-04-16 15:38:09 +0000
131@@ -150,7 +150,7 @@
132
133 if (!theCurVars.empty())
134 {
135- aInputSeq->getItem(aPosition, lItem);
136+ aInputSeq->getItem(xs_integer(aPosition), lItem);
137 bindVariables(lItem, theCurVars, aPlanState);
138 }
139
140@@ -158,7 +158,7 @@
141 {
142 if (aPosition > 1)
143 {
144- aInputSeq->getItem(aPosition - 1, lItem);
145+ aInputSeq->getItem(xs_integer(aPosition - 1), lItem);
146 }
147 else
148 {
149@@ -170,9 +170,9 @@
150
151 if (!theNextVars.empty())
152 {
153- if (aInputSeq->containsItem(aPosition + 1))
154+ if (aInputSeq->containsItem(xs_integer(aPosition + 1)))
155 {
156- aInputSeq->getItem(aPosition + 1, lItem);
157+ aInputSeq->getItem(xs_integer(aPosition + 1), lItem);
158 }
159 else
160 {
161@@ -185,7 +185,7 @@
162 if (!thePosVars.empty())
163 {
164 store::Item_t lPosItem;
165- GENV_ITEMFACTORY->createInteger(lPosItem, Integer(aPosition));
166+ GENV_ITEMFACTORY->createInteger(lPosItem, xs_integer(aPosition));
167 bindVariables(lPosItem, thePosVars, aPlanState);
168 }
169 }
170@@ -208,7 +208,7 @@
171
172 if (!theCurOuterVars.empty())
173 {
174- aInputSeq->getItem(aPosition, lItem);
175+ aInputSeq->getItem(xs_integer(aPosition), lItem);
176 bindVariables(lItem, theCurOuterVars, aPlanState);
177 }
178
179@@ -216,7 +216,7 @@
180 {
181 if (aPosition > 1)
182 {
183- aInputSeq->getItem(aPosition - 1, lItem);
184+ aInputSeq->getItem(xs_integer(aPosition - 1), lItem);
185 }
186 else
187 {
188@@ -228,9 +228,9 @@
189
190 if (!theNextOuterVars.empty())
191 {
192- if (aInputSeq->containsItem(aPosition + 1))
193+ if (aInputSeq->containsItem(xs_integer(aPosition + 1)))
194 {
195- aInputSeq->getItem(aPosition + 1, lItem);
196+ aInputSeq->getItem(xs_integer(aPosition + 1), lItem);
197 }
198 else
199 {
200@@ -716,11 +716,14 @@
201 ulong aStartPos,
202 ulong aEndPos) const
203 {
204+ xs_integer const lStartPos( aStartPos );
205+ xs_integer const lEndPos( aEndPos );
206+
207 for (std::vector<LetVarIter_t>::const_iterator lVarIter = theVarRefs.begin();
208 lVarIter != theVarRefs.end();
209 ++lVarIter)
210 {
211- (*lVarIter)->bind(aInputSeq, aPlanState, aStartPos, aEndPos);
212+ (*lVarIter)->bind(aInputSeq, aPlanState, lStartPos, lEndPos);
213 }
214 }
215
216@@ -736,13 +739,13 @@
217 if (lState->theOpenWindows.empty())
218 {
219 if (lState->theCurInputPos > theMaxNeededHistory)
220- lState->theDomainSeq->purgeUpTo(lState->theCurInputPos - theMaxNeededHistory);
221+ lState->theDomainSeq->purgeUpTo(xs_integer(lState->theCurInputPos - theMaxNeededHistory));
222 }
223 else
224 {
225 int32_t lPurgeTo = lState->theOpenWindows.front().theStartPos - theMaxNeededHistory;
226 if (lPurgeTo > 0)
227- lState->theDomainSeq->purgeUpTo(lPurgeTo);
228+ lState->theDomainSeq->purgeUpTo(xs_integer(lPurgeTo));
229 }
230 }
231 }
232@@ -769,7 +772,8 @@
233 if (theWindowType == WindowIterator::SLIDING)
234 {
235 // Get the next item from the domain sequence
236- while (lState->theDomainSeq->containsItem(lState->theCurInputPos))
237+ // TODO: can the xs_integer be hoisted?
238+ while (lState->theDomainSeq->containsItem(xs_integer(lState->theCurInputPos)))
239 {
240 // If the current item satisfies the start condition, create a candidate
241 // window starting at the current domain item.
242@@ -857,7 +861,8 @@
243 // Doing this switch now also avoids further overhad
244 if (theEndClause.theHasEndClause)
245 {
246- while (lState->theDomainSeq->containsItem(lState->theCurInputPos))
247+ // TODO: can the xs_integer be hoisted?
248+ while (lState->theDomainSeq->containsItem(xs_integer(lState->theCurInputPos)))
249 {
250 if (lState->theOpenWindows.empty() &&
251 theStartClause.evaluate(aPlanState,
252@@ -898,7 +903,8 @@
253 }
254 else
255 {
256- while (lState->theDomainSeq->containsItem(lState->theCurInputPos))
257+ // TODO: can the xs_integer be hoisted?
258+ while (lState->theDomainSeq->containsItem(xs_integer(lState->theCurInputPos)))
259 {
260 if (theStartClause.evaluate(aPlanState,
261 lState->theDomainSeq,
262
263=== modified file 'src/runtime/core/trycatch.cpp'
264--- src/runtime/core/trycatch.cpp 2012-04-09 23:08:06 +0000
265+++ src/runtime/core/trycatch.cpp 2012-04-16 15:38:09 +0000
266@@ -274,7 +274,8 @@
267
268 // function arity
269 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
270- GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getFnArity() );
271+ GENV_ITEMFACTORY->createInteger(
272+ lTmpValue, xs_integer(lIter->getFnArity()));
273 GENV_ITEMFACTORY->createAttributeNode(
274 lTmpAttr, lFunction.getp(), lArityQName, lTypeName,
275 lTmpValue);
276@@ -289,28 +290,31 @@
277
278 // location line begin
279 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
280- GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getLine() );
281+ GENV_ITEMFACTORY->createInteger( lTmpValue, xs_integer(lIter->getLine()) );
282 GENV_ITEMFACTORY->createAttributeNode(
283 lTmpAttr, lLocation.getp(), lLineBeginQName, lTypeName,
284 lTmpValue);
285
286 // location line end
287 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
288- GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getLineEnd() );
289+ GENV_ITEMFACTORY->createInteger(
290+ lTmpValue, xs_integer(lIter->getLineEnd()));
291 GENV_ITEMFACTORY->createAttributeNode(
292 lTmpAttr, lLocation.getp(), lLineEndQName, lTypeName,
293 lTmpValue);
294
295 // location column begin
296 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
297- GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getColumn() );
298+ GENV_ITEMFACTORY->createInteger(
299+ lTmpValue, xs_integer(lIter->getColumn()));
300 GENV_ITEMFACTORY->createAttributeNode(
301 lTmpAttr, lLocation.getp(), lColumnBeginQName, lTypeName,
302 lTmpValue);
303
304 // location column end
305 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
306- GENV_ITEMFACTORY->createInteger( lTmpValue, lIter->getColumnEnd() );
307+ GENV_ITEMFACTORY->createInteger(
308+ lTmpValue, xs_integer(lIter->getColumnEnd()));
309 GENV_ITEMFACTORY->createAttributeNode(
310 lTmpAttr, lLocation.getp(), lColumnEndQName, lTypeName,
311 lTmpValue);
312@@ -446,7 +450,8 @@
313 if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) &&
314 ue->has_source() ) {
315 store::Item_t lErrorLineItem;
316- GENV_ITEMFACTORY->createInteger(lErrorLineItem, ue->source_line());
317+ GENV_ITEMFACTORY->createInteger(
318+ lErrorLineItem, xs_integer(ue->source_line()));
319 lErrorLineIter = new ItemIterator(lErrorLineItem);
320 }
321 else
322@@ -472,7 +477,8 @@
323 if ( ( ue = dynamic_cast<XQueryException const*>( &e ) ) &&
324 ue->has_source() ) {
325 store::Item_t lErrorColumnItem;
326- GENV_ITEMFACTORY->createInteger(lErrorColumnItem, ue->source_column());
327+ GENV_ITEMFACTORY->createInteger(
328+ lErrorColumnItem, xs_integer(ue->source_column()));
329 lErrorColumnIter = new ItemIterator(lErrorColumnItem);
330 }
331 else
332
333=== modified file 'src/runtime/maths/maths_impl.cpp'
334--- src/runtime/maths/maths_impl.cpp 2012-03-30 19:03:09 +0000
335+++ src/runtime/maths/maths_impl.cpp 2012-04-16 15:38:09 +0000
336@@ -500,7 +500,7 @@
337 PlanIteratorState* state;
338 DEFAULT_STACK_INIT ( PlanIteratorState, state, planState );
339
340- GENV_ITEMFACTORY->createDouble(result, 3.141592653589793e0);
341+ GENV_ITEMFACTORY->createDouble(result, xs_double(3.141592653589793e0));
342 STACK_PUSH (true, state);
343
344 STACK_END (state);
345
346=== modified file 'src/runtime/numerics/format_integer_impl.cpp'
347--- src/runtime/numerics/format_integer_impl.cpp 2012-03-30 19:03:09 +0000
348+++ src/runtime/numerics/format_integer_impl.cpp 2012-04-16 15:38:09 +0000
349@@ -164,8 +164,8 @@
350 static const unsigned int letter_range = 'Z' - 'A' + 1;
351 static xs_integer integer_digit(letter_range);
352 xs_integer upper_int = valueInteger/integer_digit;
353- if(upper_int > xs_integer::zero())
354- formatIntegerAZ(upper_int - xs_integer::one(), c0, resultString);
355+ if(upper_int > 0)
356+ formatIntegerAZ(upper_int - 1, c0, resultString);
357 xs_integer mod_integer = valueInteger % integer_digit;
358 xs_int mod_int = to_xs_int(mod_integer);
359 resultString += (c0 + mod_int);
360@@ -426,7 +426,7 @@
361 formatIntegerEnglish(valueInteger/integer_##big_number_name, false, resultString); \
362 resultString += " " #big_number_name; \
363 value_mod = valueInteger % integer_##big_number_name; \
364- if(value_mod > xs_integer::zero()) \
365+ if(value_mod > 0) \
366 { \
367 resultString += " "; \
368 formatIntegerEnglish(value_mod, is_ordinal, resultString); \
369@@ -439,7 +439,7 @@
370 else if (valueInteger >= integer_##decim) \
371 { \
372 value_mod = valueInteger % integer_##decim; \
373- if(value_mod > xs_integer::zero()) \
374+ if(value_mod > 0) \
375 { \
376 resultString += decim_cardinal; \
377 resultString += "-"; \
378@@ -504,7 +504,7 @@
379 IF_GE_DECIM(3, "three", "third")
380 IF_GE_DECIM(2, "two", "second")
381 IF_GE_DECIM(1, "one", "first")
382- else if (valueInteger == xs_integer::zero())
383+ else if (valueInteger == 0)
384 {
385 if(!is_ordinal)
386 resultString += "zero";
387@@ -771,7 +771,7 @@
388 if (consumeNext(value_item, theChildren[0].getp(), planState))
389 {
390 valueInteger = value_item->getIntegerValue();
391- if(valueInteger < xs_integer::zero())
392+ if(valueInteger < 0)
393 {
394 valueInteger = -valueInteger;
395 is_neg = true;
396@@ -811,17 +811,17 @@
397 if((c0 == 'a') || (c0 == 'A'))
398 {
399 checkOptionalModifier(utf8_picture, 1, &is_ordinal, &is_traditional, utf8_word_terminal);
400- if(valueInteger > xs_integer::zero())
401+ if(valueInteger > 0)
402 {
403 if(is_neg)
404 resultString += '-';
405- formatIntegerAZ(valueInteger-xs_integer::one(), c0, resultString);
406+ formatIntegerAZ(valueInteger-1, c0, resultString);
407 }
408 }
409 else if((c0 == 'i') || (c0 == 'I'))
410 {
411 checkOptionalModifier(utf8_picture, 1, &is_ordinal, &is_traditional, utf8_word_terminal);
412- if(valueInteger > xs_integer::zero())
413+ if(valueInteger > 0)
414 {
415 if(is_neg)
416 resultString += ("-");
417
418=== modified file 'src/runtime/random/random_impl.cpp'
419--- src/runtime/random/random_impl.cpp 2012-03-30 19:03:09 +0000
420+++ src/runtime/random/random_impl.cpp 2012-04-16 15:38:09 +0000
421@@ -45,7 +45,7 @@
422
423 consumeNext(seed, theChildren[0].getp(), planState);
424 consumeNext(num, theChildren[1].getp(), planState);
425- if ( num->getIntegerValue() < xs_integer( 0 ) )
426+ if ( num->getIntegerValue() < 0 )
427 {
428 STACK_PUSH(false, state);
429 }
430@@ -110,7 +110,7 @@
431 DEFAULT_STACK_INIT(RandomIteratorState, state, planState);
432
433 consumeNext(num, theChildren[0].getp(), planState);
434- if ( num->getIntegerValue() < xs_integer( 0 ) )
435+ if ( num->getIntegerValue() < 0 )
436 {
437 STACK_PUSH(false, state);
438 }
439
440=== modified file 'src/runtime/sequences/sequences_impl.cpp'
441--- src/runtime/sequences/sequences_impl.cpp 2012-03-30 19:03:09 +0000
442+++ src/runtime/sequences/sequences_impl.cpp 2012-04-16 15:38:09 +0000
443@@ -322,12 +322,12 @@
444 }
445
446 state->thePosition = lPositionItem->getIntegerValue();
447- if (state->thePosition < xs_integer::one())
448- state->thePosition = xs_integer::one();
449+ if (state->thePosition < 1)
450+ state->thePosition = 1;
451
452 while (consumeNext(result, theChildren[0].getp(), planState))
453 {
454- if ( state->theCurrentPos == state->thePosition-xs_integer::one() ) // position found => insert sequence
455+ if ( state->theCurrentPos == state->thePosition-1 ) // position found => insert sequence
456 {
457 state->theTargetItem = result;
458 while ( consumeNext(result, theChildren[2].getp(), planState))
459
460=== modified file 'src/runtime/store/maps_impl.cpp'
461--- src/runtime/store/maps_impl.cpp 2012-03-30 19:03:09 +0000
462+++ src/runtime/store/maps_impl.cpp 2012-04-16 15:38:09 +0000
463@@ -540,7 +540,7 @@
464 );
465 }
466
467- GENV_ITEMFACTORY->createInteger(result, lIndex->size());
468+ GENV_ITEMFACTORY->createInteger(result, xs_integer(lIndex->size()));
469
470 STACK_PUSH(true, state);
471
472
473=== modified file 'src/store/naive/atomic_items.cpp'
474--- src/store/naive/atomic_items.cpp 2012-03-30 19:03:09 +0000
475+++ src/store/naive/atomic_items.cpp 2012-04-16 15:38:09 +0000
476@@ -1472,7 +1472,7 @@
477 store::Item_t StructuralAnyUriItem::getLevel() const
478 {
479 store::Item_t lResult;
480- GET_FACTORY().createInteger(lResult, theOrdPath.getLevel());
481+ GET_FACTORY().createInteger(lResult, xs_integer(theOrdPath.getLevel()));
482 return lResult;
483 }
484
485@@ -2747,7 +2747,7 @@
486 }
487
488 xs_nonNegativeInteger LongItem::getUnsignedIntegerValue() const {
489- return theValue >= 0 ? theValue : -theValue;
490+ return xs_nonNegativeInteger( theValue >= 0 ? theValue : -theValue );
491 }
492
493 store::Item* LongItem::getType() const
494
495=== modified file 'src/store/naive/collection.h'
496--- src/store/naive/collection.h 2012-03-28 23:58:23 +0000
497+++ src/store/naive/collection.h 2012-04-16 15:38:09 +0000
498@@ -65,7 +65,7 @@
499
500 /************************* Updates on collection ****************************/
501
502- virtual void addNode(store::Item* node, xs_integer position = -1) = 0;
503+ virtual void addNode(store::Item* node, xs_integer position = xs_integer(-1)) = 0;
504
505 virtual zorba::xs_integer addNodes(
506 std::vector<store::Item_t>& nodes,
507
508=== modified file 'src/store/naive/node_items.cpp'
509--- src/store/naive/node_items.cpp 2012-04-12 02:08:10 +0000
510+++ src/store/naive/node_items.cpp 2012-04-16 15:38:09 +0000
511@@ -1294,7 +1294,7 @@
512 lCurrent = lCurrent->getParent();
513 }
514 store::Item_t lRes;
515- GET_FACTORY().createInteger(lRes, lNumLevels);
516+ GET_FACTORY().createInteger(lRes, xs_integer(lNumLevels));
517 return lRes;
518 }
519
520
521=== modified file 'src/store/naive/pul_primitives.cpp'
522--- src/store/naive/pul_primitives.cpp 2012-03-30 19:03:09 +0000
523+++ src/store/naive/pul_primitives.cpp 2012-04-16 15:38:09 +0000
524@@ -986,7 +986,7 @@
525
526 for (uint64_t i = 0; i < size; ++i)
527 {
528- XmlNode* root = static_cast<XmlNode*>(collection->nodeAt(i).getp());
529+ XmlNode* root = static_cast<XmlNode*>(collection->nodeAt(xs_integer(i)).getp());
530 XmlTree* tree = root->getTree();
531 if (tree->getRefCount() > 1)
532 throw XQUERY_EXCEPTION(
533@@ -1021,7 +1021,7 @@
534 std::size_t numNodes = theNodes.size();
535 for (std::size_t i = 0; i < numNodes; ++i)
536 {
537- lColl->addNode(theNodes[i], -1);
538+ lColl->addNode(theNodes[i], xs_integer(-1));
539 ++theNumApplied;
540 }
541 }
542@@ -1051,9 +1051,10 @@
543
544 for (long i = theNumApplied-1; i >= 0; --i)
545 {
546- ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(lastPos));
547+ xs_integer xs_lastPos( lastPos );
548+ ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(xs_lastPos));
549
550- lColl->removeNode(lastPos);
551+ lColl->removeNode(xs_lastPos);
552 --lastPos;
553 }
554 }
555@@ -1075,7 +1076,7 @@
556 std::size_t numNodes = theNodes.size();
557 for (std::size_t i = 0; i < numNodes; ++i)
558 {
559- lColl->addNode(theNodes[i], i);
560+ lColl->addNode(theNodes[i], xs_integer(i));
561 ++theNumApplied;
562 }
563 }
564@@ -1087,11 +1088,12 @@
565 (GET_STORE().getCollection(theName, theDynamicCollection).getp());
566 assert(lColl);
567
568+ xs_integer const zero( xs_integer::zero() );
569 for (std::size_t i = 0; i < theNumApplied; ++i)
570 {
571- ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(0));
572+ ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(zero));
573
574- lColl->removeNode((uint64_t)0);
575+ lColl->removeNode(zero);
576 }
577 }
578
579@@ -1108,9 +1110,10 @@
580 theIsApplied = true;
581
582 std::size_t numNodes = theNodes.size();
583+ xs_integer const neg_1( -1 );
584 for (std::size_t i = 0; i < numNodes; ++i)
585 {
586- lColl->addNode(theNodes[i], -1);
587+ lColl->addNode(theNodes[i], neg_1);
588 }
589 }
590
591@@ -1135,11 +1138,12 @@
592 );
593 }
594
595+ xs_integer const xs_lastPos( lastPos );
596 for (long i = theNumApplied-1; i >= 0; --i)
597 {
598- ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(lastPos));
599+ ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(xs_lastPos));
600
601- lColl->removeNode(lastPos);
602+ lColl->removeNode(xs_lastPos);
603 }
604 }
605
606@@ -1170,7 +1174,7 @@
607 assert(lColl);
608 ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos));
609
610- lColl->removeNodes(theFirstPos, (uint64_t)theNodes.size());
611+ lColl->removeNodes(theFirstPos, xs_integer(theNodes.size()));
612 }
613
614
615@@ -1201,7 +1205,7 @@
616 assert(lColl);
617 ZORBA_ASSERT(theFirstNode == lColl->nodeAt(theFirstPos));
618
619- lColl->removeNodes(theFirstPos, (uint64_t)theNodes.size());
620+ lColl->removeNodes(theFirstPos, xs_integer(theNodes.size()));
621 }
622
623
624@@ -1240,7 +1244,7 @@
625 {
626 for (std::size_t i = numNodes; i > 0; --i)
627 {
628- if (theNodes[i-1] != lColl->nodeAt(size - i))
629+ if (theNodes[i-1] != lColl->nodeAt(xs_integer(size - i)))
630 {
631 isLast = false;
632 break;
633
634=== modified file 'src/store/naive/simple_collection.cpp'
635--- src/store/naive/simple_collection.cpp 2012-03-30 19:03:09 +0000
636+++ src/store/naive/simple_collection.cpp 2012-04-16 15:38:09 +0000
637@@ -124,16 +124,16 @@
638
639 SYNC_CODE(AutoLatch lock(theLatch, Latch::WRITE););
640
641- if (lPosition < 0 || to_xs_unsignedLong(lPosition) >= theXmlTrees.size())
642+ if (lPosition < 0 || lPosition >= theXmlTrees.size())
643 {
644 theXmlTrees.push_back(nodeItem);
645- node->setCollection(this, (uint64_t)theXmlTrees.size() - 1);
646+ node->setCollection(this, xs_integer(theXmlTrees.size() - 1));
647 }
648 else
649 {
650
651 theXmlTrees.insert(theXmlTrees.begin() + (std::size_t)lPosition, nodeItem);
652- node->setCollection(this, to_xs_unsignedInt(lPosition));
653+ node->setCollection(this, xs_integer(lPosition));
654 }
655 }
656
657@@ -203,7 +203,7 @@
658 );
659 }
660
661- node->setCollection(this, lTargetPos + i);
662+ node->setCollection(this, xs_integer(lTargetPos + i));
663 }
664
665 theXmlTrees.resize(numNodes + numNewNodes);
666@@ -232,7 +232,7 @@
667 theXmlTrees[lTargetPos + i].transfer(nodes[i]);
668 }
669
670- return lTargetPos;
671+ return xs_integer( lTargetPos );
672 }
673
674
675@@ -261,7 +261,7 @@
676 {
677 ZORBA_ASSERT(node->getCollection() == this);
678
679- node->setCollection(NULL, 0);
680+ node->setCollection(NULL, xs_integer(0));
681 std::size_t lPosition = to_xs_unsignedInt(position);
682 theXmlTrees.erase(theXmlTrees.begin() + lPosition);
683 return true;
684@@ -292,7 +292,7 @@
685 XmlNode* node = static_cast<XmlNode*>(theXmlTrees[lPosition].getp());
686 ZORBA_ASSERT(node->getCollection() == this);
687
688- node->setCollection(NULL, 0);
689+ node->setCollection(NULL, xs_integer(0));
690 theXmlTrees.erase(theXmlTrees.begin() + lPosition);
691 return true;
692 }
693@@ -314,7 +314,7 @@
694
695 if (lNum == 0 || lPosition >= theXmlTrees.size())
696 {
697- return 0;
698+ return xs_integer(0);
699 }
700 else
701 {
702@@ -328,12 +328,12 @@
703 {
704 XmlNode* node = static_cast<XmlNode*>(theXmlTrees[lPosition].getp());
705 ZORBA_ASSERT(node->getCollection() == this);
706- node->setCollection(NULL, 0);
707+ node->setCollection(NULL, xs_integer(0));
708
709 theXmlTrees.erase(theXmlTrees.begin() + lPosition);
710 }
711
712- return last-lPosition;
713+ return xs_integer(last-lPosition);
714 }
715 }
716
717@@ -434,7 +434,7 @@
718
719 for (std::size_t i = 0; i < numTrees; ++i)
720 {
721- BASE_NODE(theXmlTrees[i])->getTree()->setPosition(i);
722+ BASE_NODE(theXmlTrees[i])->getTree()->setPosition(xs_integer(i));
723 }
724 }
725
726
727=== modified file 'src/store/naive/simple_collection.h'
728--- src/store/naive/simple_collection.h 2012-03-30 19:03:09 +0000
729+++ src/store/naive/simple_collection.h 2012-04-16 15:38:09 +0000
730@@ -100,7 +100,7 @@
731
732 const store::Item* getName() const { return theName.getp(); }
733
734- xs_integer size() const { return theXmlTrees.size(); }
735+ xs_integer size() const { return xs_integer( theXmlTrees.size() ); }
736
737 bool isDynamic() const { return theIsDynamic; }
738
739@@ -110,7 +110,7 @@
740
741 store::Iterator_t getIterator();
742
743- void addNode(store::Item* node, xs_integer position = -1);
744+ void addNode(store::Item* node, xs_integer position = xs_integer(-1));
745
746 xs_integer addNodes(
747 std::vector<store::Item_t>& nodes,
748
749=== modified file 'src/store/naive/simple_index_general.cpp'
750--- src/store/naive/simple_index_general.cpp 2012-03-30 19:03:09 +0000
751+++ src/store/naive/simple_index_general.cpp 2012-04-16 15:38:09 +0000
752@@ -1667,13 +1667,13 @@
753 {
754 if (haveLower)
755 {
756- xs_double doubleValue = lowerKey->getDecimalValue();
757+ xs_double const doubleValue( lowerKey->getDecimalValue() );
758 GET_FACTORY().createDouble(lowerAltKey, doubleValue);
759 }
760
761 if (haveUpper)
762 {
763- xs_double doubleValue = upperKey->getDecimalValue();
764+ xs_double const doubleValue( upperKey->getDecimalValue() );
765 GET_FACTORY().createDouble(upperAltKey, doubleValue);
766 }
767
768@@ -1697,13 +1697,13 @@
769 {
770 if (haveLower)
771 {
772- xs_decimal decimalValue = lowerKey->getLongValue();
773+ xs_decimal const decimalValue( lowerKey->getLongValue() );
774 GET_FACTORY().createDecimal(lowerAltKey, decimalValue);
775 }
776
777 if (haveUpper)
778 {
779- xs_decimal decimalValue = upperKey->getLongValue();
780+ xs_decimal const decimalValue( upperKey->getLongValue() );
781 GET_FACTORY().createDecimal(upperAltKey, decimalValue);
782 }
783
784@@ -1714,13 +1714,13 @@
785 {
786 if (haveLower)
787 {
788- xs_double doubleValue = lowerKey->getLongValue();
789+ xs_double doubleValue( lowerKey->getLongValue() );
790 GET_FACTORY().createDouble(lowerAltKey, doubleValue);
791 }
792
793 if (haveUpper)
794 {
795- xs_double doubleValue = upperKey->getLongValue();
796+ xs_double const doubleValue( upperKey->getLongValue() );
797 GET_FACTORY().createDouble(upperAltKey, doubleValue);
798 }
799
800@@ -1772,14 +1772,14 @@
801
802 if (idx->theMaps[store::XS_DOUBLE])
803 {
804- xs_double doubleValue = longItem->getLongValue();
805+ xs_double const doubleValue( longItem->getLongValue() );
806 GET_FACTORY().createDouble(altKey, doubleValue);
807 probeMap(store::XS_DOUBLE, altKey, altKey);
808 }
809
810 if (idx->theMaps[store::XS_DECIMAL])
811 {
812- xs_decimal decimalValue = longItem->getLongValue();
813+ xs_decimal const decimalValue( longItem->getLongValue() );
814 GET_FACTORY().createDecimal(altKey, decimalValue);
815 probeMap(store::XS_DECIMAL, altKey, altKey);
816 }
817@@ -1806,7 +1806,7 @@
818
819 if (idx->theMaps[store::XS_DOUBLE])
820 {
821- xs_double doubleValue = decimalItem->getDecimalValue();
822+ xs_double const doubleValue( decimalItem->getDecimalValue() );
823 GET_FACTORY().createDouble(altKey, doubleValue);
824 probeMap(store::XS_DOUBLE, altKey, altKey);
825 }
826
827=== modified file 'src/store/naive/simple_lazy_temp_seq.cpp'
828--- src/store/naive/simple_lazy_temp_seq.cpp 2012-03-30 19:03:09 +0000
829+++ src/store/naive/simple_lazy_temp_seq.cpp 2012-04-16 15:38:09 +0000
830@@ -238,7 +238,7 @@
831 xs_integer SimpleLazyTempSeq::getSize() const
832 {
833 ZORBA_ASSERT(false);
834- return 0;
835+ return xs_integer(0);
836 }
837
838
839@@ -250,7 +250,7 @@
840 ********************************************************************************/
841 store::Iterator_t SimpleLazyTempSeq::getIterator() const
842 {
843- return new SimpleLazyTempSeqIter(this, 1, std::numeric_limits<long>::max());
844+ return new SimpleLazyTempSeqIter(this, xs_integer(1), xs_integer(std::numeric_limits<long>::max()));
845 }
846
847
848@@ -307,9 +307,9 @@
849
850 bool SimpleLazyTempSeqIter::next(store::Item_t& result)
851 {
852- if (theCurPos < theEndPos && theTempSeq->containsItem(theCurPos+1))
853+ if (theCurPos < theEndPos && theTempSeq->containsItem(xs_integer(theCurPos+1)))
854 {
855- theTempSeq->getItem(++theCurPos, result);
856+ theTempSeq->getItem(xs_integer(++theCurPos), result);
857 return true;
858 }
859 else
860
861=== modified file 'src/store/naive/simple_temp_seq.cpp'
862--- src/store/naive/simple_temp_seq.cpp 2012-03-30 19:03:09 +0000
863+++ src/store/naive/simple_temp_seq.cpp 2012-04-16 15:38:09 +0000
864@@ -133,7 +133,7 @@
865 ********************************************************************************/
866 xs_integer SimpleTempSeq::getSize() const
867 {
868- return theItems.size();
869+ return xs_integer( theItems.size() );
870 }
871
872
873
874=== modified file 'src/zorbatypes/decimal.cpp'
875--- src/zorbatypes/decimal.cpp 2012-04-12 02:08:10 +0000
876+++ src/zorbatypes/decimal.cpp 2012-04-16 15:38:09 +0000
877@@ -334,15 +334,15 @@
878
879 TEMPLATE_DECL(T)
880 Decimal Decimal::round( INTEGER_IMPL(T) const &precision ) const {
881- return round( value_, precision.itod() );
882+ return round2( value_, precision.itod() );
883 }
884 #ifndef ZORBA_WITH_BIG_INTEGER
885 template Decimal Decimal::round( INTEGER_IMPL_LL const& ) const;
886 template Decimal Decimal::round( INTEGER_IMPL_ULL const& ) const;
887 #endif /* ZORBA_WITH_BIG_INTEGER */
888
889-Decimal::value_type Decimal::round( value_type const &v,
890- value_type const &precision ) {
891+Decimal::value_type Decimal::round2( value_type const &v,
892+ value_type const &precision ) {
893 value_type const exp( value_type(10).pow( precision ) );
894 value_type result( v * exp );
895 result += MAPM::get0_5();
896@@ -353,22 +353,22 @@
897
898 TEMPLATE_DECL(T)
899 Decimal Decimal::roundHalfToEven( INTEGER_IMPL(T) const &precision ) const {
900- return roundHalfToEven( value_, precision.itod() );
901+ return roundHalfToEven2( value_, precision.itod() );
902 }
903 #ifndef ZORBA_WITH_BIG_INTEGER
904 template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_LL const& ) const;
905 template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_ULL const& ) const;
906 #endif /* ZORBA_WITH_BIG_INTEGER */
907
908-Decimal::value_type Decimal::roundHalfToEven( value_type const &v,
909- value_type const &precision ) {
910+Decimal::value_type Decimal::roundHalfToEven2( value_type const &v,
911+ value_type const &precision ) {
912 value_type const exp( value_type(10).pow( precision ) );
913 value_type result( v * exp );
914 bool const aHalfVal = (result - MAPM::get0_5()) == result.floor();
915 result += MAPM::get0_5();
916 result = result.floor();
917 if ( aHalfVal && result.is_odd() )
918- result -= 1;
919+ --result;
920 result /= exp;
921 return result;
922 }
923
924=== modified file 'src/zorbatypes/decimal.h'
925--- src/zorbatypes/decimal.h 2012-03-30 19:03:09 +0000
926+++ src/zorbatypes/decimal.h 2012-04-16 15:38:09 +0000
927@@ -21,6 +21,7 @@
928 #include <zorba/config.h>
929
930 #include "common/common.h"
931+#include "util/stl_util.h"
932 #include "zorbaserialization/archiver.h"
933 #include "zorbaserialization/class_serializer.h"
934
935@@ -30,11 +31,11 @@
936 #include "zstring.h"
937
938 #ifdef ZORBA_WITH_BIG_INTEGER
939-# define TEMPLATE_DECL(T) /* nothing */
940-# define INTEGER_IMPL(T) IntegerImpl
941+# define TEMPLATE_DECL(I) /* nothing */
942+# define INTEGER_IMPL(I) IntegerImpl
943 #else
944-# define TEMPLATE_DECL(T) template<typename T>
945-# define INTEGER_IMPL(T) IntegerImpl<T>
946+# define TEMPLATE_DECL(I) template<typename I>
947+# define INTEGER_IMPL(I) IntegerImpl<I>
948 #endif /* ZORBA_WITH_BIG_INTEGER */
949
950 namespace zorba {
951@@ -46,23 +47,22 @@
952
953 ////////// constructors /////////////////////////////////////////////////////
954
955- Decimal( char c );
956- Decimal( signed char c );
957- Decimal( short n );
958- Decimal( int n = 0 );
959- Decimal( long n );
960- Decimal( long long n );
961- Decimal( unsigned char c );
962- Decimal( unsigned short n );
963- Decimal( unsigned int n );
964- Decimal( unsigned long n );
965- Decimal( unsigned long long n );
966- Decimal( float n );
967- Decimal( double n );
968- Decimal( Decimal const &d );
969+ explicit Decimal( char c );
970+ explicit Decimal( signed char c );
971+ explicit Decimal( short n );
972+ explicit Decimal( int n = 0 );
973+ explicit Decimal( long n );
974+ explicit Decimal( long long n );
975+ explicit Decimal( unsigned char c );
976+ explicit Decimal( unsigned short n );
977+ explicit Decimal( unsigned int n );
978+ explicit Decimal( unsigned long n );
979+ explicit Decimal( unsigned long long n );
980+ explicit Decimal( float n );
981+ explicit Decimal( double n );
982
983- TEMPLATE_DECL(T)
984- Decimal( INTEGER_IMPL(T) const &i );
985+ TEMPLATE_DECL(I)
986+ explicit Decimal( INTEGER_IMPL(I) const &i );
987
988 /**
989 * Constructs a %Decimal from a C string.
990@@ -71,7 +71,7 @@
991 * whitespace is ignored.
992 * @throw std::invalid_argument if \a s does not contain a valid decimal.
993 */
994- Decimal( char const *s );
995+ explicit Decimal( char const *s );
996
997 /**
998 * Constructs a %Decimal from a Double.
999@@ -79,7 +79,7 @@
1000 * @param n The Double.
1001 * @throw std::invalid_argument if \a n is not finite.
1002 */
1003- Decimal( Double const &n );
1004+ explicit Decimal( Double const &n );
1005
1006 /**
1007 * Constructs a %Decimal from a Float.
1008@@ -87,30 +87,46 @@
1009 * @param n The Float.
1010 * @throw std::invalid_argument if \a n is not finite.
1011 */
1012- Decimal( Float const &n );
1013+ explicit Decimal( Float const &n );
1014+
1015+ /**
1016+ * Conventional copy constructor.
1017+ *
1018+ * @param d The %Decimal to copy from.
1019+ */
1020+ Decimal( Decimal const &d );
1021
1022 ////////// assignment operators /////////////////////////////////////////////
1023
1024- Decimal& operator=( char c );
1025- Decimal& operator=( signed char c );
1026- Decimal& operator=( short n );
1027- Decimal& operator=( int n );
1028- Decimal& operator=( long n );
1029+ /**
1030+ * Conventional assignment operator.
1031+ *
1032+ * @param d The %Decimal to assign from.
1033+ * @return Returns \c *this.
1034+ */
1035+ Decimal& operator=( Decimal const &d );
1036+
1037+ /**
1038+ * For every built-in arithmetic type A, assign to this %Decimal.
1039+ *
1040+ * @tparam A The built-in arithmetic type.
1041+ * @param n The arithmetic value to assign.
1042+ * @return Returns \c *this.
1043+ */
1044+ template<typename A>
1045+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,Decimal&>::type
1046+ operator=( A n );
1047+
1048+ // These arithmetic types have to be special-cased.
1049 Decimal& operator=( long long n );
1050- Decimal& operator=( unsigned char c );
1051- Decimal& operator=( unsigned short n );
1052- Decimal& operator=( unsigned int n );
1053- Decimal& operator=( unsigned long n );
1054 Decimal& operator=( unsigned long long n );
1055- Decimal& operator=( float n );
1056- Decimal& operator=( double n );
1057+
1058 Decimal& operator=( char const *s );
1059- Decimal& operator=( Decimal const &d );
1060 Decimal& operator=( Double const &d );
1061 Decimal& operator=( Float const &f );
1062
1063- TEMPLATE_DECL(T)
1064- Decimal& operator=( INTEGER_IMPL(T) const &i );
1065+ TEMPLATE_DECL(I)
1066+ Decimal& operator=( INTEGER_IMPL(I) const &i );
1067
1068 ////////// arithmetic operators /////////////////////////////////////////////
1069
1070@@ -121,10 +137,11 @@
1071 friend Decimal operator%( Decimal const&, Decimal const& );
1072
1073 #define ZORBA_DECIMAL_OP(OP) \
1074- TEMPLATE_DECL(T) \
1075- friend Decimal operator OP( Decimal const&, INTEGER_IMPL(T) const& ); \
1076- TEMPLATE_DECL(T) \
1077- friend Decimal operator OP( INTEGER_IMPL(T) const&, Decimal const& )
1078+ TEMPLATE_DECL(I) \
1079+ friend Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \
1080+ \
1081+ TEMPLATE_DECL(I) \
1082+ friend Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& )
1083
1084 ZORBA_DECIMAL_OP(+);
1085 ZORBA_DECIMAL_OP(-);
1086@@ -140,7 +157,7 @@
1087 Decimal& operator%=( Decimal const& );
1088
1089 #define ZORBA_DECIMAL_OP(OP) \
1090- TEMPLATE_DECL(T) Decimal& operator OP( INTEGER_IMPL(T) const& )
1091+ TEMPLATE_DECL(I) Decimal& operator OP( INTEGER_IMPL(I) const& )
1092
1093 ZORBA_DECIMAL_OP(+=);
1094 ZORBA_DECIMAL_OP(-=);
1095@@ -155,10 +172,10 @@
1096
1097 #define ZORBA_DECIMAL_OP(OP) \
1098 friend bool operator OP( Decimal const&, Decimal const& ); \
1099- TEMPLATE_DECL(T) \
1100- friend bool operator OP( Decimal const&, INTEGER_IMPL(T) const& ); \
1101- TEMPLATE_DECL(T) \
1102- friend bool operator OP( INTEGER_IMPL(T) const&, Decimal const& )
1103+ TEMPLATE_DECL(I) \
1104+ friend bool operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \
1105+ TEMPLATE_DECL(I) \
1106+ friend bool operator OP( INTEGER_IMPL(I) const&, Decimal const& )
1107
1108 ZORBA_DECIMAL_OP(==);
1109 ZORBA_DECIMAL_OP(!=);
1110@@ -176,11 +193,11 @@
1111 Decimal floor() const;
1112 Decimal round() const;
1113
1114- TEMPLATE_DECL(T)
1115- Decimal round( INTEGER_IMPL(T) const &precision ) const;
1116+ TEMPLATE_DECL(I)
1117+ Decimal round( INTEGER_IMPL(I) const &precision ) const;
1118
1119- TEMPLATE_DECL(T)
1120- Decimal roundHalfToEven( INTEGER_IMPL(T) const &precision ) const;
1121+ TEMPLATE_DECL(I)
1122+ Decimal roundHalfToEven( INTEGER_IMPL(I) const &precision ) const;
1123
1124 Decimal sqrt() const;
1125
1126@@ -223,16 +240,16 @@
1127
1128 static void reduce( char *s );
1129
1130- static value_type round( value_type const &v, value_type const &precision );
1131+ static value_type round2( value_type const &v, value_type const &precision );
1132
1133- static value_type roundHalfToEven( value_type const &v,
1134- value_type const &precision );
1135+ static value_type roundHalfToEven2( value_type const &v,
1136+ value_type const &precision );
1137
1138 static zstring toString( value_type const&,
1139 int precision = ZORBA_FLOAT_POINT_PRECISION );
1140
1141- TEMPLATE_DECL(T) friend class IntegerImpl;
1142- template<typename T> friend class FloatImpl;
1143+ TEMPLATE_DECL(I) friend class IntegerImpl;
1144+ template<typename F> friend class FloatImpl;
1145
1146 friend xs_long to_xs_long( Decimal const& );
1147 };
1148@@ -274,112 +291,49 @@
1149
1150 ////////// assignment operators ///////////////////////////////////////////////
1151
1152-inline Decimal& Decimal::operator=( char c ) {
1153- value_ = static_cast<long>( c );
1154- return *this;
1155-}
1156-
1157-inline Decimal& Decimal::operator=( signed char c ) {
1158- value_ = static_cast<long>( c );
1159- return *this;
1160-}
1161-
1162-inline Decimal& Decimal::operator=( short n ) {
1163- value_ = static_cast<long>( n );
1164- return *this;
1165-}
1166-
1167-inline Decimal& Decimal::operator=( int n ) {
1168- value_ = static_cast<long>( n );
1169- return *this;
1170-}
1171-
1172-inline Decimal& Decimal::operator=( long n ) {
1173- value_ = n;
1174- return *this;
1175-}
1176-
1177-inline Decimal& Decimal::operator=( unsigned char c ) {
1178- value_ = static_cast<long>( c );
1179- return *this;
1180-}
1181-
1182-inline Decimal& Decimal::operator=( unsigned short n ) {
1183- value_ = static_cast<long>( n );
1184- return *this;
1185-}
1186-
1187-inline Decimal& Decimal::operator=( unsigned int n ) {
1188- value_ = static_cast<long>( n );
1189- return *this;
1190-}
1191-
1192-inline Decimal& Decimal::operator=( float n ) {
1193- value_ = n;
1194- return *this;
1195-}
1196-
1197-inline Decimal& Decimal::operator=( double n ) {
1198- value_ = n;
1199- return *this;
1200-}
1201-
1202-inline Decimal& Decimal::operator=( char const *s ) {
1203- parse( s, &value_ );
1204- return *this;
1205-}
1206-
1207 inline Decimal& Decimal::operator=( Decimal const &d ) {
1208 value_ = d.value_;
1209 return *this;
1210 }
1211
1212+template<typename A> inline
1213+typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,Decimal&>::type
1214+Decimal::operator=( A n ) {
1215+ value_ = static_cast<long>( n );
1216+ return *this;
1217+}
1218+
1219+inline Decimal& Decimal::operator=( char const *s ) {
1220+ parse( s, &value_ );
1221+ return *this;
1222+}
1223+
1224 ////////// arithmetic operators ///////////////////////////////////////////////
1225
1226-inline Decimal operator+( Decimal const &d1, Decimal const &d2 ) {
1227- return d1.value_ + d2.value_;
1228-}
1229-
1230-inline Decimal operator-( Decimal const &d1, Decimal const &d2 ) {
1231- return d1.value_ - d2.value_;
1232-}
1233-
1234-inline Decimal operator*( Decimal const &d1, Decimal const &d2 ) {
1235- return d1.value_ * d2.value_;
1236-}
1237-
1238-inline Decimal operator/( Decimal const &d1, Decimal const &d2 ) {
1239- return d1.value_ / d2.value_;
1240-}
1241-
1242-inline Decimal operator%( Decimal const &d1, Decimal const &d2 ) {
1243- return d1.value_ % d2.value_;
1244-}
1245-
1246-inline Decimal& Decimal::operator+=( Decimal const &d ) {
1247- value_ += d.value_;
1248- return *this;
1249-}
1250-
1251-inline Decimal& Decimal::operator-=( Decimal const &d ) {
1252- value_ -= d.value_;
1253- return *this;
1254-}
1255-
1256-inline Decimal& Decimal::operator*=( Decimal const &d ) {
1257- value_ *= d.value_;
1258- return *this;
1259-}
1260-
1261-inline Decimal& Decimal::operator/=( Decimal const &d ) {
1262- value_ /= d.value_;
1263- return *this;
1264-}
1265-
1266-inline Decimal& Decimal::operator%=( Decimal const &d ) {
1267- value_ %= d.value_;
1268- return *this;
1269-}
1270+#define ZORBA_DECIMAL_OP(OP) \
1271+ inline Decimal operator OP( Decimal const &d1, Decimal const &d2 ) { \
1272+ return d1.value_ OP d2.value_; \
1273+ }
1274+
1275+ZORBA_DECIMAL_OP(+)
1276+ZORBA_DECIMAL_OP(-)
1277+ZORBA_DECIMAL_OP(*)
1278+ZORBA_DECIMAL_OP(/)
1279+ZORBA_DECIMAL_OP(%)
1280+#undef ZORBA_DECIMAL_OP
1281+
1282+#define ZORBA_DECIMAL_OP(OP) \
1283+ inline Decimal& Decimal::operator OP( Decimal const &d ) { \
1284+ value_ OP d.value_; \
1285+ return *this; \
1286+ }
1287+
1288+ZORBA_DECIMAL_OP(+=)
1289+ZORBA_DECIMAL_OP(-=)
1290+ZORBA_DECIMAL_OP(*=)
1291+ZORBA_DECIMAL_OP(/=)
1292+ZORBA_DECIMAL_OP(%=)
1293+#undef ZORBA_DECIMAL_OP
1294
1295 inline Decimal Decimal::operator-() const {
1296 return -value_;
1297
1298=== modified file 'src/zorbatypes/floatimpl.cpp'
1299--- src/zorbatypes/floatimpl.cpp 2012-04-12 02:08:10 +0000
1300+++ src/zorbatypes/floatimpl.cpp 2012-04-16 15:38:09 +0000
1301@@ -169,22 +169,54 @@
1302 template FloatImpl<double>::FloatImpl( INTEGER_IMPL_ULL const& );
1303 #endif /* ZORBA_WITH_BIG_INTEGER */
1304
1305+////////// assignment operators ///////////////////////////////////////////////
1306+
1307+template<typename FloatType>
1308+FloatImpl<FloatType>& FloatImpl<FloatType>::operator=( Decimal const &d ) {
1309+ zstring const temp( d.toString() );
1310+ parse( temp.c_str() );
1311+ return *this;
1312+}
1313+
1314+template<typename FloatType>
1315+TEMPLATE_DECL(IntType)
1316+FloatImpl<FloatType>&
1317+FloatImpl<FloatType>::operator=( INTEGER_IMPL(IntType) const &i ) {
1318+ zstring const temp( i.toString() );
1319+ parse( temp.c_str() );
1320+ return *this;
1321+}
1322+
1323+#ifndef ZORBA_WITH_BIG_INTEGER
1324+template
1325+FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_LL const& );
1326+
1327+template
1328+FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_ULL const& );
1329+
1330+template
1331+FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_LL const& );
1332+
1333+template
1334+FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_ULL const& );
1335+#endif /* ZORBA_WITH_BIG_INTEGER */
1336+
1337 ////////// math functions /////////////////////////////////////////////////////
1338
1339 template<typename FloatType>
1340 FloatImpl<FloatType> FloatImpl<FloatType>::acos() const {
1341 if ( *this < neg_one() || *this > one() )
1342 return nan();
1343- if ( !isNegZero() )
1344- return std::acos( value_ );
1345- return -std::acos( value_ );
1346+ return FloatImpl<FloatType>(
1347+ isNegZero() ? -std::acos( value_ ): std::acos( value_ )
1348+ );
1349 }
1350
1351 template<typename FloatType>
1352 FloatImpl<FloatType> FloatImpl<FloatType>::asin() const {
1353 if ( *this < neg_one() || *this > one() )
1354 return nan();
1355- return std::asin( value_ );
1356+ return FloatImpl<FloatType>( std::asin( value_ ) );
1357 }
1358
1359 template<typename FloatType>
1360@@ -220,8 +252,13 @@
1361 FloatImpl<FloatType> FloatImpl<FloatType>::round( Integer const &precision ) const {
1362 FloatImpl result;
1363 if ( isFinite() && !isZero() ) {
1364- MAPM m = Decimal::round( value_, precision.itod() );
1365- if ( value_ < 0 && m == 0 )
1366+ MAPM m(
1367+ Decimal::round2(
1368+ Decimal::value_type( value_ ),
1369+ Decimal::value_type( precision.itod() )
1370+ )
1371+ );
1372+ if ( value_ < 0 && m.sign() == 0 )
1373 result = neg_zero();
1374 else {
1375 char buf[200];
1376@@ -234,12 +271,17 @@
1377 return result;
1378 }
1379
1380-template<typename FloatType>
1381-FloatImpl<FloatType> FloatImpl<FloatType>::roundHalfToEven( Integer const &precision) const {
1382+template<typename FloatType> FloatImpl<FloatType>
1383+FloatImpl<FloatType>::roundHalfToEven( Integer const &precision) const {
1384 FloatImpl result;
1385 if ( isFinite() && !isZero() ) {
1386- MAPM m = Decimal::roundHalfToEven( value_, precision.itod() );
1387- if ( value_ < 0 && m == 0 )
1388+ MAPM m(
1389+ Decimal::roundHalfToEven2(
1390+ Decimal::value_type( value_ ),
1391+ Decimal::value_type( precision.itod() )
1392+ )
1393+ );
1394+ if ( value_ < 0 && m.sign() == 0 )
1395 result = neg_zero();
1396 else {
1397 char buf[200];
1398@@ -353,8 +395,8 @@
1399 #if 1
1400 // This is the "spec" implementation, i.e., it is an exact application of
1401 // the spec in http://www.w3.org/TR/xpath-functions/#casting
1402- MAPM decimal_mapm = value_;
1403- decimal_mapm = decimal_mapm.round(precision_);
1404+ MAPM decimal_mapm( value_ );
1405+ decimal_mapm = decimal_mapm.round( precision_ );
1406 return Decimal::toString(decimal_mapm, max_precision());
1407 #else
1408 std::stringstream stream;
1409
1410=== modified file 'src/zorbatypes/floatimpl.h'
1411--- src/zorbatypes/floatimpl.h 2012-03-30 19:03:09 +0000
1412+++ src/zorbatypes/floatimpl.h 2012-04-16 15:38:09 +0000
1413@@ -30,11 +30,11 @@
1414 #include "zorbatypes_decl.h"
1415
1416 #ifdef ZORBA_WITH_BIG_INTEGER
1417-# define TEMPLATE_DECL(T) /* nothing */
1418-# define INTEGER_IMPL(T) IntegerImpl
1419+# define TEMPLATE_DECL(I) /* nothing */
1420+# define INTEGER_IMPL(I) IntegerImpl
1421 #else
1422-# define TEMPLATE_DECL(T) template<typename T>
1423-# define INTEGER_IMPL(T) IntegerImpl<T>
1424+# define TEMPLATE_DECL(I) template<typename I>
1425+# define INTEGER_IMPL(I) IntegerImpl<I>
1426 #endif /* ZORBA_WITH_BIG_INTEGER */
1427
1428 namespace zorba {
1429@@ -56,23 +56,23 @@
1430
1431 ////////// constructors /////////////////////////////////////////////////////
1432
1433- FloatImpl( char );
1434- FloatImpl( signed char c );
1435- FloatImpl( short n );
1436- FloatImpl( int n = 0 );
1437- FloatImpl( long n );
1438- FloatImpl( long long n );
1439- FloatImpl( unsigned char c );
1440- FloatImpl( unsigned short n );
1441- FloatImpl( unsigned int n );
1442- FloatImpl( unsigned long n );
1443- FloatImpl( unsigned long long n );
1444- FloatImpl( float n );
1445- FloatImpl( double n );
1446- FloatImpl( Decimal const &d );
1447+ explicit FloatImpl( char );
1448+ explicit FloatImpl( signed char c );
1449+ explicit FloatImpl( short n );
1450+ explicit FloatImpl( int n = 0 );
1451+ explicit FloatImpl( long n );
1452+ explicit FloatImpl( long long n );
1453+ explicit FloatImpl( unsigned char c );
1454+ explicit FloatImpl( unsigned short n );
1455+ explicit FloatImpl( unsigned int n );
1456+ explicit FloatImpl( unsigned long n );
1457+ explicit FloatImpl( unsigned long long n );
1458+ explicit FloatImpl( float n );
1459+ explicit FloatImpl( double n );
1460+ explicit FloatImpl( Decimal const &d );
1461
1462- TEMPLATE_DECL(T)
1463- FloatImpl( INTEGER_IMPL(T) const &i );
1464+ TEMPLATE_DECL(IntType)
1465+ explicit FloatImpl( INTEGER_IMPL(IntType) const &i );
1466
1467 /**
1468 * Constructs a %FloatImpl from a C string.
1469@@ -84,62 +84,74 @@
1470 * @throw std::range_error if \a s contains a number that either underflows
1471 * or overflows the smallest or largest representable floating point number.
1472 */
1473- FloatImpl( char const *s );
1474+ explicit FloatImpl( char const *s );
1475
1476+ /**
1477+ * Constructs from another %FloatImpl even if its \c FloatType is different.
1478+ * (This subsumes the conventional copy constructor.)
1479+ *
1480+ * @tparam FloatType2 the floating-point type of \a f.
1481+ * @param f The %FloatImpl to copy from.
1482+ */
1483 template<typename FloatType2>
1484 FloatImpl( FloatImpl<FloatType2> const &f );
1485
1486 ////////// assignment operators /////////////////////////////////////////////
1487
1488+ /**
1489+ * Assign from a %FloatImpl even if its \c FloatType is different.
1490+ * (This subsumes the conventional assignment operator.)
1491+ *
1492+ * @tparam FloatType2 the floating-point type of \a f.
1493+ * @param f The %FloatImpl to assign from.
1494+ * @return Returns \c *this.
1495+ */
1496+ template<typename FloatType2>
1497+ FloatImpl& operator=( FloatImpl<FloatType2> const &f );
1498+
1499+ /**
1500+ * For every built-in arithmetic type A, assign to this %FloatImpl.
1501+ *
1502+ * @tparam A The built-in arithmetic type.
1503+ * @param n The arithmetic value to assign.
1504+ * @return Returns \c *this.
1505+ */
1506 template<typename A>
1507 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
1508 FloatImpl&>::type
1509 operator=( A n );
1510
1511- template<typename FloatType2>
1512- FloatImpl& operator=( FloatImpl<FloatType2> const &f );
1513+ FloatImpl& operator=( char const *s );
1514+ FloatImpl& operator=( Decimal const &d );
1515+
1516+ TEMPLATE_DECL(I)
1517+ FloatImpl& operator=( INTEGER_IMPL(I) const &i );
1518
1519 ////////// arithmetic operators /////////////////////////////////////////////
1520
1521- template<typename A>
1522- typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
1523- FloatImpl&>::type
1524- operator+=( A n );
1525-
1526- template<typename A>
1527- typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
1528- FloatImpl&>::type
1529- operator-=( A n );
1530-
1531- template<typename A>
1532- typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
1533- FloatImpl&>::type
1534- operator*=( A n );
1535-
1536- template<typename A>
1537- typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
1538- FloatImpl&>::type
1539- operator/=( A n );
1540-
1541- template<typename A>
1542- typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
1543- FloatImpl&>::type
1544- operator%=( A n );
1545-
1546- template<typename FloatType2>
1547- FloatImpl& operator+=( FloatImpl<FloatType2> const &f );
1548-
1549- template<typename FloatType2>
1550- FloatImpl& operator-=( FloatImpl<FloatType2> const &f );
1551-
1552- template<typename FloatType2>
1553- FloatImpl& operator*=( FloatImpl<FloatType2> const &f );
1554-
1555- template<typename FloatType2>
1556- FloatImpl& operator/=( FloatImpl<FloatType2> const &f );
1557-
1558- template<typename FloatType2>
1559- FloatImpl& operator%=( FloatImpl<FloatType2> const &f );
1560+#define ZORBA_FLOAT_OP(OP) \
1561+ template<typename A> \
1562+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
1563+ FloatImpl&>::type \
1564+ operator OP( A n )
1565+
1566+ ZORBA_FLOAT_OP(+=);
1567+ ZORBA_FLOAT_OP(-=);
1568+ ZORBA_FLOAT_OP(*=);
1569+ ZORBA_FLOAT_OP(/=);
1570+ ZORBA_FLOAT_OP(%=);
1571+#undef ZORBA_FLOAT_OP
1572+
1573+#define ZORBA_FLOAT_OP(OP) \
1574+ template<typename FloatType2> \
1575+ FloatImpl& operator OP( FloatImpl<FloatType2> const &f )
1576+
1577+ ZORBA_FLOAT_OP(+=);
1578+ ZORBA_FLOAT_OP(-=);
1579+ ZORBA_FLOAT_OP(*=);
1580+ ZORBA_FLOAT_OP(/=);
1581+ ZORBA_FLOAT_OP(%=);
1582+#undef ZORBA_FLOAT_OP
1583
1584 FloatImpl operator-() const;
1585
1586@@ -231,7 +243,7 @@
1587 void parse( char const* );
1588 bool parse_etc( char const* );
1589
1590- TEMPLATE_DECL(T) friend class IntegerImpl;
1591+ TEMPLATE_DECL(I) friend class IntegerImpl;
1592 friend class Decimal;
1593
1594 friend class FloatImpl<float>;
1595@@ -255,528 +267,524 @@
1596
1597 ////////// constructors ///////////////////////////////////////////////////////
1598
1599-template<typename FloatType> inline
1600-FloatImpl<FloatType>::FloatImpl( char c ) :
1601- value_( static_cast<value_type>( c ) ), precision_( max_precision() )
1602-{
1603-}
1604-
1605-template<typename FloatType> inline
1606-FloatImpl<FloatType>::FloatImpl( signed char c ) :
1607- value_( static_cast<value_type>( c ) ), precision_( max_precision() )
1608-{
1609-}
1610-
1611-template<typename FloatType> inline
1612-FloatImpl<FloatType>::FloatImpl( short n ) :
1613- value_( static_cast<value_type>( n ) ), precision_( max_precision() )
1614-{
1615-}
1616-
1617-template<typename FloatType> inline
1618-FloatImpl<FloatType>::FloatImpl( int n ) :
1619- value_( static_cast<value_type>( n ) ), precision_( max_precision() )
1620-{
1621-}
1622-
1623-template<typename FloatType> inline
1624-FloatImpl<FloatType>::FloatImpl( long n ) :
1625- value_( static_cast<value_type>( n ) ), precision_( max_precision() )
1626-{
1627-}
1628-
1629-template<typename FloatType> inline
1630-FloatImpl<FloatType>::FloatImpl( long long n ) :
1631- value_( static_cast<value_type>( n ) ), precision_( max_precision() )
1632-{
1633-}
1634-
1635-template<typename FloatType> inline
1636-FloatImpl<FloatType>::FloatImpl( unsigned char c ) :
1637- value_( static_cast<value_type>( c ) ), precision_( max_precision() )
1638-{
1639-}
1640-
1641-template<typename FloatType> inline
1642-FloatImpl<FloatType>::FloatImpl( unsigned short n ) :
1643- value_( static_cast<value_type>( n ) ), precision_( max_precision() )
1644-{
1645-}
1646-
1647-template<typename FloatType> inline
1648-FloatImpl<FloatType>::FloatImpl( unsigned int n ) :
1649- value_( static_cast<value_type>( n ) ), precision_( max_precision() )
1650-{
1651-}
1652-
1653-template<typename FloatType> inline
1654-FloatImpl<FloatType>::FloatImpl( unsigned long n ) :
1655- value_( static_cast<value_type>( n ) ), precision_( max_precision() )
1656-{
1657-}
1658-
1659-template<typename FloatType> inline
1660-FloatImpl<FloatType>::FloatImpl( unsigned long long n ) :
1661- value_( static_cast<value_type>( n ) ), precision_( max_precision() )
1662-{
1663-}
1664-
1665-template<typename FloatType> inline
1666-FloatImpl<FloatType>::FloatImpl( float n ) :
1667- value_( static_cast<value_type>( n ) ), precision_( max_precision() )
1668-{
1669-}
1670-
1671-template<typename FloatType> inline
1672-FloatImpl<FloatType>::FloatImpl( double n ) :
1673- value_( static_cast<value_type>( n ) ), precision_( max_precision() )
1674-{
1675-}
1676-
1677-template<typename FloatType> inline
1678-FloatImpl<FloatType>::FloatImpl( char const *s ) {
1679+template<typename F>
1680+inline FloatImpl<F>::FloatImpl( char c ) :
1681+ value_( static_cast<F>( c ) ), precision_( max_precision() )
1682+{
1683+}
1684+
1685+template<typename F>
1686+inline FloatImpl<F>::FloatImpl( signed char c ) :
1687+ value_( static_cast<F>( c ) ), precision_( max_precision() )
1688+{
1689+}
1690+
1691+template<typename F>
1692+inline FloatImpl<F>::FloatImpl( short n ) :
1693+ value_( static_cast<F>( n ) ), precision_( max_precision() )
1694+{
1695+}
1696+
1697+template<typename F>
1698+inline FloatImpl<F>::FloatImpl( int n ) :
1699+ value_( static_cast<F>( n ) ), precision_( max_precision() )
1700+{
1701+}
1702+
1703+template<typename F>
1704+inline FloatImpl<F>::FloatImpl( long n ) :
1705+ value_( static_cast<F>( n ) ), precision_( max_precision() )
1706+{
1707+}
1708+
1709+template<typename F>
1710+inline FloatImpl<F>::FloatImpl( long long n ) :
1711+ value_( static_cast<F>( n ) ), precision_( max_precision() )
1712+{
1713+}
1714+
1715+template<typename F>
1716+inline FloatImpl<F>::FloatImpl( unsigned char c ) :
1717+ value_( static_cast<F>( c ) ), precision_( max_precision() )
1718+{
1719+}
1720+
1721+template<typename F>
1722+inline FloatImpl<F>::FloatImpl( unsigned short n ) :
1723+ value_( static_cast<F>( n ) ), precision_( max_precision() )
1724+{
1725+}
1726+
1727+template<typename F>
1728+inline FloatImpl<F>::FloatImpl( unsigned int n ) :
1729+ value_( static_cast<F>( n ) ), precision_( max_precision() )
1730+{
1731+}
1732+
1733+template<typename F>
1734+inline FloatImpl<F>::FloatImpl( unsigned long n ) :
1735+ value_( static_cast<F>( n ) ), precision_( max_precision() )
1736+{
1737+}
1738+
1739+template<typename F>
1740+inline FloatImpl<F>::FloatImpl( unsigned long long n ) :
1741+ value_( static_cast<F>( n ) ), precision_( max_precision() )
1742+{
1743+}
1744+
1745+template<typename F>
1746+inline FloatImpl<F>::FloatImpl( float n ) :
1747+ value_( static_cast<F>( n ) ), precision_( max_precision() )
1748+{
1749+}
1750+
1751+template<typename F>
1752+inline FloatImpl<F>::FloatImpl( double n ) :
1753+ value_( static_cast<F>( n ) ), precision_( max_precision() )
1754+{
1755+}
1756+
1757+template<typename F>
1758+inline FloatImpl<F>::FloatImpl( char const *s ) {
1759 parse( s );
1760 }
1761
1762-template<typename FloatType>
1763-template<typename FloatType2>
1764-inline FloatImpl<FloatType>::FloatImpl( FloatImpl<FloatType2> const &f ) :
1765- value_( static_cast<value_type>( f.value_ ) ), precision_( max_precision() )
1766+template<typename F> template<typename G>
1767+inline FloatImpl<F>::FloatImpl( FloatImpl<G> const &f ) :
1768+ value_( static_cast<F>( f.value_ ) ), precision_( max_precision() )
1769 {
1770 }
1771
1772-template<typename FloatType>
1773-inline FloatImpl<FloatType>::FloatImpl( value_type v, precision_type p ) :
1774+template<typename F>
1775+inline FloatImpl<F>::FloatImpl( value_type v, precision_type p ) :
1776 value_( v ), precision_( p )
1777 {
1778 }
1779
1780 ////////// assignment operators ///////////////////////////////////////////////
1781
1782-template<typename T>
1783-template<typename A> inline
1784+template<typename F> template<typename G>
1785+inline FloatImpl<F>& FloatImpl<F>::operator=( FloatImpl<G> const &f ) {
1786+ value_ = static_cast<F>( f.value_ );
1787+ precision_ = max_precision();
1788+ return *this;
1789+}
1790+
1791+template<typename F> template<typename A> inline
1792 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
1793- FloatImpl<T>&>::type
1794-FloatImpl<T>::operator=( A n ) {
1795- value_ = static_cast<value_type>( n );
1796+ FloatImpl<F>&>::type
1797+FloatImpl<F>::operator=( A n ) {
1798+ value_ = static_cast<F>( n );
1799 precision_ = max_precision();
1800 return *this;
1801 }
1802
1803-template<typename T>
1804-template<typename U>
1805-inline FloatImpl<T>& FloatImpl<T>::operator=( FloatImpl<U> const &f ) {
1806- value_ = static_cast<value_type>( f.value_ );
1807- precision_ = max_precision();
1808+template<typename F>
1809+inline FloatImpl<F>& FloatImpl<F>::operator=( char const *s ) {
1810+ parse( s );
1811 return *this;
1812 }
1813
1814 ////////// arithmetic operators ///////////////////////////////////////////////
1815
1816-#define ZORBA_DEF_FLOATIMPL_OP(OP) \
1817- template<typename T,typename A> inline \
1818+#define ZORBA_FLOAT_OP(OP) \
1819+ template<typename F,typename A> inline \
1820 typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
1821- FloatImpl<T> >::type \
1822- operator OP( FloatImpl<T> const &f, A n ) { \
1823- return FloatImpl<T>( f.getNumber() OP static_cast<T>( n ) ); \
1824+ FloatImpl<F> >::type \
1825+ operator OP( FloatImpl<F> const &f, A n ) { \
1826+ return FloatImpl<F>( f.getNumber() OP static_cast<F>( n ) ); \
1827 } \
1828- template<typename T,typename A> inline \
1829- typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
1830- FloatImpl<T> >::type \
1831- operator OP( A n, FloatImpl<T> const &f ) { \
1832- return FloatImpl<T>( static_cast<T>( n ) OP f.getNumber() ); \
1833- }
1834-
1835-ZORBA_DEF_FLOATIMPL_OP( + )
1836-ZORBA_DEF_FLOATIMPL_OP( - )
1837-ZORBA_DEF_FLOATIMPL_OP( * )
1838-ZORBA_DEF_FLOATIMPL_OP( / )
1839-
1840-#undef ZORBA_DEF_FLOATIMPL_OP
1841-
1842-template<typename T,typename A> inline
1843-typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
1844- FloatImpl<T> >::type
1845-operator%( FloatImpl<T> const &f, A n ) {
1846- return FloatImpl<T>( std::fmod( f.getNumber(), static_cast<T>( n ) ) );
1847-}
1848-
1849-template<typename T,typename A> inline
1850-typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
1851- FloatImpl<T> >::type
1852-operator%( A n, FloatImpl<T> const &f ) {
1853- return FloatImpl<T>( std::fmod( static_cast<T>( n ), f.getNumber() ) );
1854-}
1855-
1856-#define ZORBA_DEF_FLOATIMPL_OP(OP) \
1857- template<typename T> inline \
1858- FloatImpl<T> operator OP( FloatImpl<T> const &f, FloatImpl<T> const &g ) { \
1859- return FloatImpl<T>( f.getNumber() OP g.getNumber() ); \
1860- }
1861-
1862-ZORBA_DEF_FLOATIMPL_OP( + )
1863-ZORBA_DEF_FLOATIMPL_OP( - )
1864-ZORBA_DEF_FLOATIMPL_OP( * )
1865-ZORBA_DEF_FLOATIMPL_OP( / )
1866-
1867-#undef ZORBA_DEF_FLOATIMPL_OP
1868-
1869-template<typename T> inline
1870-FloatImpl<T> operator%( FloatImpl<T> const &f, FloatImpl<T> const &g ) {
1871- return FloatImpl<T>( std::fmod( f.getNumber(), g.getNumber() ) );
1872-}
1873-
1874-#define ZORBA_DEF_FLOATIMPL_OP(OP) \
1875- template<typename T> \
1876- template<typename A> inline \
1877- typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
1878- FloatImpl<T>&>::type \
1879- FloatImpl<T>::operator OP( A n ) { \
1880- value_ OP static_cast<value_type>( n ); \
1881+ \
1882+ template<typename F,typename A> inline \
1883+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
1884+ FloatImpl<F> >::type \
1885+ operator OP( A n, FloatImpl<F> const &f ) { \
1886+ return FloatImpl<F>( static_cast<F>( n ) OP f.getNumber() ); \
1887+ }
1888+
1889+ZORBA_FLOAT_OP(+)
1890+ZORBA_FLOAT_OP(-)
1891+ZORBA_FLOAT_OP(*)
1892+ZORBA_FLOAT_OP(/)
1893+#undef ZORBA_FLOAT_OP
1894+
1895+template<typename F,typename A> inline
1896+typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
1897+ FloatImpl<F> >::type
1898+operator%( FloatImpl<F> const &f, A n ) {
1899+ return FloatImpl<F>( std::fmod( f.getNumber(), static_cast<F>( n ) ) );
1900+}
1901+
1902+template<typename F,typename A> inline
1903+typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
1904+ FloatImpl<F> >::type
1905+operator%( A n, FloatImpl<F> const &f ) {
1906+ return FloatImpl<F>( std::fmod( static_cast<F>( n ), f.getNumber() ) );
1907+}
1908+
1909+#define ZORBA_FLOAT_OP(OP) \
1910+ template<typename F> inline \
1911+ FloatImpl<F> operator OP( FloatImpl<F> const &f, FloatImpl<F> const &g ) { \
1912+ return FloatImpl<F>( f.getNumber() OP g.getNumber() ); \
1913+ }
1914+
1915+ZORBA_FLOAT_OP(+)
1916+ZORBA_FLOAT_OP(-)
1917+ZORBA_FLOAT_OP(*)
1918+ZORBA_FLOAT_OP(/)
1919+#undef ZORBA_FLOAT_OP
1920+
1921+template<typename F>
1922+inline FloatImpl<F> operator%( FloatImpl<F> const &f, FloatImpl<F> const &g ) {
1923+ return FloatImpl<F>( std::fmod( f.getNumber(), g.getNumber() ) );
1924+}
1925+
1926+#define ZORBA_FLOAT_OP(OP) \
1927+ template<typename F> template<typename A> inline \
1928+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
1929+ FloatImpl<F>&>::type \
1930+ FloatImpl<F>::operator OP( A n ) { \
1931+ value_ OP static_cast<F>( n ); \
1932 return *this; \
1933 }
1934
1935-ZORBA_DEF_FLOATIMPL_OP( += )
1936-ZORBA_DEF_FLOATIMPL_OP( -= )
1937-ZORBA_DEF_FLOATIMPL_OP( *= )
1938-ZORBA_DEF_FLOATIMPL_OP( /= )
1939-ZORBA_DEF_FLOATIMPL_OP( %= )
1940-
1941-#undef ZORBA_DEF_FLOATIMPL_OP
1942-
1943-#define ZORBA_DEF_FLOATIMPL_OP(OP) \
1944- template<typename T> \
1945- template<typename U> \
1946- inline FloatImpl<T>& FloatImpl<T>::operator OP( FloatImpl<U> const &f ) { \
1947- value_ OP static_cast<value_type>( f.value_ ); \
1948+ZORBA_FLOAT_OP(+=)
1949+ZORBA_FLOAT_OP(-=)
1950+ZORBA_FLOAT_OP(*=)
1951+ZORBA_FLOAT_OP(/=)
1952+ZORBA_FLOAT_OP(%=)
1953+#undef ZORBA_FLOAT_OP
1954+
1955+#define ZORBA_FLOAT_OP(OP) \
1956+ template<typename F> template<typename G> \
1957+ inline FloatImpl<F>& FloatImpl<F>::operator OP( FloatImpl<G> const &f ) { \
1958+ value_ OP static_cast<F>( f.value_ ); \
1959 return *this; \
1960 }
1961
1962-ZORBA_DEF_FLOATIMPL_OP( += )
1963-ZORBA_DEF_FLOATIMPL_OP( -= )
1964-ZORBA_DEF_FLOATIMPL_OP( *= )
1965-ZORBA_DEF_FLOATIMPL_OP( /= )
1966-ZORBA_DEF_FLOATIMPL_OP( %= )
1967-
1968-#undef ZORBA_DEF_FLOATIMPL_OP
1969-
1970-template<typename FloatType>
1971-inline FloatImpl<FloatType> FloatImpl<FloatType>::operator-() const {
1972- return FloatImpl<FloatType>( -value_, precision_ );
1973-}
1974-
1975-inline Double operator+( Double const &d, Float const &f ) {
1976- return d.getNumber() + f.getNumber();
1977-}
1978-
1979-inline Double operator+( Float const &f, Double const &d ) {
1980- return f.getNumber() + d.getNumber();
1981-}
1982-
1983-inline Double operator-( Double const &d, Float const &f ) {
1984- return d.getNumber() - f.getNumber();
1985-}
1986-
1987-inline Double operator-( Float const &f, Double const &d ) {
1988- return f.getNumber() - d.getNumber();
1989-}
1990-
1991-inline Double operator*( Double const &d, Float const &f ) {
1992- return d.getNumber() * f.getNumber();
1993-}
1994-
1995-inline Double operator*( Float const &f, Double const &d ) {
1996- return f.getNumber() * d.getNumber();
1997-}
1998-
1999-inline Double operator/( Double const &d, Float const &f ) {
2000- return d.getNumber() / f.getNumber();
2001-}
2002-
2003-inline Double operator/( Float const &f, Double const &d ) {
2004- return f.getNumber() / d.getNumber();
2005-}
2006+ZORBA_FLOAT_OP(+=)
2007+ZORBA_FLOAT_OP(-=)
2008+ZORBA_FLOAT_OP(*=)
2009+ZORBA_FLOAT_OP(/=)
2010+#undef ZORBA_FLOAT_OP
2011+
2012+template<typename F> template<typename G>
2013+inline FloatImpl<F>& FloatImpl<F>::operator%=( FloatImpl<G> const &f ) {
2014+ value_ = std::fmod( value_, static_cast<F>( f.value_ ) );
2015+ return *this;
2016+}
2017+
2018+template<typename F>
2019+inline FloatImpl<F> FloatImpl<F>::operator-() const {
2020+ return FloatImpl<F>( -value_, precision_ );
2021+}
2022+
2023+#define ZORBA_FLOAT_OP(OP) \
2024+ inline Double operator OP( Double const &d, Float const &f ) { \
2025+ return Double( d.getNumber() OP f.getNumber() ); \
2026+ } \
2027+ inline Double operator OP( Float const &f, Double const &d ) { \
2028+ return Double( f.getNumber() OP d.getNumber() ); \
2029+ }
2030+
2031+ZORBA_FLOAT_OP(+)
2032+ZORBA_FLOAT_OP(-)
2033+ZORBA_FLOAT_OP(*)
2034+ZORBA_FLOAT_OP(/)
2035+#undef ZORBA_FLOAT_OP
2036
2037 inline Double operator%( Double const &d, Float const &f ) {
2038- return std::fmod( d.getNumber(), static_cast<double>( f.getNumber() ) );
2039+ return Double(
2040+ std::fmod( d.getNumber(), static_cast<double>( f.getNumber() ) )
2041+ );
2042 }
2043
2044 inline Double operator%( Float const &f, Double const &d ) {
2045- return std::fmod( static_cast<double>( f.getNumber() ), d.getNumber() );
2046+ return Double(
2047+ std::fmod( static_cast<double>( f.getNumber() ), d.getNumber() )
2048+ );
2049 }
2050
2051 ////////// relational operators ///////////////////////////////////////////////
2052
2053-template<typename T,typename U>
2054-inline bool operator==( FloatImpl<T> const &f, FloatImpl<U> const &g ) {
2055+template<typename F,typename G>
2056+inline bool operator==( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
2057 return f.getNumber() == g.getNumber();
2058 }
2059
2060-template<typename T,typename U>
2061-inline bool operator!=( FloatImpl<T> const &f, FloatImpl<U> const &g ) {
2062+template<typename F,typename G>
2063+inline bool operator!=( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
2064 return f.getNumber() != g.getNumber();
2065 }
2066
2067-template<typename T,typename U>
2068-inline bool operator<( FloatImpl<T> const &f, FloatImpl<U> const &g ) {
2069+template<typename F,typename G>
2070+inline bool operator<( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
2071 return f.getNumber() < g.getNumber();
2072 }
2073
2074-template<typename T,typename U>
2075-inline bool operator<=( FloatImpl<T> const &f, FloatImpl<U> const &g ) {
2076+template<typename F,typename G>
2077+inline bool operator<=( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
2078 return !f.isNaN() && !g.isNaN() && f.getNumber() <= g.getNumber();
2079 }
2080
2081-template<typename T,typename U>
2082-inline bool operator>( FloatImpl<T> const &f, FloatImpl<U> const &g ) {
2083+template<typename F,typename G>
2084+inline bool operator>( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
2085 return f.getNumber() > g.getNumber();
2086 }
2087
2088-template<typename T,typename U>
2089-inline bool operator>=( FloatImpl<T> const &f, FloatImpl<U> const &g ) {
2090+template<typename F,typename G>
2091+inline bool operator>=( FloatImpl<F> const &f, FloatImpl<G> const &g ) {
2092 return !f.isNaN() && !g.isNaN() && f.getNumber() >= g.getNumber();
2093 }
2094
2095-template<typename T>
2096-inline bool operator==( FloatImpl<T> const &f, double d ) {
2097+template<typename F>
2098+inline bool operator==( FloatImpl<F> const &f, double d ) {
2099 return f.getNumber() == d;
2100 }
2101
2102-template<typename T>
2103-inline bool operator==( double d, FloatImpl<T> const &f ) {
2104+template<typename F>
2105+inline bool operator==( double d, FloatImpl<F> const &f ) {
2106 return d = f.getNumber();
2107 }
2108
2109-template<typename T>
2110-inline bool operator!=( FloatImpl<T> const &f, double d ) {
2111- return f.getNumber() != d;
2112-}
2113-
2114-template<typename T>
2115-inline bool operator!=( double d, FloatImpl<T> const &f ) {
2116- return f.getNumber() != d;
2117-}
2118-
2119-template<typename T>
2120-inline bool operator<( FloatImpl<T> const &f, double d ) {
2121+template<typename F>
2122+inline bool operator!=( FloatImpl<F> const &f, double d ) {
2123+ return f.getNumber() != d;
2124+}
2125+
2126+template<typename F>
2127+inline bool operator!=( double d, FloatImpl<F> const &f ) {
2128+ return f.getNumber() != d;
2129+}
2130+
2131+template<typename F>
2132+inline bool operator<( FloatImpl<F> const &f, double d ) {
2133 return f.getNumber() < d;
2134 }
2135
2136-template<typename T>
2137-inline bool operator<( double d, FloatImpl<T> const &f ) {
2138+template<typename F>
2139+inline bool operator<( double d, FloatImpl<F> const &f ) {
2140 return d < f.getNumber();
2141 }
2142
2143-template<typename T>
2144-inline bool operator<=( FloatImpl<T> const &f, double d ) {
2145+template<typename F>
2146+inline bool operator<=( FloatImpl<F> const &f, double d ) {
2147 return !f.isNaN() && d == d && f.getNumber() <= d;
2148 }
2149
2150-template<typename T>
2151-inline bool operator<=( double d, FloatImpl<T> const &f ) {
2152+template<typename F>
2153+inline bool operator<=( double d, FloatImpl<F> const &f ) {
2154 return d == d && !f.isNaN() && d <= f.getNumber();
2155 }
2156
2157-template<typename T>
2158-inline bool operator>( FloatImpl<T> const &f, double d ) {
2159+template<typename F>
2160+inline bool operator>( FloatImpl<F> const &f, double d ) {
2161 return f.getNumber() > d;
2162 }
2163
2164-template<typename T>
2165-inline bool operator>( double d, FloatImpl<T> const &f ) {
2166+template<typename F>
2167+inline bool operator>( double d, FloatImpl<F> const &f ) {
2168 return d > f.getNumber();
2169 }
2170
2171-template<typename T>
2172-inline bool operator>=( FloatImpl<T> const &f, double d ) {
2173+template<typename F>
2174+inline bool operator>=( FloatImpl<F> const &f, double d ) {
2175 return !f.isNaN() && d == d && f.getNumber() >= d;
2176 }
2177
2178-template<typename T>
2179-inline bool operator>=( double d, FloatImpl<T> const &f ) {
2180+template<typename F>
2181+inline bool operator>=( double d, FloatImpl<F> const &f ) {
2182 return d == d && !f.isNaN() && d >= f.getNumber();
2183 }
2184
2185 ////////// math functions /////////////////////////////////////////////////////
2186
2187-template<typename FloatType> inline FloatImpl<FloatType>
2188-FloatImpl<FloatType>::acosh() const {
2189- // formula from www.mathworks.com
2190- return std::log( value_ + std::sqrt( value_ * value_ - 1 ) );
2191-}
2192-
2193-template<typename FloatType> inline FloatImpl<FloatType>
2194-FloatImpl<FloatType>::asinh() const {
2195- // formula from www.mathworks.com
2196- return std::log( value_ + std::sqrt( value_ * value_ + 1 ) );
2197-}
2198-
2199-template<typename FloatType> inline FloatImpl<FloatType>
2200-FloatImpl<FloatType>::atan() const {
2201- return std::atan( value_ );
2202-}
2203-
2204-template<typename FloatType> inline FloatImpl<FloatType>
2205-FloatImpl<FloatType>::atanh() const {
2206- // formula from www.mathworks.com
2207- return 0.5 * std::log( (1 + value_) / (1 - value_) );
2208-}
2209-
2210-template<typename FloatType> inline FloatImpl<FloatType>
2211-FloatImpl<FloatType>::atan2( double x ) const {
2212- return std::atan2( value_, static_cast<value_type>( x ) );
2213-}
2214-
2215-template<typename FloatType> inline FloatImpl<FloatType>
2216-FloatImpl<FloatType>::atan2( FloatImpl<FloatType> const &x ) const {
2217- return atan2( x.value_ );
2218-}
2219-
2220-template<typename FloatType> inline FloatImpl<FloatType>
2221-FloatImpl<FloatType>::ceil() const {
2222- return std::ceil( value_ );
2223-}
2224-
2225-template<typename FloatType> inline FloatImpl<FloatType>
2226-FloatImpl<FloatType>::cos() const {
2227- return std::cos( value_ );
2228-}
2229-
2230-template<typename FloatType> inline FloatImpl<FloatType>
2231-FloatImpl<FloatType>::cosh() const {
2232- return std::cosh( value_ );
2233-}
2234-
2235-template<typename FloatType> inline FloatImpl<FloatType>
2236-FloatImpl<FloatType>::exp() const {
2237- return std::exp( value_ );
2238-}
2239-
2240-template<typename FloatType> inline FloatImpl<FloatType>
2241-FloatImpl<FloatType>::exp10() const {
2242- return std::pow( 10, value_ );
2243-}
2244-
2245-template<typename FloatType> inline FloatImpl<FloatType>
2246-FloatImpl<FloatType>::floor() const {
2247- return std::floor( value_ );
2248-}
2249-
2250-template<typename FloatType> inline FloatImpl<FloatType>
2251-FloatImpl<FloatType>::fmod( double d ) const {
2252- return std::fmod( value_, static_cast<value_type>( d ) );
2253-}
2254-
2255-template<typename FloatType> inline FloatImpl<FloatType>
2256-FloatImpl<FloatType>::fmod( FloatImpl<FloatType> const &f ) const {
2257- return fmod( f.value_ );
2258-}
2259-
2260-template<typename FloatType>
2261-FloatImpl<FloatType> FloatImpl<FloatType>::log() const {
2262- return value_ < 0 ? nan() : FloatImpl<FloatType>( std::log( value_ ) );
2263-}
2264-
2265-template<typename FloatType>
2266-FloatImpl<FloatType> FloatImpl<FloatType>::log10() const {
2267- return value_ < 0 ? nan() : FloatImpl<FloatType>( std::log10( value_ ) );
2268-}
2269-
2270-template<typename FloatType> inline FloatImpl<FloatType>
2271-FloatImpl<FloatType>::pow( int p ) const {
2272- return std::pow( value_, p );
2273-}
2274-
2275-template<typename FloatType> inline FloatImpl<FloatType>
2276-FloatImpl<FloatType>::pow( FloatImpl<FloatType> const &p ) const {
2277- return p.isNaN() ? value_ : std::pow( value_, p.value_ );
2278-}
2279-
2280-template<typename FloatType> inline FloatImpl<FloatType>
2281-FloatImpl<FloatType>::sin() const {
2282- return std::sin( value_ );
2283-}
2284-
2285-template<typename FloatType> inline FloatImpl<FloatType>
2286-FloatImpl<FloatType>::sinh() const {
2287- return std::sinh( value_ );
2288-}
2289-
2290-template<typename FloatType> inline FloatImpl<FloatType>
2291-FloatImpl<FloatType>::sqrt() const {
2292+template<typename F>
2293+inline FloatImpl<F> FloatImpl<F>::acosh() const {
2294+ // formula from www.mathworks.com
2295+ return FloatImpl<F>(
2296+ std::log( value_ + std::sqrt( value_ * value_ - 1 ) )
2297+ );
2298+}
2299+
2300+template<typename F>
2301+inline FloatImpl<F> FloatImpl<F>::asinh() const {
2302+ // formula from www.mathworks.com
2303+ return FloatImpl<F>(
2304+ std::log( value_ + std::sqrt( value_ * value_ + 1 ) )
2305+ );
2306+}
2307+
2308+template<typename F>
2309+inline FloatImpl<F> FloatImpl<F>::atan() const {
2310+ return FloatImpl<F>( std::atan( value_ ) );
2311+}
2312+
2313+template<typename F>
2314+inline FloatImpl<F> FloatImpl<F>::atanh() const {
2315+ // formula from www.mathworks.com
2316+ return FloatImpl<F>( 0.5 * std::log( (1 + value_) / (1 - value_) ) );
2317+}
2318+
2319+template<typename F>
2320+inline FloatImpl<F> FloatImpl<F>::atan2( double x ) const {
2321+ return FloatImpl<F>( std::atan2( value_, static_cast<F>( x ) ) );
2322+}
2323+
2324+template<typename F>
2325+inline FloatImpl<F> FloatImpl<F>::atan2( FloatImpl<F> const &x ) const {
2326+ return FloatImpl<F>( atan2( x.value_ ) );
2327+}
2328+
2329+template<typename F>
2330+inline FloatImpl<F> FloatImpl<F>::ceil() const {
2331+ return FloatImpl<F>( std::ceil( value_ ) );
2332+}
2333+
2334+template<typename F>
2335+inline FloatImpl<F> FloatImpl<F>::cos() const {
2336+ return FloatImpl<F>( std::cos( value_ ) );
2337+}
2338+
2339+template<typename F>
2340+inline FloatImpl<F> FloatImpl<F>::cosh() const {
2341+ return FloatImpl<F>( std::cosh( value_ ) );
2342+}
2343+
2344+template<typename F>
2345+inline FloatImpl<F> FloatImpl<F>::exp() const {
2346+ return FloatImpl<F>( std::exp( value_ ) );
2347+}
2348+
2349+template<typename F>
2350+inline FloatImpl<F> FloatImpl<F>::exp10() const {
2351+ return FloatImpl<F>( std::pow( 10, value_ ) );
2352+}
2353+
2354+template<typename F>
2355+inline FloatImpl<F> FloatImpl<F>::floor() const {
2356+ return FloatImpl<F>( std::floor( value_ ) );
2357+}
2358+
2359+template<typename F>
2360+inline FloatImpl<F> FloatImpl<F>::fmod( double d ) const {
2361+ return FloatImpl<F>( std::fmod( value_, static_cast<F>( d ) ) );
2362+}
2363+
2364+template<typename F>
2365+inline FloatImpl<F>
2366+FloatImpl<F>::fmod( FloatImpl<F> const &f ) const {
2367+ return FloatImpl<F>( fmod( f.value_ ) );
2368+}
2369+
2370+template<typename F>
2371+FloatImpl<F> FloatImpl<F>::log() const {
2372+ return value_ < 0 ? nan() : FloatImpl<F>( std::log( value_ ) );
2373+}
2374+
2375+template<typename F>
2376+FloatImpl<F> FloatImpl<F>::log10() const {
2377+ return value_ < 0 ? nan() : FloatImpl<F>( std::log10( value_ ) );
2378+}
2379+
2380+template<typename F>
2381+inline FloatImpl<F> FloatImpl<F>::pow( int p ) const {
2382+ return FloatImpl<F>( std::pow( value_, p ) );
2383+}
2384+
2385+template<typename F>
2386+inline FloatImpl<F>
2387+FloatImpl<F>::pow( FloatImpl<F> const &p ) const {
2388+ return FloatImpl<F>(
2389+ p.isNaN() ? value_ : std::pow( value_, p.value_ )
2390+ );
2391+}
2392+
2393+template<typename F>
2394+inline FloatImpl<F> FloatImpl<F>::sin() const {
2395+ return FloatImpl<F>( std::sin( value_ ) );
2396+}
2397+
2398+template<typename F>
2399+inline FloatImpl<F> FloatImpl<F>::sinh() const {
2400+ return FloatImpl<F>( std::sinh( value_ ) );
2401+}
2402+
2403+template<typename F>
2404+inline FloatImpl<F> FloatImpl<F>::sqrt() const {
2405 return value_ < 0 ? nan() : FloatImpl( std::sqrt( value_ ) );
2406 }
2407
2408-template<typename FloatType> inline FloatImpl<FloatType>
2409-FloatImpl<FloatType>::tan() const {
2410- return std::tan( value_ );
2411+template<typename F>
2412+inline FloatImpl<F> FloatImpl<F>::tan() const {
2413+ return FloatImpl<F>( std::tan( value_ ) );
2414 }
2415
2416-template<typename FloatType> inline FloatImpl<FloatType>
2417-FloatImpl<FloatType>::tanh() const {
2418- return std::tanh( value_ );
2419+template<typename F>
2420+inline FloatImpl<F> FloatImpl<F>::tanh() const {
2421+ return FloatImpl<F>( std::tanh( value_ ) );
2422 }
2423
2424 ////////// miscellaneous //////////////////////////////////////////////////////
2425
2426-template<typename T>
2427-template<typename U>
2428-inline int FloatImpl<T>::compare( FloatImpl<U> const &f ) const {
2429+template<typename F> template<typename G>
2430+inline int FloatImpl<F>::compare( FloatImpl<G> const &f ) const {
2431 return value_ < f.value_ ? -1 : value_ > f.value_ ? 1 : 0;
2432 }
2433
2434-template<typename FloatType>
2435-inline uint32_t FloatImpl<FloatType>::hash() const {
2436+template<typename F>
2437+inline uint32_t FloatImpl<F>::hash() const {
2438 return static_cast<uint32_t>( value_ );
2439 }
2440
2441-template<typename FloatType>
2442-inline bool FloatImpl<FloatType>::isNeg() const {
2443+template<typename F>
2444+inline bool FloatImpl<F>::isNeg() const {
2445 return value_ < 0;
2446 }
2447
2448-template<typename FloatType>
2449-inline bool FloatImpl<FloatType>::isPos() const {
2450+template<typename F>
2451+inline bool FloatImpl<F>::isPos() const {
2452 return value_ > 0;
2453 }
2454
2455-template<typename FloatType>
2456-inline bool FloatImpl<FloatType>::isPosZero() const {
2457+template<typename F>
2458+inline bool FloatImpl<F>::isPosZero() const {
2459 return value_ == 0 && !isNegZero();
2460 }
2461
2462-template<typename FloatType>
2463-inline bool FloatImpl<FloatType>::isNaN() const {
2464+template<typename F>
2465+inline bool FloatImpl<F>::isNaN() const {
2466 return value_ != value_;
2467 }
2468
2469-template<typename FloatType>
2470-inline bool FloatImpl<FloatType>::isNegInf() const {
2471- return value_ == -std::numeric_limits<FloatType>::infinity();
2472-}
2473-
2474-template<typename FloatType>
2475-inline bool FloatImpl<FloatType>::isPosInf() const {
2476- return value_ == std::numeric_limits<FloatType>::infinity();
2477-}
2478-
2479-template<typename FloatType>
2480-inline bool FloatImpl<FloatType>::isFinite() const {
2481+template<typename F>
2482+inline bool FloatImpl<F>::isNegInf() const {
2483+ return value_ == -std::numeric_limits<F>::infinity();
2484+}
2485+
2486+template<typename F>
2487+inline bool FloatImpl<F>::isPosInf() const {
2488+ return value_ == std::numeric_limits<F>::infinity();
2489+}
2490+
2491+template<typename F>
2492+inline bool FloatImpl<F>::isFinite() const {
2493 return !isNaN() && !isPosInf() && !isNegInf();
2494 }
2495
2496-template<typename FloatType>
2497-inline bool FloatImpl<FloatType>::isInteger() const {
2498+template<typename F>
2499+inline bool FloatImpl<F>::isInteger() const {
2500 return isFinite() && ::floor( value_ ) == value_;
2501 }
2502
2503-template <typename FloatType>
2504-inline bool FloatImpl<FloatType>::isZero() const {
2505+template <typename F>
2506+inline bool FloatImpl<F>::isZero() const {
2507 return value_ == 0;
2508 }
2509
2510-template<typename FloatType> inline
2511-std::ostream& operator<<( std::ostream &os, FloatImpl<FloatType> const &f ) {
2512+template<typename F>
2513+inline std::ostream& operator<<( std::ostream &os, FloatImpl<F> const &f ) {
2514 return os << f.toString();
2515 }
2516
2517
2518=== modified file 'src/zorbatypes/integer.cpp'
2519--- src/zorbatypes/integer.cpp 2012-03-30 19:03:09 +0000
2520+++ src/zorbatypes/integer.cpp 2012-04-16 15:38:09 +0000
2521@@ -230,13 +230,13 @@
2522
2523 TEMPLATE_DECL(T)
2524 INTEGER_IMPL(T) INTEGER_IMPL(T)::round( IntegerImpl const &precision ) const {
2525- return IntegerImpl( Decimal::round( itod(), precision.itod() ) );
2526+ return IntegerImpl( Decimal::round2( itod(), precision.itod() ) );
2527 }
2528
2529 TEMPLATE_DECL(T)
2530 INTEGER_IMPL(T)
2531 INTEGER_IMPL(T)::roundHalfToEven( IntegerImpl const &precision ) const {
2532- return IntegerImpl( Decimal::roundHalfToEven( itod(), precision.itod() ) );
2533+ return IntegerImpl( Decimal::roundHalfToEven2( itod(), precision.itod() ) );
2534 }
2535
2536 ////////// miscellaneous //////////////////////////////////////////////////////
2537
2538=== modified file 'src/zorbatypes/integer.h'
2539--- src/zorbatypes/integer.h 2012-04-12 02:08:10 +0000
2540+++ src/zorbatypes/integer.h 2012-04-16 15:38:09 +0000
2541@@ -22,8 +22,8 @@
2542 #include <limits>
2543
2544 #include <zorba/config.h>
2545+
2546 #include "common/common.h"
2547-
2548 #include "util/stl_util.h"
2549
2550 #include "m_apm.h"
2551@@ -32,25 +32,25 @@
2552 #include "zstring.h"
2553
2554 #ifdef ZORBA_WITH_BIG_INTEGER
2555-# define TEMPLATE_DECL(T) /* nothing */
2556-# define INTEGER_IMPL(T) IntegerImpl
2557+# define TEMPLATE_DECL(I) /* nothing */
2558+# define TEMPLATE_DECL2(I,A) template<typename A>
2559+# define INTEGER_IMPL(I) IntegerImpl
2560 #else
2561-# define TEMPLATE_DECL(T) template<typename T>
2562-# define INTEGER_IMPL(T) IntegerImpl<T>
2563+# define TEMPLATE_DECL(I) template<typename I>
2564+# define TEMPLATE_DECL2(I,A) template<typename I,typename A>
2565+# define INTEGER_IMPL(I) IntegerImpl<I>
2566 #endif /* ZORBA_WITH_BIG_INTEGER */
2567 #define INTEGER_IMPL_LL INTEGER_IMPL(long long)
2568 #define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
2569
2570 namespace zorba {
2571
2572-TEMPLATE_DECL(T)
2573+TEMPLATE_DECL(I)
2574 class IntegerImpl;
2575
2576-namespace serialization
2577-{
2578+namespace serialization {
2579 class Archiver;
2580-
2581- TEMPLATE_DECL(T) void operator&( Archiver&, INTEGER_IMPL(T)& );
2582+ TEMPLATE_DECL(I) void operator&( Archiver&, INTEGER_IMPL(I)& );
2583 }
2584
2585 ///////////////////////////////////////////////////////////////////////////////
2586@@ -61,23 +61,20 @@
2587
2588 ////////// constructors /////////////////////////////////////////////////////
2589
2590- IntegerImpl( char c );
2591- IntegerImpl( signed char c );
2592- IntegerImpl( short n );
2593- IntegerImpl( int n = 0 );
2594- IntegerImpl( long n );
2595- IntegerImpl( long long n );
2596- IntegerImpl( unsigned char c );
2597- IntegerImpl( unsigned short n );
2598- IntegerImpl( unsigned int n );
2599- IntegerImpl( unsigned long n );
2600- IntegerImpl( unsigned long long n );
2601- IntegerImpl( float n );
2602- IntegerImpl( double n );
2603- IntegerImpl( Decimal const &d );
2604-
2605- TEMPLATE_DECL(U)
2606- IntegerImpl( INTEGER_IMPL(U) const &i );
2607+ explicit IntegerImpl( char c );
2608+ explicit IntegerImpl( signed char c );
2609+ explicit IntegerImpl( short n );
2610+ explicit IntegerImpl( int n = 0 );
2611+ explicit IntegerImpl( long n );
2612+ explicit IntegerImpl( long long n );
2613+ explicit IntegerImpl( unsigned char c );
2614+ explicit IntegerImpl( unsigned short n );
2615+ explicit IntegerImpl( unsigned int n );
2616+ explicit IntegerImpl( unsigned long n );
2617+ explicit IntegerImpl( unsigned long long n );
2618+ explicit IntegerImpl( float n );
2619+ explicit IntegerImpl( double n );
2620+ explicit IntegerImpl( Decimal const &d );
2621
2622 /**
2623 * Constructs an %IntegerImpl from a C string.
2624@@ -89,7 +86,7 @@
2625 * or overflows the smallest or largest representable integer (only when not
2626 * compiled with ZORBA_WITH_BIG_INTEGER).
2627 */
2628- IntegerImpl( char const *s );
2629+ explicit IntegerImpl( char const *s );
2630
2631 /**
2632 * Constructs an %IntegerImpl from a Double.
2633@@ -97,7 +94,7 @@
2634 * @param d The Double.
2635 * @throw std::invalid_argument if \a d is not finite.
2636 */
2637- IntegerImpl( Double const &d );
2638+ explicit IntegerImpl( Double const &d );
2639
2640 /**
2641 * Constructs an %IntegerImpl from a Float.
2642@@ -105,54 +102,113 @@
2643 * @param f The Float.
2644 * @throw std::invalid_argument if \a f is not finite.
2645 */
2646- IntegerImpl( Float const &f );
2647+ explicit IntegerImpl( Float const &f );
2648+
2649+ /**
2650+ * Constructs from another %IntegerImpl even if its \c IntType is different.
2651+ * (This subsumes the conventional copy constructor.)
2652+ *
2653+ * @tparam IntType2 the integer type of \a i.
2654+ * @param i The %IntegerImpl to copy from.
2655+ */
2656+ TEMPLATE_DECL(IntType2)
2657+ IntegerImpl( INTEGER_IMPL(IntType2) const &i );
2658
2659 ////////// assignment operators /////////////////////////////////////////////
2660
2661- IntegerImpl& operator=( char c );
2662- IntegerImpl& operator=( signed char c );
2663- IntegerImpl& operator=( short n );
2664- IntegerImpl& operator=( int n );
2665- IntegerImpl& operator=( long n );
2666- IntegerImpl& operator=( long long n );
2667- IntegerImpl& operator=( unsigned char c );
2668- IntegerImpl& operator=( unsigned short n );
2669- IntegerImpl& operator=( unsigned int n );
2670- IntegerImpl& operator=( unsigned long n );
2671- IntegerImpl& operator=( unsigned long long n );
2672- IntegerImpl& operator=( float n );
2673- IntegerImpl& operator=( double n );
2674+ /**
2675+ * Assign from an %IntegerImpl even if its \c IntType is different.
2676+ * (This subsumes the conventional assignment operator.)
2677+ *
2678+ * @tparam IntType2 the integer type of \a i.
2679+ * @param i The %IntegerImpl to assign from.
2680+ * @return Returns \c *this.
2681+ */
2682+ TEMPLATE_DECL(IntType2)
2683+ IntegerImpl& operator=( INTEGER_IMPL(IntType2) const &i );
2684+
2685+ /**
2686+ * For every built-in arithmetic type A, assign to this %IntegerImpl.
2687+ *
2688+ * @tparam A The built-in arithmetic type.
2689+ * @param n The arithmetic value to assign.
2690+ * @return Returns \c *this.
2691+ */
2692+ template<typename A>
2693+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
2694+ IntegerImpl&>::type
2695+ operator=( A n );
2696+
2697+ // These arithmetic types have to be special-cased.
2698+ IntegerImpl& operator=( long long );
2699+ IntegerImpl& operator=( unsigned long );
2700+ IntegerImpl& operator=( unsigned long long );
2701+
2702 IntegerImpl& operator=( char const *s );
2703 IntegerImpl& operator=( Decimal const &d );
2704 IntegerImpl& operator=( Double const &d );
2705 IntegerImpl& operator=( Float const &f );
2706
2707- TEMPLATE_DECL(U)
2708- IntegerImpl& operator=( INTEGER_IMPL(U) const &i );
2709-
2710 ////////// arithmetic operators /////////////////////////////////////////////
2711
2712 #define ZORBA_INTEGER_OP(OP) \
2713- TEMPLATE_DECL(T) friend \
2714- INTEGER_IMPL(T) operator OP( INTEGER_IMPL(T) const&, \
2715- INTEGER_IMPL(T) const& ); \
2716- TEMPLATE_DECL(T) friend \
2717- Decimal operator OP( INTEGER_IMPL(T) const&, Decimal const& ); \
2718- TEMPLATE_DECL(T) friend \
2719- Decimal operator OP( Decimal const&, INTEGER_IMPL(T) const& )
2720-
2721- ZORBA_INTEGER_OP(+);
2722- ZORBA_INTEGER_OP(-);
2723- ZORBA_INTEGER_OP(*);
2724- ZORBA_INTEGER_OP(/);
2725- ZORBA_INTEGER_OP(%);
2726-#undef ZORBA_INTEGER_OP
2727-
2728- IntegerImpl& operator+=( IntegerImpl const& );
2729- IntegerImpl& operator-=( IntegerImpl const& );
2730- IntegerImpl& operator*=( IntegerImpl const& );
2731- IntegerImpl& operator/=( IntegerImpl const& );
2732- IntegerImpl& operator%=( IntegerImpl const& );
2733+ TEMPLATE_DECL(I) friend \
2734+ INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const&, \
2735+ INTEGER_IMPL(I) const& ); \
2736+ \
2737+ TEMPLATE_DECL(I) friend \
2738+ Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \
2739+ \
2740+ TEMPLATE_DECL(I) friend \
2741+ Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& )
2742+
2743+ ZORBA_INTEGER_OP(+);
2744+ ZORBA_INTEGER_OP(-);
2745+ ZORBA_INTEGER_OP(*);
2746+ ZORBA_INTEGER_OP(/);
2747+ ZORBA_INTEGER_OP(%);
2748+#undef ZORBA_INTEGER_OP
2749+
2750+#define ZORBA_INTEGER_OP(OP) \
2751+ TEMPLATE_DECL2(I,A) friend \
2752+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
2753+ INTEGER_IMPL(I)>::type \
2754+ operator OP( INTEGER_IMPL(I) const&, A ); \
2755+ \
2756+ TEMPLATE_DECL2(I,A) friend \
2757+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
2758+ INTEGER_IMPL(I)>::type \
2759+ operator OP( A, INTEGER_IMPL(I) const& )
2760+
2761+ ZORBA_INTEGER_OP(+);
2762+ ZORBA_INTEGER_OP(-);
2763+ ZORBA_INTEGER_OP(*);
2764+ ZORBA_INTEGER_OP(/);
2765+ ZORBA_INTEGER_OP(%);
2766+#undef ZORBA_INTEGER_OP
2767+
2768+#define ZORBA_INTEGER_OP(OP,TYPE) \
2769+ IntegerImpl& operator OP( TYPE )
2770+
2771+ ZORBA_INTEGER_OP(+=,IntegerImpl const&);
2772+ ZORBA_INTEGER_OP(-=,IntegerImpl const&);
2773+ ZORBA_INTEGER_OP(*=,IntegerImpl const&);
2774+ ZORBA_INTEGER_OP(/=,IntegerImpl const&);
2775+ ZORBA_INTEGER_OP(%=,IntegerImpl const&);
2776+#undef ZORBA_INTEGER_OP
2777+
2778+#define ZORBA_INTEGER_OP(OP) \
2779+ template<typename A> \
2780+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
2781+ IntegerImpl&>::type \
2782+ operator OP( A )
2783+
2784+ ZORBA_INTEGER_OP(+=);
2785+ ZORBA_INTEGER_OP(-=);
2786+ ZORBA_INTEGER_OP(*=);
2787+ ZORBA_INTEGER_OP(/=);
2788+ ZORBA_INTEGER_OP(%=);
2789+#undef ZORBA_INTEGER_OP
2790
2791 IntegerImpl operator-() const;
2792
2793@@ -164,12 +220,31 @@
2794 ////////// relational operators /////////////////////////////////////////////
2795
2796 #define ZORBA_INTEGER_OP(OP) \
2797- TEMPLATE_DECL(T) friend \
2798- bool operator OP( INTEGER_IMPL(T) const&, INTEGER_IMPL(T) const& ); \
2799- TEMPLATE_DECL(T) friend \
2800- bool operator OP( INTEGER_IMPL(T) const&, Decimal const& ); \
2801- TEMPLATE_DECL(T) friend \
2802- bool operator OP( Decimal const&, INTEGER_IMPL(T) const& )
2803+ TEMPLATE_DECL(I) friend \
2804+ bool operator OP( INTEGER_IMPL(I) const&, INTEGER_IMPL(I) const& ); \
2805+ \
2806+ TEMPLATE_DECL(I) friend \
2807+ bool operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \
2808+ \
2809+ TEMPLATE_DECL(I) friend \
2810+ bool operator OP( Decimal const&, INTEGER_IMPL(I) const& )
2811+
2812+ ZORBA_INTEGER_OP(==);
2813+ ZORBA_INTEGER_OP(!=);
2814+ ZORBA_INTEGER_OP(< );
2815+ ZORBA_INTEGER_OP(<=);
2816+ ZORBA_INTEGER_OP(> );
2817+ ZORBA_INTEGER_OP(>=);
2818+#undef ZORBA_INTEGER_OP
2819+
2820+#define ZORBA_INTEGER_OP(OP) \
2821+ TEMPLATE_DECL2(I,A) friend \
2822+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \
2823+ operator OP( INTEGER_IMPL(I) const&, A ); \
2824+ \
2825+ TEMPLATE_DECL2(I,A) friend \
2826+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \
2827+ operator OP( A, INTEGER_IMPL(I) const& )
2828
2829 ZORBA_INTEGER_OP(==);
2830 ZORBA_INTEGER_OP(!=);
2831@@ -214,6 +289,11 @@
2832 }
2833
2834 #ifdef ZORBA_WITH_BIG_INTEGER
2835+ template<typename T>
2836+ static value_type cast( T n ) {
2837+ return value_type( static_cast<long>( n ) );
2838+ }
2839+
2840 static value_type ftoi( MAPM const &d ) {
2841 return d.sign() >= 0 ? d.floor() : d.ceil();
2842 }
2843@@ -222,6 +302,11 @@
2844 return value_; // intentional no-op
2845 }
2846 #else
2847+ template<typename T>
2848+ static value_type cast( T n ) {
2849+ return static_cast<value_type>( n );
2850+ }
2851+
2852 bool is_long() const;
2853
2854 static value_type ftoi( value_type v ) {
2855@@ -239,7 +324,7 @@
2856 template<typename T> friend class FloatImpl;
2857
2858 #ifndef ZORBA_WITH_BIG_INTEGER
2859- template<typename U> friend class IntegerImpl;
2860+ template<typename T> friend class IntegerImpl;
2861 #endif /* ZORBA_WITH_BIG_INTEGER */
2862
2863 friend xs_int to_xs_int( INTEGER_IMPL_LL const& );
2864@@ -247,8 +332,8 @@
2865 friend xs_unsignedInt to_xs_unsignedInt( INTEGER_IMPL_LL const& );
2866 friend xs_unsignedLong to_xs_unsignedLong( INTEGER_IMPL_LL const& );
2867
2868- TEMPLATE_DECL(T) friend
2869- void serialization::operator&( serialization::Archiver&, INTEGER_IMPL(T)& );
2870+ TEMPLATE_DECL(I) friend
2871+ void serialization::operator&( serialization::Archiver&, INTEGER_IMPL(I)& );
2872 };
2873
2874 typedef INTEGER_IMPL_LL Integer;
2875@@ -256,78 +341,78 @@
2876
2877 ////////// constructors ///////////////////////////////////////////////////////
2878
2879-TEMPLATE_DECL(T)
2880-inline INTEGER_IMPL(T)::IntegerImpl( char c ) :
2881- value_( static_cast<long>( c ) )
2882-{
2883-}
2884-
2885-TEMPLATE_DECL(T)
2886-inline INTEGER_IMPL(T)::IntegerImpl( signed char c ) :
2887- value_( static_cast<long>( c ) )
2888-{
2889-}
2890-
2891-TEMPLATE_DECL(T)
2892-inline INTEGER_IMPL(T)::IntegerImpl( short n ) :
2893- value_( static_cast<long>( n ) )
2894-{
2895-}
2896-
2897-TEMPLATE_DECL(T)
2898-inline INTEGER_IMPL(T)::IntegerImpl( int n ) :
2899- value_( static_cast<long>( n ) )
2900-{
2901-}
2902-
2903-TEMPLATE_DECL(T)
2904-inline INTEGER_IMPL(T)::IntegerImpl( long n ) :
2905- value_( n )
2906-{
2907-}
2908-
2909-#ifndef ZORBA_WITH_BIG_INTEGER
2910-TEMPLATE_DECL(T)
2911-inline INTEGER_IMPL(T)::IntegerImpl( long long n ) :
2912- value_( n )
2913-{
2914-}
2915-#endif /* ZORBA_WITH_BIG_INTEGER */
2916-
2917-TEMPLATE_DECL(T)
2918-inline INTEGER_IMPL(T)::IntegerImpl( unsigned char c ) :
2919- value_( static_cast<long>( c ) )
2920-{
2921-}
2922-
2923-TEMPLATE_DECL(T)
2924-inline INTEGER_IMPL(T)::IntegerImpl( unsigned short n ) :
2925- value_( static_cast<long>( n ) )
2926-{
2927-}
2928-
2929-TEMPLATE_DECL(T)
2930-inline INTEGER_IMPL(T)::IntegerImpl( unsigned int n ) :
2931- value_( static_cast<long>( n ) )
2932-{
2933-}
2934-
2935-#ifndef ZORBA_WITH_BIG_INTEGER
2936-TEMPLATE_DECL(T)
2937-inline INTEGER_IMPL(T)::IntegerImpl( unsigned long n ) :
2938- value_( static_cast<value_type>( n ) )
2939-{
2940-}
2941-
2942-TEMPLATE_DECL(T)
2943-inline INTEGER_IMPL(T)::IntegerImpl( unsigned long long n ) :
2944- value_( static_cast<value_type>( n ) )
2945-{
2946-}
2947-#endif /* ZORBA_WITH_BIG_INTEGER */
2948-
2949-TEMPLATE_DECL(T)
2950-inline INTEGER_IMPL(T)::IntegerImpl( float n ) :
2951+TEMPLATE_DECL(I)
2952+inline INTEGER_IMPL(I)::IntegerImpl( char c ) :
2953+ value_( static_cast<long>( c ) )
2954+{
2955+}
2956+
2957+TEMPLATE_DECL(I)
2958+inline INTEGER_IMPL(I)::IntegerImpl( signed char c ) :
2959+ value_( static_cast<long>( c ) )
2960+{
2961+}
2962+
2963+TEMPLATE_DECL(I)
2964+inline INTEGER_IMPL(I)::IntegerImpl( short n ) :
2965+ value_( static_cast<long>( n ) )
2966+{
2967+}
2968+
2969+TEMPLATE_DECL(I)
2970+inline INTEGER_IMPL(I)::IntegerImpl( int n ) :
2971+ value_( static_cast<long>( n ) )
2972+{
2973+}
2974+
2975+TEMPLATE_DECL(I)
2976+inline INTEGER_IMPL(I)::IntegerImpl( long n ) :
2977+ value_( n )
2978+{
2979+}
2980+
2981+#ifndef ZORBA_WITH_BIG_INTEGER
2982+TEMPLATE_DECL(I)
2983+inline INTEGER_IMPL(I)::IntegerImpl( long long n ) :
2984+ value_( n )
2985+{
2986+}
2987+#endif /* ZORBA_WITH_BIG_INTEGER */
2988+
2989+TEMPLATE_DECL(I)
2990+inline INTEGER_IMPL(I)::IntegerImpl( unsigned char c ) :
2991+ value_( static_cast<long>( c ) )
2992+{
2993+}
2994+
2995+TEMPLATE_DECL(I)
2996+inline INTEGER_IMPL(I)::IntegerImpl( unsigned short n ) :
2997+ value_( static_cast<long>( n ) )
2998+{
2999+}
3000+
3001+TEMPLATE_DECL(I)
3002+inline INTEGER_IMPL(I)::IntegerImpl( unsigned int n ) :
3003+ value_( static_cast<long>( n ) )
3004+{
3005+}
3006+
3007+#ifndef ZORBA_WITH_BIG_INTEGER
3008+TEMPLATE_DECL(I)
3009+inline INTEGER_IMPL(I)::IntegerImpl( unsigned long n ) :
3010+ value_( static_cast<value_type>( n ) )
3011+{
3012+}
3013+
3014+TEMPLATE_DECL(I)
3015+inline INTEGER_IMPL(I)::IntegerImpl( unsigned long long n ) :
3016+ value_( static_cast<value_type>( n ) )
3017+{
3018+}
3019+#endif /* ZORBA_WITH_BIG_INTEGER */
3020+
3021+TEMPLATE_DECL(I)
3022+inline INTEGER_IMPL(I)::IntegerImpl( float n ) :
3023 #ifdef ZORBA_WITH_BIG_INTEGER
3024 value_( static_cast<double>( n ) )
3025 #else
3026@@ -336,8 +421,8 @@
3027 {
3028 }
3029
3030-TEMPLATE_DECL(T)
3031-inline INTEGER_IMPL(T)::IntegerImpl( double n ) :
3032+TEMPLATE_DECL(I)
3033+inline INTEGER_IMPL(I)::IntegerImpl( double n ) :
3034 #ifdef ZORBA_WITH_BIG_INTEGER
3035 value_( n )
3036 #else
3037@@ -346,111 +431,56 @@
3038 {
3039 }
3040
3041-TEMPLATE_DECL(T)
3042-inline INTEGER_IMPL(T)::IntegerImpl( char const *s ) {
3043+TEMPLATE_DECL(I)
3044+inline INTEGER_IMPL(I)::IntegerImpl( char const *s ) {
3045 parse( s );
3046 }
3047
3048-TEMPLATE_DECL(T)
3049-TEMPLATE_DECL(U)
3050-inline INTEGER_IMPL(T)::IntegerImpl( INTEGER_IMPL(U) const &i ) :
3051+TEMPLATE_DECL(I)
3052+TEMPLATE_DECL(J)
3053+inline INTEGER_IMPL(I)::IntegerImpl( INTEGER_IMPL(J) const &i ) :
3054 value_( i.value_ )
3055 {
3056 }
3057
3058 ////////// assignment operators ///////////////////////////////////////////////
3059
3060-TEMPLATE_DECL(T)
3061-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( char c ) {
3062- value_ = static_cast<long>( c );
3063- return *this;
3064-}
3065-
3066-TEMPLATE_DECL(T)
3067-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( signed char c ) {
3068- value_ = static_cast<long>( c );
3069- return *this;
3070-}
3071-
3072-TEMPLATE_DECL(T)
3073-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( short n ) {
3074- value_ = static_cast<long>( n );
3075- return *this;
3076-}
3077-
3078-TEMPLATE_DECL(T)
3079-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( int n ) {
3080- value_ = static_cast<long>( n );
3081- return *this;
3082-}
3083-
3084-TEMPLATE_DECL(T)
3085-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( long n ) {
3086- value_ = n;
3087- return *this;
3088-}
3089-
3090-#ifndef ZORBA_WITH_BIG_INTEGER
3091-TEMPLATE_DECL(T)
3092-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( long long n ) {
3093- value_ = n;
3094- return *this;
3095-}
3096-#endif /* ZORBA_WITH_BIG_INTEGER */
3097-
3098-TEMPLATE_DECL(T)
3099-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned char c ) {
3100- value_ = static_cast<long>( c );
3101- return *this;
3102-}
3103-
3104-TEMPLATE_DECL(T)
3105-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned short n ) {
3106- value_ = static_cast<long>( n );
3107- return *this;
3108-}
3109-
3110-TEMPLATE_DECL(T)
3111-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned int n ) {
3112- value_ = static_cast<long>( n );
3113- return *this;
3114-}
3115-
3116-#ifndef ZORBA_WITH_BIG_INTEGER
3117-TEMPLATE_DECL(T)
3118-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned long n ) {
3119- value_ = static_cast<long>( n );
3120- return *this;
3121-}
3122-
3123-TEMPLATE_DECL(T)
3124-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned long long n ) {
3125- value_ = n;
3126- return *this;
3127-}
3128-#endif /* ZORBA_WITH_BIG_INTEGER */
3129-
3130-TEMPLATE_DECL(T)
3131-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( float n ) {
3132- value_ = static_cast<long>( n );
3133- return *this;
3134-}
3135-
3136-TEMPLATE_DECL(T)
3137-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( double n ) {
3138- value_ = static_cast<long>( n );
3139- return *this;
3140-}
3141-
3142-TEMPLATE_DECL(T)
3143-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( char const *s ) {
3144+TEMPLATE_DECL(I) template<typename A> inline
3145+typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
3146+ INTEGER_IMPL(I)&>::type
3147+INTEGER_IMPL(I)::operator=( A n ) {
3148+ value_ = static_cast<long>( n );
3149+ return *this;
3150+}
3151+
3152+#ifndef ZORBA_WITH_BIG_INTEGER
3153+template<typename I>
3154+inline IntegerImpl<I>& IntegerImpl<I>::operator=( long long n ) {
3155+ value_ = n;
3156+ return *this;
3157+}
3158+
3159+template<typename I>
3160+inline IntegerImpl<I>& IntegerImpl<I>::operator=( unsigned long n ) {
3161+ value_ = static_cast<long>( n );
3162+ return *this;
3163+}
3164+
3165+template<typename I>
3166+inline IntegerImpl<I>& IntegerImpl<I>::operator=( unsigned long long n ) {
3167+ value_ = n;
3168+ return *this;
3169+}
3170+#endif /* ZORBA_WITH_BIG_INTEGER */
3171+
3172+TEMPLATE_DECL(I)
3173+inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( char const *s ) {
3174 parse( s );
3175 return *this;
3176 }
3177
3178-TEMPLATE_DECL(T)
3179-TEMPLATE_DECL(U)
3180-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( INTEGER_IMPL(U) const &i ) {
3181+TEMPLATE_DECL(I) TEMPLATE_DECL(J)
3182+inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( INTEGER_IMPL(J) const &i ) {
3183 value_ = i.value_;
3184 return *this;
3185 }
3186@@ -458,26 +488,66 @@
3187 ////////// arithmetic operators ///////////////////////////////////////////////
3188
3189 #define ZORBA_INTEGER_OP(OP) \
3190- TEMPLATE_DECL(T) inline \
3191- INTEGER_IMPL(T) operator OP( INTEGER_IMPL(T) const &i, \
3192- INTEGER_IMPL(T) const &j ) { \
3193- return i.value_ OP j.value_; \
3194- }
3195-
3196-ZORBA_INTEGER_OP(+)
3197-ZORBA_INTEGER_OP(-)
3198-ZORBA_INTEGER_OP(*)
3199-ZORBA_INTEGER_OP(%)
3200-#undef ZORBA_INTEGER_OP
3201-
3202-TEMPLATE_DECL(T) inline
3203-INTEGER_IMPL(T) operator/( INTEGER_IMPL(T) const &i, INTEGER_IMPL(T) const &j ) {
3204- return INTEGER_IMPL(T)::ftoi( i.value_ / j.value_ );
3205+ TEMPLATE_DECL(I) inline \
3206+ INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const &i, \
3207+ INTEGER_IMPL(I) const &j ) { \
3208+ return INTEGER_IMPL(I)( i.value_ OP j.value_ ); \
3209+ }
3210+
3211+ZORBA_INTEGER_OP(+)
3212+ZORBA_INTEGER_OP(-)
3213+ZORBA_INTEGER_OP(*)
3214+ZORBA_INTEGER_OP(%)
3215+#undef ZORBA_INTEGER_OP
3216+
3217+TEMPLATE_DECL(I) inline
3218+INTEGER_IMPL(I) operator/( INTEGER_IMPL(I) const &i,
3219+ INTEGER_IMPL(I) const &j ) {
3220+ return INTEGER_IMPL(I)( INTEGER_IMPL(I)::ftoi( i.value_ / j.value_ ) );
3221+}
3222+
3223+#define ZORBA_INTEGER_OP(OP) \
3224+ TEMPLATE_DECL2(I,A) inline \
3225+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
3226+ INTEGER_IMPL(I)>::type \
3227+ operator OP( INTEGER_IMPL(I) const& i, A n ) { \
3228+ return INTEGER_IMPL(I)( i.value_ OP INTEGER_IMPL(I)::cast( n ) ); \
3229+ } \
3230+ \
3231+ TEMPLATE_DECL2(I,A) inline \
3232+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
3233+ INTEGER_IMPL(I)>::type \
3234+ operator OP( A n, INTEGER_IMPL(I) const &i ) { \
3235+ return INTEGER_IMPL(I)( INTEGER_IMPL(I)::cast( n ) OP i.value_ ); \
3236+ }
3237+
3238+ZORBA_INTEGER_OP(+)
3239+ZORBA_INTEGER_OP(-)
3240+ZORBA_INTEGER_OP(*)
3241+ZORBA_INTEGER_OP(%)
3242+#undef ZORBA_INTEGER_OP
3243+
3244+TEMPLATE_DECL2(I,A) inline
3245+typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
3246+ INTEGER_IMPL(I)>::type
3247+operator/( INTEGER_IMPL(I) const &i, A n ) {
3248+ return INTEGER_IMPL(I)(
3249+ INTEGER_IMPL(I)::ftoi( i.value_ / INTEGER_IMPL(I)::cast( n ) )
3250+ );
3251+}
3252+
3253+TEMPLATE_DECL2(I,A) inline
3254+typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
3255+ INTEGER_IMPL(I)>::type
3256+operator/( A n, INTEGER_IMPL(I) const &i ) {
3257+ return INTEGER_IMPL(I)(
3258+ INTEGER_IMPL(I)::ftoi( INTEGER_IMPL(I)::cast( n ) / i.value_ )
3259+ );
3260 }
3261
3262 #define ZORBA_INTEGER_OP(OP) \
3263- TEMPLATE_DECL(T) inline \
3264- INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator OP( IntegerImpl const &i ) { \
3265+ TEMPLATE_DECL(I) inline \
3266+ INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator OP( IntegerImpl const &i ) { \
3267 value_ OP i.value_; \
3268 return *this; \
3269 }
3270@@ -488,39 +558,62 @@
3271 ZORBA_INTEGER_OP(%=)
3272 #undef ZORBA_INTEGER_OP
3273
3274-TEMPLATE_DECL(T)
3275-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator/=( IntegerImpl const &i ) {
3276+TEMPLATE_DECL(I)
3277+inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator/=( IntegerImpl const &i ) {
3278 value_ = ftoi( value_ / i.value_ );
3279 return *this;
3280 }
3281
3282-TEMPLATE_DECL(T)
3283-inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator-() const {
3284- return -value_;
3285-}
3286-
3287-TEMPLATE_DECL(T)
3288-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator++() {
3289+#define ZORBA_INTEGER_OP(OP) \
3290+ TEMPLATE_DECL(I) template<typename A> inline \
3291+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value, \
3292+ INTEGER_IMPL(I)&>::type \
3293+ INTEGER_IMPL(I)::operator OP( A n ) { \
3294+ value_ OP cast( n ); \
3295+ return *this; \
3296+ }
3297+
3298+ZORBA_INTEGER_OP(+=)
3299+ZORBA_INTEGER_OP(-=)
3300+ZORBA_INTEGER_OP(*=)
3301+ZORBA_INTEGER_OP(%=)
3302+#undef ZORBA_INTEGER_OP
3303+
3304+TEMPLATE_DECL(I) template<typename A> inline
3305+typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,
3306+ INTEGER_IMPL(I)&>::type
3307+INTEGER_IMPL(I)::operator/=( A n ) {
3308+ value_ = ftoi( value_ / cast( n ) );
3309+ return *this;
3310+}
3311+
3312+TEMPLATE_DECL(I)
3313+inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator-() const {
3314+ return INTEGER_IMPL(I)( -value_ );
3315+}
3316+
3317+TEMPLATE_DECL(I)
3318+inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator++() {
3319 ++value_;
3320 return *this;
3321 }
3322
3323-TEMPLATE_DECL(T)
3324-inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator++(int) {
3325- INTEGER_IMPL(T) const result( *this );
3326+TEMPLATE_DECL(I)
3327+inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator++(int) {
3328+ INTEGER_IMPL(I) const result( *this );
3329 ++value_;
3330 return result;
3331 }
3332
3333-TEMPLATE_DECL(T)
3334-inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator--() {
3335+TEMPLATE_DECL(I)
3336+inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator--() {
3337 --value_;
3338 return *this;
3339 }
3340
3341-TEMPLATE_DECL(T)
3342-inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator--(int) {
3343- INTEGER_IMPL(T) const result( *this );
3344+TEMPLATE_DECL(I)
3345+inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator--(int) {
3346+ INTEGER_IMPL(I) const result( *this );
3347 --value_;
3348 return result;
3349 }
3350@@ -528,8 +621,8 @@
3351 ////////// relational operators ///////////////////////////////////////////////
3352
3353 #define ZORBA_INTEGER_OP(OP) \
3354- TEMPLATE_DECL(T) inline \
3355- bool operator OP( INTEGER_IMPL(T) const &i, INTEGER_IMPL(T) const &j ) { \
3356+ TEMPLATE_DECL(I) inline \
3357+ bool operator OP( INTEGER_IMPL(I) const &i, INTEGER_IMPL(I) const &j ) { \
3358 return i.value_ OP j.value_; \
3359 }
3360
3361@@ -541,6 +634,27 @@
3362 ZORBA_INTEGER_OP(>=)
3363 #undef ZORBA_INTEGER_OP
3364
3365+#define ZORBA_INTEGER_OP(OP) \
3366+ TEMPLATE_DECL2(I,A) inline \
3367+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \
3368+ operator OP( INTEGER_IMPL(I) const &i, A n ) { \
3369+ return i.value_ OP INTEGER_IMPL(I)::cast( n ); \
3370+ } \
3371+ \
3372+ TEMPLATE_DECL2(I,A) inline \
3373+ typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<A>::value,bool>::type \
3374+ operator OP( A n, INTEGER_IMPL(I) const &i ) { \
3375+ return INTEGER_IMPL(I)::cast( n ) OP i.value_; \
3376+ } \
3377+
3378+ ZORBA_INTEGER_OP(==)
3379+ ZORBA_INTEGER_OP(!=)
3380+ ZORBA_INTEGER_OP(< )
3381+ ZORBA_INTEGER_OP(<=)
3382+ ZORBA_INTEGER_OP(> )
3383+ ZORBA_INTEGER_OP(>=)
3384+#undef ZORBA_INTEGER_OP
3385+
3386 ////////// miscellaneous //////////////////////////////////////////////////////
3387
3388 #ifdef ZORBA_WITH_BIG_INTEGER
3389@@ -555,31 +669,31 @@
3390
3391 #else
3392
3393-template<typename IntType>
3394-inline int IntegerImpl<IntType>::compare( IntegerImpl const &i ) const {
3395+template<typename I>
3396+inline int IntegerImpl<I>::compare( IntegerImpl const &i ) const {
3397 return value_ < i.value_ ? -1 : value_ > i.value_ ? 1 : 0;
3398 }
3399
3400-template<typename IntType>
3401-inline uint32_t IntegerImpl<IntType>::hash() const {
3402+template<typename I>
3403+inline uint32_t IntegerImpl<I>::hash() const {
3404 return static_cast<uint32_t>( value_ );
3405 }
3406
3407-template<typename IntType>
3408-inline bool IntegerImpl<IntType>::is_long() const {
3409+template<typename I>
3410+inline bool IntegerImpl<I>::is_long() const {
3411 return value_ >= std::numeric_limits<long>::min() &&
3412 value_ <= std::numeric_limits<long>::max();
3413 }
3414
3415-template<typename IntType>
3416-inline int IntegerImpl<IntType>::sign() const {
3417+template<typename I>
3418+inline int IntegerImpl<I>::sign() const {
3419 return ztd::lt0( value_ ) ? -1 : value_ > 0 ? 1 : 0;
3420 }
3421
3422 #endif /* ZORBA_WITH_BIG_INTEGER */
3423
3424-TEMPLATE_DECL(T)
3425-inline std::ostream& operator<<( std::ostream &os, INTEGER_IMPL(T) const &i ) {
3426+TEMPLATE_DECL(I)
3427+inline std::ostream& operator<<( std::ostream &os, INTEGER_IMPL(I) const &i ) {
3428 return os << i.toString();
3429 }
3430

Subscribers

People subscribed via source and target branches