Merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba

Proposed by Paul J. Lucas on 2013-04-25
Status: Merged
Approved by: Matthias Brantner on 2013-05-08
Approved revision: 11447
Merged at revision: 11443
Proposed branch: lp:~paul-lucas/zorba/bug-1090089
Merge into: lp:zorba
Diff against target: 5153 lines (+1559/-1216)
91 files modified
ChangeLog (+1/-0)
src/api/dynamiccontextimpl.cpp (+1/-0)
src/api/item.cpp (+3/-1)
src/api/itemfactoryimpl.cpp (+6/-3)
src/api/serialization/serializer.cpp (+1/-0)
src/capi/csequence.cpp (+4/-3)
src/common/shared_types.h (+12/-10)
src/compiler/expression/expr.cpp (+3/-0)
src/compiler/expression/expr_manager.cpp (+10/-8)
src/compiler/parser/jsoniq_parser.cpp (+5/-6)
src/compiler/parser/parser_helpers.h (+2/-0)
src/compiler/parser/parser_y_includes.h (+6/-6)
src/compiler/parser/symbol_table.cpp (+3/-0)
src/compiler/parser/xquery_parser.cpp (+5/-6)
src/compiler/parsetree/parsenode_print_xml_visitor.cpp (+5/-2)
src/compiler/parsetree/parsenodes.cpp (+1/-0)
src/compiler/parsetree/parsenodes.h (+3/-0)
src/compiler/rewriter/rules/flwor_rules.cpp (+5/-3)
src/compiler/rewriter/rules/fold_rules.cpp (+2/-0)
src/compiler/translator/translator.cpp (+7/-4)
src/functions/udf.cpp (+1/-0)
src/runtime/base/plan_iterator.cpp (+4/-8)
src/runtime/booleans/BooleanImpl.cpp (+1/-0)
src/runtime/collections/collections_base.h (+1/-0)
src/runtime/collections/collections_impl.cpp (+6/-7)
src/runtime/core/arithmetic_impl.cpp (+1/-0)
src/runtime/core/var_iterators.h (+1/-1)
src/runtime/durations_dates_times/durations_dates_times_impl.cpp (+2/-0)
src/runtime/full_text/ft_module_impl.cpp (+1/-0)
src/runtime/full_text/ft_util.cpp (+1/-0)
src/runtime/full_text/ftcontains_visitor.cpp (+1/-2)
src/runtime/hof/dynamic_fncall_iterator.cpp (+1/-0)
src/runtime/hof/fn_hof_functions_impl.cpp (+1/-0)
src/runtime/indexing/index_ddl.cpp (+13/-11)
src/runtime/introspection/sctx_impl.cpp (+1/-0)
src/runtime/item/item_impl.cpp (+1/-0)
src/runtime/json/jsoniq_functions_impl.cpp (+1/-0)
src/runtime/maths/pregenerated/maths.cpp (+4/-4)
src/runtime/maths/pregenerated/maths.h (+1/-0)
src/runtime/numerics/NumericsImpl.cpp (+9/-7)
src/runtime/numerics/format_integer.cpp (+1/-0)
src/runtime/numerics/format_number.cpp (+3/-2)
src/runtime/numerics/numerics_impl.cpp (+5/-3)
src/runtime/random/pregenerated/random.h (+1/-0)
src/runtime/sequences/pregenerated/sequences.cpp (+14/-14)
src/runtime/sequences/pregenerated/sequences.h (+1/-0)
src/runtime/sequences/sequences_impl.cpp (+12/-8)
src/runtime/spec/maths/maths.xml (+3/-2)
src/runtime/spec/random/random.xml (+4/-0)
src/runtime/spec/sequences/sequences.xml (+8/-7)
src/runtime/store/maps_impl.cpp (+1/-0)
src/runtime/strings/strings_impl.cpp (+7/-2)
src/store/api/collection.h (+1/-1)
src/store/api/iterator.h (+1/-1)
src/store/naive/atomic_items.cpp (+1/-1)
src/store/naive/atomic_items.h (+4/-1)
src/store/naive/collection.h (+1/-0)
src/store/naive/collection_tree_info.h (+1/-0)
src/store/naive/pul_primitives.cpp (+1/-1)
src/store/naive/simple_collection.cpp (+2/-2)
src/store/naive/simple_index_value.h (+1/-0)
src/store/naive/simple_lazy_temp_seq.cpp (+2/-2)
src/store/naive/simple_pul.cpp (+3/-6)
src/store/naive/simple_temp_seq.cpp (+1/-0)
src/system/globalenv.cpp (+1/-0)
src/types/casting.cpp (+33/-19)
src/types/schema/XercesParseUtils.cpp (+7/-4)
src/util/stl_util.h (+18/-0)
src/zorbaserialization/serialize_basic_types.cpp (+1/-0)
src/zorbaserialization/serialize_zorba_types.cpp (+15/-20)
src/zorbaserialization/serialize_zorba_types.h (+7/-18)
src/zorbatypes/CMakeLists.txt (+1/-0)
src/zorbatypes/datetime.h (+3/-4)
src/zorbatypes/datetime/datetimetype.cpp (+9/-8)
src/zorbatypes/datetime/duration.cpp (+8/-4)
src/zorbatypes/datetime/timezone.cpp (+1/-0)
src/zorbatypes/decimal.cpp (+63/-79)
src/zorbatypes/decimal.h (+24/-36)
src/zorbatypes/duration.h (+6/-6)
src/zorbatypes/floatimpl.cpp (+91/-116)
src/zorbatypes/floatimpl.h (+21/-36)
src/zorbatypes/integer.cpp (+253/-192)
src/zorbatypes/integer.h (+553/-483)
src/zorbatypes/numconversions.cpp (+8/-1)
src/zorbatypes/numconversions.h (+2/-0)
src/zorbatypes/numeric_types.cpp (+82/-0)
src/zorbatypes/numeric_types.h (+106/-0)
src/zorbatypes/schema_types.h (+26/-25)
src/zorbatypes/timezone.h (+1/-1)
src/zorbatypes/zorbatypes_decl.h (+1/-17)
test/fots/CMakeLists.txt (+2/-2)
To merge this branch: bzr merge lp:~paul-lucas/zorba/bug-1090089
Reviewer Review Type Date Requested Status
Matthias Brantner 2013-05-05 Approve on 2013-05-08
Paul J. Lucas Approve on 2013-04-25
Review via email: mp+160962@code.launchpad.net

Commit message

Completely reworked the implementation of Integer so that it now correctly handles xs:integer, xs:negativeInteger, xs:nonNegativeInteger, and xs:positiveInteger.

Also cleaned-up #includes for Zorba classes so as to reduce uncessary #includes.

This is an intermediate merge proposal just go get all of the above changes in. The actual fix for distinct-values() will come later depending on the outcome of the thread posted to zorba-dev.

Description of the change

Completely reworked the implementation of Integer so that it now correctly handles xs:integer, xs:negativeInteger, xs:nonNegativeInteger, and xs:positiveInteger.

Also cleaned-up #includes for Zorba classes so as to reduce uncessary #includes.

This is an intermediate merge proposal just go get all of the above changes in. The actual fix for distinct-values() will come later depending on the outcome of the thread posted to zorba-dev.

To post a comment you must log in.
Paul J. Lucas (paul-lucas) :
review: Approve
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug-1090089-2013-04-30T14-52-16.682Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug-1090089-2013-04-30T15-05-58.851Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug-1090089-2013-04-30T17-37-58.355Z is finished. The
  final status was:

  25 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug-1090089-2013-04-30T23-29-18.17Z is finished. The
  final status was:

  25 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug-1090089-2013-05-01T04-39-58.887Z is finished. The
  final status was:

  8 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug-1090089-2013-05-04T00-48-32.868Z is finished. The
  final status was:

  3 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug-1090089-2013-05-04T17-34-09.498Z is finished. The
  final status was:

  2 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug-1090089-2013-05-05T03-23-20.786Z is finished. The
  final status was:

  1 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1090089-2013-05-05T03-55-20.658Z is finished. The final status was:

All tests succeeded!

Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 1 Approve.

lp:~paul-lucas/zorba/bug-1090089 updated on 2013-05-08
11442. By Paul J. Lucas on 2013-05-06

Merge from trunk.

11443. By Paul J. Lucas on 2013-05-06

Cosmetic change.

11444. By Paul J. Lucas on 2013-05-07

Now always returning Integer for binary operators.

11445. By Paul J. Lucas on 2013-05-08

Merge from trunk.

11446. By Paul J. Lucas on 2013-05-08

Updated ChangeLog.

11447. By Paul J. Lucas on 2013-05-08

Undid change.

review: Approve
review: Approve
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1090089-2013-05-08T19-45-21.587Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2013-05-08 03:22:27 +0000
+++ ChangeLog 2013-05-08 15:05:31 +0000
@@ -1,5 +1,6 @@
1Zorba - The XQuery Processor1Zorba - The XQuery Processor
22
3
3version 2.94version 2.9
45
5New Features:6New Features:
67
=== modified file 'src/api/dynamiccontextimpl.cpp'
--- src/api/dynamiccontextimpl.cpp 2013-05-08 03:19:57 +0000
+++ src/api/dynamiccontextimpl.cpp 2013-05-08 15:05:31 +0000
@@ -27,6 +27,7 @@
27#include "types/typemanager.h"27#include "types/typemanager.h"
28#include "types/root_typemanager.h"28#include "types/root_typemanager.h"
29#include "types/schema/validate.h"29#include "types/schema/validate.h"
30#include "zorbatypes/integer.h"
3031
31#include "api/unmarshaller.h"32#include "api/unmarshaller.h"
32#include "api/zorbaimpl.h"33#include "api/zorbaimpl.h"
3334
=== modified file 'src/api/item.cpp'
--- src/api/item.cpp 2013-02-26 04:12:43 +0000
+++ src/api/item.cpp 2013-05-08 15:05:31 +0000
@@ -38,7 +38,9 @@
38#include "store/api/iterator.h"38#include "store/api/iterator.h"
39#include "store/api/collection.h"39#include "store/api/collection.h"
4040
41#include <zorbatypes/numconversions.h>41#include "zorbatypes/floatimpl.h"
42#include "zorbatypes/integer.h"
43#include "zorbatypes/numconversions.h"
4244
43namespace zorba {45namespace zorba {
4446
4547
=== modified file 'src/api/itemfactoryimpl.cpp'
--- src/api/itemfactoryimpl.cpp 2013-03-27 03:30:14 +0000
+++ src/api/itemfactoryimpl.cpp 2013-05-08 15:05:31 +0000
@@ -25,14 +25,17 @@
2525
26#include "api/itemfactoryimpl.h"26#include "api/itemfactoryimpl.h"
2727
28#include "zorbatypes/duration.h"28#include "zorbatypes/decimal.h"
29#include "zorbatypes/floatimpl.h"
30#include "zorbatypes/integer.h"
31#include "zorbatypes/schema_types.h"
2932
30#include "system/globalenv.h"33#include "system/globalenv.h"
3134
35#include "store/api/copymode.h"
36#include "store/api/item.h"
32#include "store/api/item_factory.h"37#include "store/api/item_factory.h"
33#include "store/api/store.h"38#include "store/api/store.h"
34#include "store/api/copymode.h"
35#include "store/api/item.h"
3639
37#include "api/unmarshaller.h"40#include "api/unmarshaller.h"
3841
3942
=== modified file 'src/api/serialization/serializer.cpp'
--- src/api/serialization/serializer.cpp 2013-04-25 02:05:20 +0000
+++ src/api/serialization/serializer.cpp 2013-05-08 15:05:31 +0000
@@ -39,6 +39,7 @@
3939
40#include "system/globalenv.h"40#include "system/globalenv.h"
41#include "zorbamisc/ns_consts.h"41#include "zorbamisc/ns_consts.h"
42#include "zorbatypes/integer.h"
42#include "zorbatypes/numconversions.h"43#include "zorbatypes/numconversions.h"
4344
44#include "store/api/iterator.h"45#include "store/api/iterator.h"
4546
=== modified file 'src/capi/csequence.cpp'
--- src/capi/csequence.cpp 2013-02-07 17:24:36 +0000
+++ src/capi/csequence.cpp 2013-05-08 15:05:31 +0000
@@ -18,16 +18,17 @@
18#include "capi/csequence.h"18#include "capi/csequence.h"
1919
20#include <cassert>20#include <cassert>
21#include <string.h>21#include <cstring>
2222
23#include <zorba/zorba.h>23#include <zorba/zorba.h>
24#include <zorba/diagnostic_list.h>24#include <zorba/diagnostic_list.h>
25#include <zorba/iterator.h>25#include <zorba/iterator.h>
26#include <zorba/store_consts.h>26#include <zorba/store_consts.h>
27#include <zorbamisc/ns_consts.h>
28#include <zorbatypes/numconversions.h>
2927
30#include "util/string_util.h"28#include "util/string_util.h"
29#include "zorbamisc/ns_consts.h"
30#include "zorbatypes/floatimpl.h"
31#include "zorbatypes/numconversions.h"
3132
32#include "error.h"33#include "error.h"
3334
3435
=== modified file 'src/common/shared_types.h'
--- src/common/shared_types.h 2013-04-26 04:44:36 +0000
+++ src/common/shared_types.h 2013-05-08 15:05:31 +0000
@@ -133,18 +133,20 @@
133typedef rchandle<GMonth> GMonth_t;133typedef rchandle<GMonth> GMonth_t;
134134
135/* numerics */135/* numerics */
136template<typename FloatType> class FloatImpl;136template<typename F> class FloatImpl;
137typedef FloatImpl<double> Double;137typedef FloatImpl<double> Double;
138typedef FloatImpl<float> Float;138typedef FloatImpl<float> Float;
139#ifdef ZORBA_WITH_BIG_INTEGER139class integer_traits;
140class IntegerImpl;140class negative_traits;
141typedef IntegerImpl Integer;141class nonNegative_traits;
142typedef IntegerImpl UInteger;142class nonPositive_traits;
143#else143class positive_traits;
144template<typename IntType> class IntegerImpl;144template<class T> class IntegerImpl;
145typedef IntegerImpl<long long> Integer;145typedef IntegerImpl<integer_traits> Integer;
146typedef IntegerImpl<unsigned long long> UInteger;146typedef IntegerImpl<negative_traits> NegativeInteger;
147#endif /* ZORBA_WITH_BIG_INTEGER */147typedef IntegerImpl<nonNegative_traits> NonNegativeInteger;
148typedef IntegerImpl<nonPositive_traits> NonPositiveInteger;
149typedef IntegerImpl<positive_traits> PositiveInteger;
148150
149/* api */151/* api */
150class serializer;152class serializer;
151153
=== modified file 'src/compiler/expression/expr.cpp'
--- src/compiler/expression/expr.cpp 2013-03-07 10:10:10 +0000
+++ src/compiler/expression/expr.cpp 2013-05-08 15:05:31 +0000
@@ -49,6 +49,9 @@
4949
50#include "store/api/store.h"50#include "store/api/store.h"
51#include "store/api/item_factory.h"51#include "store/api/item_factory.h"
52#include "zorbatypes/decimal.h"
53#include "zorbatypes/floatimpl.h"
54#include "zorbatypes/integer.h"
5255
5356
54namespace zorba57namespace zorba
5558
=== modified file 'src/compiler/expression/expr_manager.cpp'
--- src/compiler/expression/expr_manager.cpp 2013-04-16 20:06:08 +0000
+++ src/compiler/expression/expr_manager.cpp 2013-05-08 15:05:31 +0000
@@ -15,22 +15,24 @@
15 */15 */
1616
17#include "stdafx.h"17#include "stdafx.h"
18
19#include "zorbatypes/decimal.h"
20#include "zorbatypes/integer.h"
21
22#include "expr.h"
18#include "expr_manager.h"23#include "expr_manager.h"
19
20#include "mem_manager.h"
21
22#include "expr.h"
23#include "ftnode.h"
24#include "var_expr.h"
25#include "flwor_expr.h"24#include "flwor_expr.h"
26#include "fo_expr.h"25#include "fo_expr.h"
27#include "ft_expr.h"26#include "ft_expr.h"
27#include "ftnode.h"
28#include "function_item_expr.h"28#include "function_item_expr.h"
29#include "json_exprs.h"
30#include "mem_manager.h"
29#include "path_expr.h"31#include "path_expr.h"
32#include "pragma.h"
30#include "script_exprs.h"33#include "script_exprs.h"
31#include "update_exprs.h"34#include "update_exprs.h"
32#include "json_exprs.h"35#include "var_expr.h"
33#include "pragma.h"
3436
35namespace zorba37namespace zorba
36{38{
3739
=== modified file 'src/compiler/parser/jsoniq_parser.cpp'
--- src/compiler/parser/jsoniq_parser.cpp 2013-04-24 17:26:02 +0000
+++ src/compiler/parser/jsoniq_parser.cpp 2013-05-08 15:05:31 +0000
@@ -50,14 +50,13 @@
50#pragma warning(disable: 4786)50#pragma warning(disable: 4786)
51#endif51#endif
5252
53#include "compiler/api/compilercb.h"
54#include "compiler/parser/parse_constants.h"
55#include "compiler/parser/parser_helpers.h"
56#include "compiler/parser/xquery_driver.h"
53#include "compiler/parsetree/parsenodes.h"57#include "compiler/parsetree/parsenodes.h"
54#include "compiler/parser/parse_constants.h"
55#include "compiler/api/compilercb.h"
56#include "store/api/update_consts.h"58#include "store/api/update_consts.h"
5759#include "zorbatypes/integer.h"
58#include "compiler/parser/xquery_driver.h"
59
60#include "compiler/parser/parser_helpers.h"
6160
62#define SYMTAB( n ) driver.symtab.get( (off_t)n )61#define SYMTAB( n ) driver.symtab.get( (off_t)n )
63#define SYMTAB_PUT( s ) driver.symtab.put( s )62#define SYMTAB_PUT( s ) driver.symtab.put( s )
6463
=== modified file 'src/compiler/parser/parser_helpers.h'
--- src/compiler/parser/parser_helpers.h 2013-03-16 00:58:28 +0000
+++ src/compiler/parser/parser_helpers.h 2013-05-08 15:05:31 +0000
@@ -23,6 +23,8 @@
2323
24namespace zorba {24namespace zorba {
2525
26 class location;
27
26 namespace parser {28 namespace parser {
2729
28 extern const char *the_tumbling, *the_sliding, *the_start, *the_end, *the_only_end, *the_declare, *the_create;30 extern const char *the_tumbling, *the_sliding, *the_start, *the_end, *the_only_end, *the_declare, *the_create;
2931
=== modified file 'src/compiler/parser/parser_y_includes.h'
--- src/compiler/parser/parser_y_includes.h 2013-04-17 18:08:27 +0000
+++ src/compiler/parser/parser_y_includes.h 2013-05-08 15:05:31 +0000
@@ -60,14 +60,14 @@
60#pragma warning(disable: 4786)60#pragma warning(disable: 4786)
61#endif61#endif
6262
63#include "compiler/parsetree/parsenodes.h"63#include "compiler/api/compilercb.h"
64#include "compiler/parser/parse_constants.h"64#include "compiler/parser/parse_constants.h"
65#include "compiler/api/compilercb.h"65#include "compiler/parser/parser_helpers.h"
66#include "compiler/parser/xquery_driver.h"
67#include "compiler/parsetree/parsenodes.h"
66#include "store/api/update_consts.h"68#include "store/api/update_consts.h"
6769#include "zorbatypes/decimal.h"
68#include "compiler/parser/xquery_driver.h"70#include "zorbatypes/integer.h"
69
70#include "compiler/parser/parser_helpers.h"
7171
72#define SYMTAB( n ) driver.symtab.get( (off_t)n )72#define SYMTAB( n ) driver.symtab.get( (off_t)n )
73#define SYMTAB_PUT( s ) driver.symtab.put( s )73#define SYMTAB_PUT( s ) driver.symtab.put( s )
7474
=== modified file 'src/compiler/parser/symbol_table.cpp'
--- src/compiler/parser/symbol_table.cpp 2013-03-25 19:47:18 +0000
+++ src/compiler/parser/symbol_table.cpp 2013-05-08 15:05:31 +0000
@@ -15,6 +15,9 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include "zorbatypes/decimal.h"
19#include "zorbatypes/floatimpl.h"
20#include "zorbatypes/integer.h"
18#include "zorbatypes/numconversions.h"21#include "zorbatypes/numconversions.h"
1922
20#include "compiler/parser/symbol_table.h"23#include "compiler/parser/symbol_table.h"
2124
=== modified file 'src/compiler/parser/xquery_parser.cpp'
--- src/compiler/parser/xquery_parser.cpp 2013-04-24 17:26:02 +0000
+++ src/compiler/parser/xquery_parser.cpp 2013-05-08 15:05:31 +0000
@@ -50,14 +50,13 @@
50#pragma warning(disable: 4786)50#pragma warning(disable: 4786)
51#endif51#endif
5252
53#include "compiler/api/compilercb.h"
54#include "compiler/parser/parse_constants.h"
55#include "compiler/parser/parser_helpers.h"
56#include "compiler/parser/xquery_driver.h"
53#include "compiler/parsetree/parsenodes.h"57#include "compiler/parsetree/parsenodes.h"
54#include "compiler/parser/parse_constants.h"
55#include "compiler/api/compilercb.h"
56#include "store/api/update_consts.h"58#include "store/api/update_consts.h"
5759#include "zorbatypes/integer.h"
58#include "compiler/parser/xquery_driver.h"
59
60#include "compiler/parser/parser_helpers.h"
6160
62#define SYMTAB( n ) driver.symtab.get( (off_t)n )61#define SYMTAB( n ) driver.symtab.get( (off_t)n )
63#define SYMTAB_PUT( s ) driver.symtab.put( s )62#define SYMTAB_PUT( s ) driver.symtab.put( s )
6463
=== modified file 'src/compiler/parsetree/parsenode_print_xml_visitor.cpp'
--- src/compiler/parsetree/parsenode_print_xml_visitor.cpp 2013-03-22 00:38:18 +0000
+++ src/compiler/parsetree/parsenode_print_xml_visitor.cpp 2013-05-08 15:05:31 +0000
@@ -16,9 +16,12 @@
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include <ostream>18#include <ostream>
19#include "compiler/parsetree/parsenode_print_xml_visitor.h"19
20#include "compiler/parsetree/parsenode_visitor.h"
21#include "types/typemanager.h"20#include "types/typemanager.h"
21#include "zorbatypes/integer.h"
22
23#include "parsenode_print_xml_visitor.h"
24#include "parsenode_visitor.h"
2225
23using namespace std;26using namespace std;
2427
2528
=== modified file 'src/compiler/parsetree/parsenodes.cpp'
--- src/compiler/parsetree/parsenodes.cpp 2013-04-17 22:41:05 +0000
+++ src/compiler/parsetree/parsenodes.cpp 2013-05-08 15:05:31 +0000
@@ -29,6 +29,7 @@
29#include "compiler/parsetree/parsenodes.h"29#include "compiler/parsetree/parsenodes.h"
30#include "compiler/parser/parse_constants.h"30#include "compiler/parser/parse_constants.h"
31#include "compiler/parsetree/parsenode_visitor.h"31#include "compiler/parsetree/parsenode_visitor.h"
32#include "zorbatypes/integer.h"
3233
33#include <iostream>34#include <iostream>
34#include <sstream>35#include <sstream>
3536
=== modified file 'src/compiler/parsetree/parsenodes.h'
--- src/compiler/parsetree/parsenodes.h 2013-05-08 03:19:57 +0000
+++ src/compiler/parsetree/parsenodes.h 2013-05-08 15:05:31 +0000
@@ -32,6 +32,9 @@
3232
33#include "store/api/item.h"33#include "store/api/item.h"
3434
35#include "zorbatypes/decimal.h"
36#include "zorbatypes/integer.h"
37#include "zorbatypes/floatimpl.h"
35#include "zorbatypes/rchandle.h"38#include "zorbatypes/rchandle.h"
36#include "zorbatypes/schema_types.h"39#include "zorbatypes/schema_types.h"
37#include "zorbatypes/zstring.h"40#include "zorbatypes/zstring.h"
3841
=== modified file 'src/compiler/rewriter/rules/flwor_rules.cpp'
--- src/compiler/rewriter/rules/flwor_rules.cpp 2013-04-15 12:07:41 +0000
+++ src/compiler/rewriter/rules/flwor_rules.cpp 2013-05-08 15:05:31 +0000
@@ -37,6 +37,8 @@
3737
38#include "system/properties.h"38#include "system/properties.h"
3939
40#include "zorbatypes/integer.h"
41
40#include <memory>42#include <memory>
41#include <iterator>43#include <iterator>
4244
@@ -300,7 +302,7 @@
300 if (pvar != NULL)302 if (pvar != NULL)
301 {303 {
302 expr* constExpr = rCtx.theEM->304 expr* constExpr = rCtx.theEM->
303 create_const_expr(sctx, udf, loc, xs_integer::zero());305 create_const_expr(sctx, udf, loc, numeric_consts<xs_integer>::zero());
304306
305 subst_vars(rCtx, pvar, constExpr, 2);307 subst_vars(rCtx, pvar, constExpr, 2);
306 fc->set_pos_var(NULL);308 fc->set_pos_var(NULL);
@@ -318,7 +320,7 @@
318 if (pvar != NULL && (domQuant == TypeConstants::QUANT_ONE || ! outerFor))320 if (pvar != NULL && (domQuant == TypeConstants::QUANT_ONE || ! outerFor))
319 {321 {
320 expr* constExpr = rCtx.theEM->322 expr* constExpr = rCtx.theEM->
321 create_const_expr(sctx, udf, loc, xs_integer::one());323 create_const_expr(sctx, udf, loc, numeric_consts<xs_integer>::one());
322324
323 subst_vars(rCtx, pvar, constExpr, 2);325 subst_vars(rCtx, pvar, constExpr, 2);
324 fc->set_pos_var(NULL);326 fc->set_pos_var(NULL);
@@ -461,7 +463,7 @@
461 // since one value is still returned, count variables are changed to 1463 // since one value is still returned, count variables are changed to 1
462 subst_vars(rCtx,464 subst_vars(rCtx,
463 static_cast<count_clause*>(clause)->get_var(),465 static_cast<count_clause*>(clause)->get_var(),
464 rCtx.theEM->create_const_expr(sctx, udf, loc, xs_integer::one()),466 rCtx.theEM->create_const_expr(sctx, udf, loc, numeric_consts<xs_integer>::one()),
465 2);467 2);
466468
467 theFlwor->remove_clause(0);469 theFlwor->remove_clause(0);
468470
=== modified file 'src/compiler/rewriter/rules/fold_rules.cpp'
--- src/compiler/rewriter/rules/fold_rules.cpp 2013-05-04 20:20:05 +0000
+++ src/compiler/rewriter/rules/fold_rules.cpp 2013-05-08 15:05:31 +0000
@@ -47,6 +47,8 @@
47#include "store/api/store.h"47#include "store/api/store.h"
48#include "store/api/item_factory.h"48#include "store/api/item_factory.h"
4949
50#include "zorbatypes/integer.h"
51
50#include <iterator>52#include <iterator>
5153
52namespace zorba {54namespace zorba {
5355
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2013-05-08 08:01:05 +0000
+++ src/compiler/translator/translator.cpp 2013-05-08 15:05:31 +0000
@@ -88,9 +88,12 @@
88#include "types/typemanagerimpl.h"88#include "types/typemanagerimpl.h"
89#include "types/schema/schema.h"89#include "types/schema/schema.h"
9090
91#include "zorbamisc/ns_consts.h"
92#include "zorbatypes/decimal.h"
93#include "zorbatypes/floatimpl.h"
94#include "zorbatypes/integer.h"
95#include "zorbatypes/numconversions.h"
91#include "zorbatypes/URI.h"96#include "zorbatypes/URI.h"
92#include "zorbatypes/numconversions.h"
93#include "zorbamisc/ns_consts.h"
9497
95#ifdef ZORBA_WITH_DEBUGGER98#ifdef ZORBA_WITH_DEBUGGER
96#include "debugger/debugger_commons.h"99#include "debugger/debugger_commons.h"
@@ -11932,8 +11935,8 @@
11932 }11935 }
11933 case FunctionConsts::FN_HEAD_1:11936 case FunctionConsts::FN_HEAD_1:
11934 {11937 {
11935 arguments.push_back(CREATE(const)(theRootSctx, theUDF, loc, xs_integer::one()));11938 arguments.push_back(CREATE(const)(theRootSctx, theUDF, loc, numeric_consts<xs_integer>::one()));
11936 arguments.push_back(CREATE(const)(theRootSctx, theUDF, loc, xs_integer::one()));11939 arguments.push_back(CREATE(const)(theRootSctx, theUDF, loc, numeric_consts<xs_integer>::one()));
1193711940
11938 function* f = BUILTIN_FUNC(OP_ZORBA_SUBSEQUENCE_INT_3);11941 function* f = BUILTIN_FUNC(OP_ZORBA_SUBSEQUENCE_INT_3);
1193911942
1194011943
=== modified file 'src/functions/udf.cpp'
--- src/functions/udf.cpp 2013-04-24 01:35:58 +0000
+++ src/functions/udf.cpp 2013-05-08 15:05:31 +0000
@@ -36,6 +36,7 @@
36#include "diagnostics/assert.h"36#include "diagnostics/assert.h"
3737
38#include "types/typeops.h"38#include "types/typeops.h"
39#include "zorbatypes/integer.h"
3940
40#include "zorbaserialization/serialize_template_types.h"41#include "zorbaserialization/serialize_template_types.h"
41#include "zorbaserialization/serialize_zorba_types.h"42#include "zorbaserialization/serialize_zorba_types.h"
4243
=== modified file 'src/runtime/base/plan_iterator.cpp'
--- src/runtime/base/plan_iterator.cpp 2013-03-24 20:40:03 +0000
+++ src/runtime/base/plan_iterator.cpp 2013-05-08 15:05:31 +0000
@@ -15,18 +15,14 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include "compiler/api/compilercb.h"
18#include "context/static_context.h"19#include "context/static_context.h"
19
20#include "compiler/api/compilercb.h"
21
22#include "runtime/base/plan_iterator.h"20#include "runtime/base/plan_iterator.h"
23
24#include "runtime/util/flowctl_exception.h"21#include "runtime/util/flowctl_exception.h"
2522#include "store/api/item_factory.h"
23#include "store/api/store.h"
26#include "system/globalenv.h"24#include "system/globalenv.h"
2725#include "zorbatypes/integer.h"
28#include "store/api/store.h"
29#include "store/api/item_factory.h"
3026
3127
32namespace zorba28namespace zorba
3329
=== modified file 'src/runtime/booleans/BooleanImpl.cpp'
--- src/runtime/booleans/BooleanImpl.cpp 2013-05-02 00:18:56 +0000
+++ src/runtime/booleans/BooleanImpl.cpp 2013-05-08 15:05:31 +0000
@@ -20,6 +20,7 @@
2020
21#include "zorbatypes/collation_manager.h"21#include "zorbatypes/collation_manager.h"
22#include "zorbatypes/datetime.h"22#include "zorbatypes/datetime.h"
23#include "zorbatypes/integer.h"
2324
24#include "system/globalenv.h"25#include "system/globalenv.h"
2526
2627
=== modified file 'src/runtime/collections/collections_base.h'
--- src/runtime/collections/collections_base.h 2013-02-07 17:24:36 +0000
+++ src/runtime/collections/collections_base.h 2013-05-08 15:05:31 +0000
@@ -31,6 +31,7 @@
31#include "types/typeimpl.h"31#include "types/typeimpl.h"
3232
33#include "diagnostics/util_macros.h"33#include "diagnostics/util_macros.h"
34#include "zorbatypes/integer.h"
3435
3536
36namespace zorba {37namespace zorba {
3738
=== modified file 'src/runtime/collections/collections_impl.cpp'
--- src/runtime/collections/collections_impl.cpp 2013-03-24 20:40:03 +0000
+++ src/runtime/collections/collections_impl.cpp 2013-05-08 15:05:31 +0000
@@ -307,9 +307,9 @@
307 lSkip = lSkipItem->getIntegerValue(); 307 lSkip = lSkipItem->getIntegerValue();
308308
309 // negative skip is not allowed309 // negative skip is not allowed
310 if (lSkip < xs_integer::zero())310 if (lSkip.sign() < 0)
311 {311 {
312 lSkip = xs_integer::zero();312 lSkip = numeric_consts<xs_integer>::zero();
313 }313 }
314314
315 if (!lRefPassed)315 if (!lRefPassed)
@@ -381,11 +381,10 @@
381 // skip parameter passed381 // skip parameter passed
382 store::Item_t skipItem;382 store::Item_t skipItem;
383 consumeNext(skipItem, theChildren[1].getp(), planState);383 consumeNext(skipItem, theChildren[1].getp(), planState);
384 xs_integer skip = skipItem->getIntegerValue(); 384 xs_integer skip( skipItem->getIntegerValue() );
385385
386 count -= (skip <= xs_integer::zero() ? xs_integer::zero() : skip);386 count -= (skip.sign() <= 0 ? numeric_consts<xs_integer>::zero() : skip);
387387 count = (count.sign() < 0 ? numeric_consts<xs_integer>::zero() : count);
388 count = (count < xs_integer::zero() ? xs_integer::zero() : count);
389 }388 }
390389
391 STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, count), state);390 STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, count), state);
392391
=== modified file 'src/runtime/core/arithmetic_impl.cpp'
--- src/runtime/core/arithmetic_impl.cpp 2013-04-08 21:32:54 +0000
+++ src/runtime/core/arithmetic_impl.cpp 2013-05-08 15:05:31 +0000
@@ -21,6 +21,7 @@
21#include "diagnostics/util_macros.h"21#include "diagnostics/util_macros.h"
2222
23#include "zorbatypes/datetime.h"23#include "zorbatypes/datetime.h"
24#include "zorbatypes/decimal.h"
24#include "zorbatypes/duration.h"25#include "zorbatypes/duration.h"
2526
26#include "system/globalenv.h"27#include "system/globalenv.h"
2728
=== modified file 'src/runtime/core/var_iterators.h'
--- src/runtime/core/var_iterators.h 2013-05-08 08:01:05 +0000
+++ src/runtime/core/var_iterators.h 2013-05-08 15:05:31 +0000
@@ -23,7 +23,7 @@
23#include "runtime/base/unarybase.h"23#include "runtime/base/unarybase.h"
24#include "runtime/base/narybase.h"24#include "runtime/base/narybase.h"
2525
26#include "zorbatypes/schema_types.h"26#include "zorbatypes/integer.h"
2727
2828
29namespace zorba29namespace zorba
3030
=== modified file 'src/runtime/durations_dates_times/durations_dates_times_impl.cpp'
--- src/runtime/durations_dates_times/durations_dates_times_impl.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/durations_dates_times/durations_dates_times_impl.cpp 2013-05-08 15:05:31 +0000
@@ -17,6 +17,8 @@
1717
18#include "zorbatypes/datetime.h"18#include "zorbatypes/datetime.h"
19#include "zorbatypes/duration.h"19#include "zorbatypes/duration.h"
20#include "zorbatypes/decimal.h"
21#include "zorbatypes/integer.h"
20#include "zorbatypes/numconversions.h"22#include "zorbatypes/numconversions.h"
21#include "zorbatypes/datetime/parse.h"23#include "zorbatypes/datetime/parse.h"
2224
2325
=== modified file 'src/runtime/full_text/ft_module_impl.cpp'
--- src/runtime/full_text/ft_module_impl.cpp 2013-04-16 22:12:03 +0000
+++ src/runtime/full_text/ft_module_impl.cpp 2013-05-08 15:05:31 +0000
@@ -46,6 +46,7 @@
46#include "types/typeops.h"46#include "types/typeops.h"
47#include "util/stl_util.h"47#include "util/stl_util.h"
48#include "util/utf8_util.h"48#include "util/utf8_util.h"
49#include "zorbatypes/integer.h"
49#include "zorbatypes/URI.h"50#include "zorbatypes/URI.h"
50#include "zorbautils/locale.h"51#include "zorbautils/locale.h"
5152
5253
=== modified file 'src/runtime/full_text/ft_util.cpp'
--- src/runtime/full_text/ft_util.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/ft_util.cpp 2013-05-08 15:05:31 +0000
@@ -20,6 +20,7 @@
2020
21#include "diagnostics/xquery_diagnostics.h"21#include "diagnostics/xquery_diagnostics.h"
22#include "zorbamisc/ns_consts.h"22#include "zorbamisc/ns_consts.h"
23#include "zorbatypes/integer.h"
23#include "zorbatypes/numconversions.h"24#include "zorbatypes/numconversions.h"
24#include "zorbautils/locale.h"25#include "zorbautils/locale.h"
2526
2627
=== modified file 'src/runtime/full_text/ftcontains_visitor.cpp'
--- src/runtime/full_text/ftcontains_visitor.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/ftcontains_visitor.cpp 2013-05-08 15:05:31 +0000
@@ -24,12 +24,11 @@
24#include "compiler/parser/query_loc.h"24#include "compiler/parser/query_loc.h"
25#include "diagnostics/xquery_diagnostics.h"25#include "diagnostics/xquery_diagnostics.h"
26#include "store/api/store.h"26#include "store/api/store.h"
27
28#include "system/globalenv.h"27#include "system/globalenv.h"
29
30#include "util/cxx_util.h"28#include "util/cxx_util.h"
31#include "util/indent.h"29#include "util/indent.h"
32#include "util/stl_util.h"30#include "util/stl_util.h"
31#include "zorbatypes/integer.h"
3332
34#ifndef NDEBUG33#ifndef NDEBUG
35#include "system/properties.h"34#include "system/properties.h"
3635
=== modified file 'src/runtime/hof/dynamic_fncall_iterator.cpp'
--- src/runtime/hof/dynamic_fncall_iterator.cpp 2013-05-05 04:49:50 +0000
+++ src/runtime/hof/dynamic_fncall_iterator.cpp 2013-05-08 15:05:31 +0000
@@ -34,6 +34,7 @@
34#include "types/root_typemanager.h"34#include "types/root_typemanager.h"
35#include "types/casting.h"35#include "types/casting.h"
36#include "types/typeops.h"36#include "types/typeops.h"
37#include "zorbatypes/integer.h"
3738
38#include "system/globalenv.h"39#include "system/globalenv.h"
3940
4041
=== modified file 'src/runtime/hof/fn_hof_functions_impl.cpp'
--- src/runtime/hof/fn_hof_functions_impl.cpp 2013-04-24 01:35:58 +0000
+++ src/runtime/hof/fn_hof_functions_impl.cpp 2013-05-08 15:05:31 +0000
@@ -42,6 +42,7 @@
42#include "system/globalenv.h"42#include "system/globalenv.h"
4343
44#include "zorbamisc/ns_consts.h"44#include "zorbamisc/ns_consts.h"
45#include "zorbatypes/integer.h"
4546
4647
47#include "compiler/expression/expr_manager.h"48#include "compiler/expression/expr_manager.h"
4849
=== modified file 'src/runtime/indexing/index_ddl.cpp'
--- src/runtime/indexing/index_ddl.cpp 2013-03-24 20:40:03 +0000
+++ src/runtime/indexing/index_ddl.cpp 2013-05-08 15:05:31 +0000
@@ -34,6 +34,8 @@
34#include "types/typeimpl.h"34#include "types/typeimpl.h"
35#include "types/typeops.h"35#include "types/typeops.h"
36#include "types/casting.h"36#include "types/casting.h"
37#include "zorbatypes/decimal.h"
38#include "zorbatypes/integer.h"
3739
38#include "context/static_context.h"40#include "context/static_context.h"
39#include "context/dynamic_context.h"41#include "context/dynamic_context.h"
@@ -623,7 +625,7 @@
623 PlanState& planState) const625 PlanState& planState) const
624{626{
625 store::IndexCondition_t cond;627 store::IndexCondition_t cond;
626 xs_integer skip = xs_integer::zero();628 xs_integer skip( numeric_consts<xs_integer>::zero() );
627629
628 try630 try
629 {631 {
@@ -641,8 +643,8 @@
641 store::Item_t skipItem;643 store::Item_t skipItem;
642 ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState));644 ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState));
643 skip = skipItem->getIntegerValue();645 skip = skipItem->getIntegerValue();
644 if (skip < xs_integer::zero())646 if (skip.sign() < 0)
645 skip = xs_integer::zero();647 skip = numeric_consts<xs_integer>::zero();
646 }648 }
647649
648 state->theIterator->init(cond, skip);650 state->theIterator->init(cond, skip);
@@ -687,8 +689,8 @@
687 store::Item_t skipItem;689 store::Item_t skipItem;
688 ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState));690 ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState));
689 skip = skipItem->getIntegerValue();691 skip = skipItem->getIntegerValue();
690 if (skip < xs_integer::zero())692 if (skip.sign() < 0)
691 skip = xs_integer::zero();693 skip = numeric_consts<xs_integer>::zero();
692 }694 }
693695
694 state->theIterator->init(cond, skip);696 state->theIterator->init(cond, skip);
@@ -1071,7 +1073,7 @@
1071 PlanState& planState) const1073 PlanState& planState) const
1072{1074{
1073 store::IndexCondition_t cond;1075 store::IndexCondition_t cond;
1074 xs_integer skip = xs_integer::zero();1076 xs_integer skip( numeric_consts<xs_integer>::zero() );
10751077
1076 try1078 try
1077 {1079 {
@@ -1087,8 +1089,8 @@
1087 store::Item_t skipItem;1089 store::Item_t skipItem;
1088 ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState));1090 ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState));
1089 skip = skipItem->getIntegerValue();1091 skip = skipItem->getIntegerValue();
1090 if (skip < xs_integer::zero())1092 if (skip.sign() < 0)
1091 skip = xs_integer::zero();1093 skip = numeric_consts<xs_integer>::zero();
1092 }1094 }
10931095
1094 state->theIterator->init(cond, skip);1096 state->theIterator->init(cond, skip);
@@ -1114,7 +1116,7 @@
1114 PlanState& planState) const1116 PlanState& planState) const
1115{1117{
1116 store::IndexCondition_t cond;1118 store::IndexCondition_t cond;
1117 xs_integer skip = xs_integer::zero();1119 xs_integer skip( numeric_consts<xs_integer>::zero() );
11181120
1119 try1121 try
1120 {1122 {
@@ -1130,8 +1132,8 @@
1130 store::Item_t skipItem;1132 store::Item_t skipItem;
1131 ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState));1133 ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState));
1132 skip = skipItem->getIntegerValue();1134 skip = skipItem->getIntegerValue();
1133 if (skip < xs_integer::zero())1135 if (skip.sign() < 0)
1134 skip = xs_integer::zero();1136 skip = numeric_consts<xs_integer>::zero();
1135 }1137 }
11361138
1137 state->theIterator->init(cond, skip);1139 state->theIterator->init(cond, skip);
11381140
=== modified file 'src/runtime/introspection/sctx_impl.cpp'
--- src/runtime/introspection/sctx_impl.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/introspection/sctx_impl.cpp 2013-05-08 15:05:31 +0000
@@ -19,6 +19,7 @@
1919
20#include "diagnostics/assert.h"20#include "diagnostics/assert.h"
21#include "diagnostics/xquery_diagnostics.h"21#include "diagnostics/xquery_diagnostics.h"
22#include "zorbatypes/integer.h"
22#include "zorbatypes/numconversions.h"23#include "zorbatypes/numconversions.h"
2324
24#include "system/globalenv.h"25#include "system/globalenv.h"
2526
=== modified file 'src/runtime/item/item_impl.cpp'
--- src/runtime/item/item_impl.cpp 2012-07-17 18:47:54 +0000
+++ src/runtime/item/item_impl.cpp 2013-05-08 15:05:31 +0000
@@ -25,6 +25,7 @@
25#include "store/api/store.h"25#include "store/api/store.h"
2626
27#include "util/mem_sizeof.h"27#include "util/mem_sizeof.h"
28#include "zorbatypes/integer.h"
2829
29using namespace std;30using namespace std;
3031
3132
=== modified file 'src/runtime/json/jsoniq_functions_impl.cpp'
--- src/runtime/json/jsoniq_functions_impl.cpp 2013-05-05 04:49:50 +0000
+++ src/runtime/json/jsoniq_functions_impl.cpp 2013-05-08 15:05:31 +0000
@@ -46,6 +46,7 @@
46#include "types/typeimpl.h"46#include "types/typeimpl.h"
47#include "types/typeops.h"47#include "types/typeops.h"
48#include "types/root_typemanager.h"48#include "types/root_typemanager.h"
49#include "zorbatypes/integer.h"
4950
50#include <runtime/util/doc_uri_heuristics.h>51#include <runtime/util/doc_uri_heuristics.h>
5152
5253
=== modified file 'src/runtime/maths/pregenerated/maths.cpp'
--- src/runtime/maths/pregenerated/maths.cpp 2013-03-05 23:11:50 +0000
+++ src/runtime/maths/pregenerated/maths.cpp 2013-05-08 15:05:31 +0000
@@ -640,12 +640,12 @@
640640
641void ModfIteratorState::init(PlanState& planState) {641void ModfIteratorState::init(PlanState& planState) {
642 PlanIteratorState::init(planState);642 PlanIteratorState::init(planState);
643 theDoubInteger = xs_double::zero();643 theDoubInteger = numeric_consts<xs_double>::zero();
644}644}
645645
646void ModfIteratorState::reset(PlanState& planState) {646void ModfIteratorState::reset(PlanState& planState) {
647 PlanIteratorState::reset(planState);647 PlanIteratorState::reset(planState);
648 theDoubInteger = xs_double::zero();648 theDoubInteger = numeric_consts<xs_double>::zero();
649}649}
650// </ModfIterator>650// </ModfIterator>
651651
@@ -678,12 +678,12 @@
678678
679void FrexpIteratorState::init(PlanState& planState) {679void FrexpIteratorState::init(PlanState& planState) {
680 PlanIteratorState::init(planState);680 PlanIteratorState::init(planState);
681 theIntExponent = xs_integer::zero();681 theIntExponent = numeric_consts<xs_integer>::zero();
682}682}
683683
684void FrexpIteratorState::reset(PlanState& planState) {684void FrexpIteratorState::reset(PlanState& planState) {
685 PlanIteratorState::reset(planState);685 PlanIteratorState::reset(planState);
686 theIntExponent = xs_integer::zero();686 theIntExponent = numeric_consts<xs_integer>::zero();
687}687}
688// </FrexpIterator>688// </FrexpIterator>
689689
690690
=== modified file 'src/runtime/maths/pregenerated/maths.h'
--- src/runtime/maths/pregenerated/maths.h 2013-03-05 23:11:50 +0000
+++ src/runtime/maths/pregenerated/maths.h 2013-05-08 15:05:31 +0000
@@ -29,6 +29,7 @@
29#include "runtime/base/binarybase.h"29#include "runtime/base/binarybase.h"
30#include "runtime/base/noarybase.h"30#include "runtime/base/noarybase.h"
3131
32#include "zorbatypes/integer.h"
32#include "zorbatypes/schema_types.h"33#include "zorbatypes/schema_types.h"
3334
3435
3536
=== modified file 'src/runtime/numerics/NumericsImpl.cpp'
--- src/runtime/numerics/NumericsImpl.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/numerics/NumericsImpl.cpp 2013-05-08 15:05:31 +0000
@@ -20,6 +20,8 @@
20#include "diagnostics/assert.h"20#include "diagnostics/assert.h"
21#include "diagnostics/util_macros.h"21#include "diagnostics/util_macros.h"
22#include "diagnostics/xquery_diagnostics.h"22#include "diagnostics/xquery_diagnostics.h"
23#include "zorbatypes/decimal.h"
24#include "zorbatypes/integer.h"
23#include "zorbatypes/zorbatypes_decl.h"25#include "zorbatypes/zorbatypes_decl.h"
2426
25#include "system/globalenv.h"27#include "system/globalenv.h"
@@ -393,7 +395,7 @@
393{395{
394 xs_decimal ld0 = i0->getDecimalValue();396 xs_decimal ld0 = i0->getDecimalValue();
395 xs_decimal ld1 = i1->getDecimalValue();397 xs_decimal ld1 = i1->getDecimalValue();
396 if ( ld1 == Integer::zero() )398 if ( ld1.sign() == 0 )
397 {399 {
398 throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );400 throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
399 }401 }
@@ -412,7 +414,7 @@
412{414{
413 xs_decimal const ll0(i0->getIntegerValue());415 xs_decimal const ll0(i0->getIntegerValue());
414 xs_decimal const ll1(i1->getIntegerValue());416 xs_decimal const ll1(i1->getIntegerValue());
415 if ( ll1 == Integer::zero() )417 if ( ll1.sign() == 0 )
416 {418 {
417 throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );419 throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
418 }420 }
@@ -435,7 +437,7 @@
435 xs_double d0 = i0->getDoubleValue();437 xs_double d0 = i0->getDoubleValue();
436 xs_double d1 = i1->getDoubleValue();438 xs_double d1 = i1->getDoubleValue();
437439
438 if ( d1 == xs_double::zero() )440 if ( d1 == numeric_consts<xs_double>::zero() )
439 {441 {
440 throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );442 throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
441 }443 }
@@ -455,7 +457,7 @@
455457
456 if (i0->isPosOrNegInf()) {458 if (i0->isPosOrNegInf()) {
457 // idiv with +-INF divisor has 0 as result459 // idiv with +-INF divisor has 0 as result
458 return GENV_ITEMFACTORY->createInteger(result, Integer::zero());460 return GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero());
459 }461 }
460462
461 xs_integer const lInteger( d0 / d1 );463 xs_integer const lInteger( d0 / d1 );
@@ -474,7 +476,7 @@
474{476{
475 xs_float f0 = i0->getFloatValue();477 xs_float f0 = i0->getFloatValue();
476 xs_float f1 = i1->getFloatValue();478 xs_float f1 = i1->getFloatValue();
477 if ( f1 == xs_float::zero() )479 if ( f1 == numeric_consts<xs_float>::zero() )
478 {480 {
479 throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );481 throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
480 }482 }
@@ -494,7 +496,7 @@
494 if (i0->isPosOrNegInf()) 496 if (i0->isPosOrNegInf())
495 {497 {
496 // idiv with +-INF divisor has 0 as result498 // idiv with +-INF divisor has 0 as result
497 return GENV_ITEMFACTORY->createInteger(result, Integer::zero());499 return GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero());
498 }500 }
499501
500 xs_integer const lInteger( f0 / f1 );502 xs_integer const lInteger( f0 / f1 );
@@ -606,7 +608,7 @@
606 xs_integer ll0 = i0->getIntegerValue();608 xs_integer ll0 = i0->getIntegerValue();
607 xs_integer ll1 = i1->getIntegerValue();609 xs_integer ll1 = i1->getIntegerValue();
608610
609 if (ll1 == Integer::zero())611 if ( ll1.sign() == 0 )
610 {612 {
611 throw XQUERY_EXCEPTION(err::FOAR0001, ERROR_LOC(loc));613 throw XQUERY_EXCEPTION(err::FOAR0001, ERROR_LOC(loc));
612 }614 }
613615
=== modified file 'src/runtime/numerics/format_integer.cpp'
--- src/runtime/numerics/format_integer.cpp 2013-05-04 20:27:31 +0000
+++ src/runtime/numerics/format_integer.cpp 2013-05-08 15:05:31 +0000
@@ -34,6 +34,7 @@
34#include "util/stream_util.h"34#include "util/stream_util.h"
35#include "util/unicode_util.h"35#include "util/unicode_util.h"
36#include "util/utf8_string.h"36#include "util/utf8_string.h"
37#include "zorbatypes/integer.h"
37#include "zorbatypes/numconversions.h"38#include "zorbatypes/numconversions.h"
3839
39using namespace std;40using namespace std;
4041
=== modified file 'src/runtime/numerics/format_number.cpp'
--- src/runtime/numerics/format_number.cpp 2013-05-03 23:19:41 +0000
+++ src/runtime/numerics/format_number.cpp 2013-05-08 15:05:31 +0000
@@ -31,7 +31,8 @@
31#include "types/typeconstants.h"31#include "types/typeconstants.h"
32#include "types/typeops.h"32#include "types/typeops.h"
33#include "util/xml_util.h"33#include "util/xml_util.h"
34#include "zorbatypes/zorbatypes_decl.h"34#include "zorbatypes/floatimpl.h"
35#include "zorbatypes/integer.h"
3536
36namespace zorba {37namespace zorba {
3738
@@ -258,7 +259,7 @@
258 );259 );
259260
260 store::Item_t zero;261 store::Item_t zero;
261 GENV_ITEMFACTORY->createDouble( zero, xs_double::zero() );262 GENV_ITEMFACTORY->createDouble( zero, numeric_consts<xs_double>::zero() );
262263
263 //264 //
264 // Ibid: [T]he positive sub-picture and its associated variables are used if265 // Ibid: [T]he positive sub-picture and its associated variables are used if
265266
=== modified file 'src/runtime/numerics/numerics_impl.cpp'
--- src/runtime/numerics/numerics_impl.cpp 2013-04-11 17:37:16 +0000
+++ src/runtime/numerics/numerics_impl.cpp 2013-05-08 15:05:31 +0000
@@ -22,6 +22,8 @@
22#include "diagnostics/assert.h"22#include "diagnostics/assert.h"
23#include "diagnostics/util_macros.h"23#include "diagnostics/util_macros.h"
24#include "diagnostics/xquery_diagnostics.h"24#include "diagnostics/xquery_diagnostics.h"
25#include "zorbatypes/decimal.h"
26#include "zorbatypes/integer.h"
25#include "zorbatypes/zorbatypes_decl.h"27#include "zorbatypes/zorbatypes_decl.h"
2628
27#include "system/globalenv.h"29#include "system/globalenv.h"
@@ -97,7 +99,7 @@
97 }99 }
98 else if (TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))100 else if (TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))
99 {101 {
100 if (result->getIntegerValue() >= xs_decimal::zero())102 if (result->getIntegerValue().sign() >= 0)
101 {103 {
102 if ( !TypeOps::is_equal(tm, *type, *rtm.INTEGER_TYPE_ONE))104 if ( !TypeOps::is_equal(tm, *type, *rtm.INTEGER_TYPE_ONE))
103 GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue());105 GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue());
@@ -109,7 +111,7 @@
109 }111 }
110 else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))112 else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))
111 {113 {
112 if ( result->getDecimalValue() >= xs_decimal::zero())114 if ( result->getDecimalValue().sign() >= 0)
113 {115 {
114 if ( !TypeOps::is_equal(tm, *type, *rtm.DECIMAL_TYPE_ONE))116 if ( !TypeOps::is_equal(tm, *type, *rtm.DECIMAL_TYPE_ONE))
115 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue());117 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue());
@@ -301,7 +303,7 @@
301 //item type is subtype of INTEGER303 //item type is subtype of INTEGER
302 else if(TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))304 else if(TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))
303 {305 {
304 if(precision_integer < Integer::zero())306 if(precision_integer.sign() < 0)
305 GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue().round(precision_integer));307 GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue().round(precision_integer));
306 }308 }
307309
308310
=== modified file 'src/runtime/random/pregenerated/random.h'
--- src/runtime/random/pregenerated/random.h 2013-03-05 23:11:50 +0000
+++ src/runtime/random/pregenerated/random.h 2013-05-08 15:05:31 +0000
@@ -29,6 +29,7 @@
2929
3030
31#include "runtime/base/narybase.h"31#include "runtime/base/narybase.h"
32#include "zorbatypes/integer.h"
3233
3334
34namespace zorba {35namespace zorba {
3536
=== modified file 'src/runtime/sequences/pregenerated/sequences.cpp'
--- src/runtime/sequences/pregenerated/sequences.cpp 2013-04-15 20:57:28 +0000
+++ src/runtime/sequences/pregenerated/sequences.cpp 2013-05-08 15:05:31 +0000
@@ -238,15 +238,15 @@
238238
239void FnInsertBeforeIteratorState::init(PlanState& planState) {239void FnInsertBeforeIteratorState::init(PlanState& planState) {
240 PlanIteratorState::init(planState);240 PlanIteratorState::init(planState);
241 theCurrentPos = xs_integer::zero();241 theCurrentPos = numeric_consts<xs_integer>::zero();
242 thePosition = xs_integer::zero();242 thePosition = numeric_consts<xs_integer>::zero();
243 theTargetItem = NULL;243 theTargetItem = NULL;
244}244}
245245
246void FnInsertBeforeIteratorState::reset(PlanState& planState) {246void FnInsertBeforeIteratorState::reset(PlanState& planState) {
247 PlanIteratorState::reset(planState);247 PlanIteratorState::reset(planState);
248 theCurrentPos = xs_integer::zero();248 theCurrentPos = numeric_consts<xs_integer>::zero();
249 thePosition = xs_integer::zero();249 thePosition = numeric_consts<xs_integer>::zero();
250 theTargetItem = NULL;250 theTargetItem = NULL;
251}251}
252// </FnInsertBeforeIterator>252// </FnInsertBeforeIterator>
@@ -284,15 +284,15 @@
284284
285void FnRemoveIteratorState::init(PlanState& planState) {285void FnRemoveIteratorState::init(PlanState& planState) {
286 PlanIteratorState::init(planState);286 PlanIteratorState::init(planState);
287 theCurrentPos = xs_integer::zero();287 theCurrentPos = numeric_consts<xs_integer>::zero();
288 thePosition = xs_integer::zero();288 thePosition = numeric_consts<xs_integer>::zero();
289 theCollator = 0;289 theCollator = 0;
290}290}
291291
292void FnRemoveIteratorState::reset(PlanState& planState) {292void FnRemoveIteratorState::reset(PlanState& planState) {
293 PlanIteratorState::reset(planState);293 PlanIteratorState::reset(planState);
294 theCurrentPos = xs_integer::zero();294 theCurrentPos = numeric_consts<xs_integer>::zero();
295 thePosition = xs_integer::zero();295 thePosition = numeric_consts<xs_integer>::zero();
296 theCollator = 0;296 theCollator = 0;
297}297}
298// </FnRemoveIterator>298// </FnRemoveIterator>
@@ -863,16 +863,16 @@
863863
864void OpToIteratorState::init(PlanState& planState) {864void OpToIteratorState::init(PlanState& planState) {
865 PlanIteratorState::init(planState);865 PlanIteratorState::init(planState);
866 theCurInt = xs_integer::zero();866 theCurInt = numeric_consts<xs_integer>::zero();
867 theFirstVal = xs_integer::zero();867 theFirstVal = numeric_consts<xs_integer>::zero();
868 theLastVal = xs_integer::zero();868 theLastVal = numeric_consts<xs_integer>::zero();
869}869}
870870
871void OpToIteratorState::reset(PlanState& planState) {871void OpToIteratorState::reset(PlanState& planState) {
872 PlanIteratorState::reset(planState);872 PlanIteratorState::reset(planState);
873 theCurInt = xs_integer::zero();873 theCurInt = numeric_consts<xs_integer>::zero();
874 theFirstVal = xs_integer::zero();874 theFirstVal = numeric_consts<xs_integer>::zero();
875 theLastVal = xs_integer::zero();875 theLastVal = numeric_consts<xs_integer>::zero();
876}876}
877// </OpToIterator>877// </OpToIterator>
878878
879879
=== modified file 'src/runtime/sequences/pregenerated/sequences.h'
--- src/runtime/sequences/pregenerated/sequences.h 2013-04-15 20:57:28 +0000
+++ src/runtime/sequences/pregenerated/sequences.h 2013-05-08 15:05:31 +0000
@@ -31,6 +31,7 @@
31#include "runtime/base/narybase.h"31#include "runtime/base/narybase.h"
32#include "runtime/base/narybase.h"32#include "runtime/base/narybase.h"
33#include "runtime/core/path_iterators.h"33#include "runtime/core/path_iterators.h"
34#include "zorbatypes/integer.h"
3435
3536
36namespace zorba {37namespace zorba {
3738
=== modified file 'src/runtime/sequences/sequences_impl.cpp'
--- src/runtime/sequences/sequences_impl.cpp 2013-05-01 23:06:33 +0000
+++ src/runtime/sequences/sequences_impl.cpp 2013-05-08 15:05:31 +0000
@@ -20,12 +20,13 @@
20#include <vector>20#include <vector>
21#include <sstream>21#include <sstream>
2222
23#include <zorbautils/fatal.h>
24#include "diagnostics/xquery_diagnostics.h"23#include "diagnostics/xquery_diagnostics.h"
25#include "diagnostics/util_macros.h"24#include "diagnostics/util_macros.h"
2625
27#include <zorbatypes/URI.h>26#include "zorbatypes/decimal.h"
28#include <zorbamisc/ns_consts.h>27#include "zorbatypes/URI.h"
28#include "zorbamisc/ns_consts.h"
29#include "zorbautils/fatal.h"
2930
30// For timing31// For timing
31#include <zorba/util/time.h>32#include <zorba/util/time.h>
@@ -1599,7 +1600,10 @@
1599 else1600 else
1600 {1601 {
1601 STACK_PUSH(1602 STACK_PUSH(
1602 GENV_ITEMFACTORY->createInteger( result, Integer::zero() ), state1603 GENV_ITEMFACTORY->createInteger(
1604 result, numeric_consts<xs_integer>::zero()
1605 ),
1606 state
1603 );1607 );
1604 }1608 }
1605 }1609 }
@@ -1648,7 +1652,7 @@
1648 }1652 }
1649 else1653 else
1650 {1654 {
1651 GENV_ITEMFACTORY->createInteger(result, Integer::zero());1655 GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero());
1652 STACK_PUSH(true, state);1656 STACK_PUSH(true, state);
1653 }1657 }
16541658
@@ -1697,7 +1701,7 @@
1697 }1701 }
1698 else1702 else
1699 {1703 {
1700 GENV_ITEMFACTORY->createInteger(result, Integer::zero());1704 GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero());
1701 STACK_PUSH(true, state);1705 STACK_PUSH(true, state);
1702 }1706 }
17031707
@@ -1745,7 +1749,7 @@
1745 }1749 }
1746 else1750 else
1747 {1751 {
1748 GENV_ITEMFACTORY->createInteger(result, Integer::zero());1752 GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero());
1749 STACK_PUSH(true, state);1753 STACK_PUSH(true, state);
1750 }1754 }
17511755
@@ -1803,7 +1807,7 @@
1803 }1807 }
1804 else1808 else
1805 {1809 {
1806 GENV_ITEMFACTORY->createInteger(result, Integer::zero());1810 GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero());
1807 STACK_PUSH(true, state);1811 STACK_PUSH(true, state);
1808 }1812 }
18091813
18101814
=== modified file 'src/runtime/spec/maths/maths.xml'
--- src/runtime/spec/maths/maths.xml 2013-02-07 17:24:36 +0000
+++ src/runtime/spec/maths/maths.xml 2013-05-08 15:05:31 +0000
@@ -6,6 +6,7 @@
6 xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd">6 xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd">
77
8<zorba:header>8<zorba:header>
9 <zorba:include form="Quoted">zorbatypes/integer.h</zorba:include>
9 <zorba:include form="Quoted">zorbatypes/schema_types.h</zorba:include>10 <zorba:include form="Quoted">zorbatypes/schema_types.h</zorba:include>
10</zorba:header>11</zorba:header>
11 12
@@ -462,7 +463,7 @@
462 </zorba:function>463 </zorba:function>
463464
464 <zorba:state generateInit="true" generateReset="true">465 <zorba:state generateInit="true" generateReset="true">
465 <zorba:member type="xs_double" name="theDoubInteger" defaultValue="xs_double::zero()"466 <zorba:member type="xs_double" name="theDoubInteger" defaultValue="numeric_consts&lt;xs_double&gt;::zero()"
466 brief=""/>467 brief=""/>
467 </zorba:state>468 </zorba:state>
468 469
@@ -485,7 +486,7 @@
485 </zorba:function>486 </zorba:function>
486487
487 <zorba:state generateInit="true" generateReset="true">488 <zorba:state generateInit="true" generateReset="true">
488 <zorba:member type="xs_integer" name="theIntExponent" defaultValue="xs_integer::zero()"489 <zorba:member type="xs_integer" name="theIntExponent" defaultValue="numeric_consts&lt;xs_integer&gt;::zero()"
489 brief=""/>490 brief=""/>
490 </zorba:state>491 </zorba:state>
491 492
492493
=== modified file 'src/runtime/spec/random/random.xml'
--- src/runtime/spec/random/random.xml 2013-02-07 17:24:36 +0000
+++ src/runtime/spec/random/random.xml 2013-05-08 15:05:31 +0000
@@ -12,6 +12,10 @@
12 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"12 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
13 xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd">13 xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd">
1414
15<zorba:header>
16 <zorba:include form="Quoted">zorbatypes/integer.h</zorba:include>
17</zorba:header>
18
15<!--19<!--
16/*******************************************************************************20/*******************************************************************************
17********************************************************************************/21********************************************************************************/
1822
=== modified file 'src/runtime/spec/sequences/sequences.xml'
--- src/runtime/spec/sequences/sequences.xml 2013-04-15 20:57:28 +0000
+++ src/runtime/spec/sequences/sequences.xml 2013-05-08 15:05:31 +0000
@@ -15,6 +15,7 @@
15<zorba:header>15<zorba:header>
16 <zorba:include form="Quoted">runtime/base/narybase.h</zorba:include>16 <zorba:include form="Quoted">runtime/base/narybase.h</zorba:include>
17 <zorba:include form="Quoted">runtime/core/path_iterators.h</zorba:include>17 <zorba:include form="Quoted">runtime/core/path_iterators.h</zorba:include>
18 <zorba:include form="Quoted">zorbatypes/integer.h</zorba:include>
18 <zorba:fwd-decl ns="zorba">NodeHandleHashSet</zorba:fwd-decl>19 <zorba:fwd-decl ns="zorba">NodeHandleHashSet</zorba:fwd-decl>
19 <zorba:fwd-decl ns="zorba">AtomicItemHandleHashSet</zorba:fwd-decl>20 <zorba:fwd-decl ns="zorba">AtomicItemHandleHashSet</zorba:fwd-decl>
20</zorba:header>21</zorba:header>
@@ -283,10 +284,10 @@
283284
284 <zorba:state>285 <zorba:state>
285 <zorba:member type="xs_integer" name="theCurrentPos"286 <zorba:member type="xs_integer" name="theCurrentPos"
286 defaultValue="xs_integer::zero()" brief="the current position in the sequence"/>287 defaultValue="numeric_consts&lt;xs_integer&gt;::zero()" brief="the current position in the sequence"/>
287288
288 <zorba:member type="xs_integer" name="thePosition"289 <zorba:member type="xs_integer" name="thePosition"
289 defaultValue="xs_integer::zero()" brief=""/>290 defaultValue="numeric_consts&lt;xs_integer&gt;::zero()" brief=""/>
290291
291 <zorba:member type="store::Item_t" name="theTargetItem"292 <zorba:member type="store::Item_t" name="theTargetItem"
292 defaultValue="NULL" brief=""/>293 defaultValue="NULL" brief=""/>
@@ -328,10 +329,10 @@
328329
329 <zorba:state>330 <zorba:state>
330 <zorba:member type="xs_integer" name="theCurrentPos"331 <zorba:member type="xs_integer" name="theCurrentPos"
331 defaultValue="xs_integer::zero()" brief="the current position in the sequence"/>332 defaultValue="numeric_consts&lt;xs_integer&gt;::zero()" brief="the current position in the sequence"/>
332333
333 <zorba:member type="xs_integer" name="thePosition"334 <zorba:member type="xs_integer" name="thePosition"
334 defaultValue="xs_integer::zero()" brief="the position to delete"/>335 defaultValue="numeric_consts&lt;xs_integer&gt;::zero()" brief="the position to delete"/>
335336
336 <zorba:member type="XQPCollator*" name="theCollator"337 <zorba:member type="XQPCollator*" name="theCollator"
337 defaultValue="0" brief="the collator"/>338 defaultValue="0" brief="the collator"/>
@@ -952,12 +953,12 @@
952953
953 <zorba:state>954 <zorba:state>
954 <zorba:member type="xs_integer" name="theCurInt"955 <zorba:member type="xs_integer" name="theCurInt"
955 defaultValue="xs_integer::zero()" brief="the current integer"/>956 defaultValue="numeric_consts&lt;xs_integer&gt;::zero()" brief="the current integer"/>
956957
957 <zorba:member type="xs_integer" name="theFirstVal"958 <zorba:member type="xs_integer" name="theFirstVal"
958 defaultValue="xs_integer::zero()" brief="first integer"/>959 defaultValue="numeric_consts&lt;xs_integer&gt;::zero()" brief="first integer"/>
959960
960 <zorba:member type="xs_integer" name="theLastVal" defaultValue="xs_integer::zero()"961 <zorba:member type="xs_integer" name="theLastVal" defaultValue="numeric_consts&lt;xs_integer&gt;::zero()"
961 brief="last integer"/>962 brief="last integer"/>
962 </zorba:state>963 </zorba:state>
963964
964965
=== modified file 'src/runtime/store/maps_impl.cpp'
--- src/runtime/store/maps_impl.cpp 2013-03-05 12:34:19 +0000
+++ src/runtime/store/maps_impl.cpp 2013-05-08 15:05:31 +0000
@@ -19,6 +19,7 @@
19#include "diagnostics/util_macros.h"19#include "diagnostics/util_macros.h"
20#include "diagnostics/xquery_diagnostics.h"20#include "diagnostics/xquery_diagnostics.h"
2121
22#include "zorbatypes/integer.h"
22#include "zorbatypes/URI.h"23#include "zorbatypes/URI.h"
2324
24#include "system/globalenv.h"25#include "system/globalenv.h"
2526
=== modified file 'src/runtime/strings/strings_impl.cpp'
--- src/runtime/strings/strings_impl.cpp 2013-05-04 20:20:05 +0000
+++ src/runtime/strings/strings_impl.cpp 2013-05-08 15:05:31 +0000
@@ -25,6 +25,7 @@
25#include "diagnostics/xquery_diagnostics.h"25#include "diagnostics/xquery_diagnostics.h"
26#include "diagnostics/util_macros.h"26#include "diagnostics/util_macros.h"
2727
28#include "zorbatypes/integer.h"
28#include "zorbatypes/numconversions.h"29#include "zorbatypes/numconversions.h"
2930
30#include "system/globalenv.h"31#include "system/globalenv.h"
@@ -734,8 +735,12 @@
734 }735 }
735 else736 else
736 {737 {
737 STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, xs_integer::zero()),738 STACK_PUSH(
738 state);739 GENV_ITEMFACTORY->createInteger(
740 result, numeric_consts<xs_integer>::zero()
741 ),
742 state
743 );
739 }744 }
740 STACK_END(state);745 STACK_END(state);
741}746}
742747
=== modified file 'src/store/api/collection.h'
--- src/store/api/collection.h 2013-02-07 17:24:36 +0000
+++ src/store/api/collection.h 2013-05-08 15:05:31 +0000
@@ -59,7 +59,7 @@
59 * @return Iterator59 * @return Iterator
60 */60 */
61 virtual Iterator_t getIterator(61 virtual Iterator_t getIterator(
62 const xs_integer& aSkip = xs_integer::zero(),62 const xs_integer& aSkip = numeric_consts<xs_integer>::zero(),
63 const zstring& aStart = "") = 0;63 const zstring& aStart = "") = 0;
6464
65 /**65 /**
6666
=== modified file 'src/store/api/iterator.h'
--- src/store/api/iterator.h 2013-03-05 00:45:43 +0000
+++ src/store/api/iterator.h 2013-05-08 15:05:31 +0000
@@ -177,7 +177,7 @@
177 virtual ~IndexProbeIterator() { }177 virtual ~IndexProbeIterator() { }
178178
179 virtual void init(const IndexCondition_t& cond,179 virtual void init(const IndexCondition_t& cond,
180 const xs_integer& aSkip = xs_integer::zero()) = 0;180 const xs_integer& aSkip = numeric_consts<xs_integer>::zero()) = 0;
181181
182 virtual void open() = 0;182 virtual void open() = 0;
183 183
184184
=== modified file 'src/store/naive/atomic_items.cpp'
--- src/store/naive/atomic_items.cpp 2013-04-16 21:12:12 +0000
+++ src/store/naive/atomic_items.cpp 2013-05-08 15:05:31 +0000
@@ -2691,7 +2691,7 @@
26912691
2692bool DecimalItem::getEBV() const2692bool DecimalItem::getEBV() const
2693{2693{
2694 return ( theValue != xs_decimal::zero() );2694 return !!theValue.sign();
2695}2695}
26962696
26972697
26982698
=== modified file 'src/store/naive/atomic_items.h'
--- src/store/naive/atomic_items.h 2013-04-08 08:45:18 +0000
+++ src/store/naive/atomic_items.h 2013-05-08 15:05:31 +0000
@@ -38,8 +38,11 @@
38#include "naive_ft_token_iterator.h"38#include "naive_ft_token_iterator.h"
39#endif /* ZORBA_NO_FULL_TEXT */39#endif /* ZORBA_NO_FULL_TEXT */
4040
41#include "zorbatypes/datetime.h"
42#include "zorbatypes/decimal.h"
43#include "zorbatypes/floatimpl.h"
44#include "zorbatypes/integer.h"
41#include "zorbatypes/schema_types.h"45#include "zorbatypes/schema_types.h"
42#include "zorbatypes/datetime.h"
4346
44#include "diagnostics/xquery_diagnostics.h"47#include "diagnostics/xquery_diagnostics.h"
45#include "ordpath.h"48#include "ordpath.h"
4649
=== modified file 'src/store/naive/collection.h'
--- src/store/naive/collection.h 2013-02-26 04:12:43 +0000
+++ src/store/naive/collection.h 2013-05-08 15:05:31 +0000
@@ -17,6 +17,7 @@
17#define ZORBA_SIMPLESTORE_COLLECTION17#define ZORBA_SIMPLESTORE_COLLECTION
1818
19#include "store/api/collection.h"19#include "store/api/collection.h"
20#include "zorbatypes/integer.h"
2021
21#include "shared_types.h"22#include "shared_types.h"
22#include "tree_id.h"23#include "tree_id.h"
2324
=== modified file 'src/store/naive/collection_tree_info.h'
--- src/store/naive/collection_tree_info.h 2013-02-06 18:52:32 +0000
+++ src/store/naive/collection_tree_info.h 2013-05-08 15:05:31 +0000
@@ -18,6 +18,7 @@
18#define ZORBA_STORE_COLLECTION_TREE_INFO_H18#define ZORBA_STORE_COLLECTION_TREE_INFO_H
1919
20#include <zorba/config.h>20#include <zorba/config.h>
21#include "zorbatypes/integer.h"
2122
22namespace zorba23namespace zorba
23{24{
2425
=== modified file 'src/store/naive/pul_primitives.cpp'
--- src/store/naive/pul_primitives.cpp 2013-02-26 04:12:43 +0000
+++ src/store/naive/pul_primitives.cpp 2013-05-08 15:05:31 +0000
@@ -1147,7 +1147,7 @@
11471147
1148 assert(lColl);1148 assert(lColl);
11491149
1150 xs_integer const zero( xs_integer::zero() );1150 xs_integer const zero( numeric_consts<xs_integer>::zero() );
1151 for (std::size_t i = 0; i < theNumApplied; ++i)1151 for (std::size_t i = 0; i < theNumApplied; ++i)
1152 {1152 {
1153 ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(zero));1153 ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(zero));
11541154
=== modified file 'src/store/naive/simple_collection.cpp'
--- src/store/naive/simple_collection.cpp 2013-04-16 21:12:12 +0000
+++ src/store/naive/simple_collection.cpp 2013-05-08 15:05:31 +0000
@@ -93,7 +93,7 @@
93 const zstring& startRef)93 const zstring& startRef)
94{94{
95 store::Item_t startNode;95 store::Item_t startNode;
96 xs_integer startPos = xs_integer::zero();96 xs_integer startPos;
9797
98 if (startRef.size() != 0 &&98 if (startRef.size() != 0 &&
99 (!GET_STORE().getNodeByReference(startNode, startRef) ||99 (!GET_STORE().getNodeByReference(startNode, startRef) ||
@@ -511,7 +511,7 @@
511511
512 if (num == 0 || pos >= theTrees.size())512 if (num == 0 || pos >= theTrees.size())
513 {513 {
514 return xs_integer::zero();514 return numeric_consts<xs_integer>::zero();
515 }515 }
516 else516 else
517 {517 {
518518
=== modified file 'src/store/naive/simple_index_value.h'
--- src/store/naive/simple_index_value.h 2013-02-07 17:24:36 +0000
+++ src/store/naive/simple_index_value.h 2013-05-08 15:05:31 +0000
@@ -17,6 +17,7 @@
17#define ZORBA_SIMPLE_STORE_INDEX_HASH_VALUE17#define ZORBA_SIMPLE_STORE_INDEX_HASH_VALUE
1818
19#include "simple_index.h"19#include "simple_index.h"
20#include "zorbatypes/integer.h"
20#include <map>21#include <map>
2122
22namespace zorba23namespace zorba
2324
=== modified file 'src/store/naive/simple_lazy_temp_seq.cpp'
--- src/store/naive/simple_lazy_temp_seq.cpp 2013-04-16 21:12:12 +0000
+++ src/store/naive/simple_lazy_temp_seq.cpp 2013-05-08 15:05:31 +0000
@@ -21,9 +21,9 @@
21#include "diagnostics/dict.h"21#include "diagnostics/dict.h"
22#include "diagnostics/util_macros.h"22#include "diagnostics/util_macros.h"
23#include "diagnostics/xquery_exception.h"23#include "diagnostics/xquery_exception.h"
2424#include "simple_lazy_temp_seq.h"
25#include "store/api/item.h"25#include "store/api/item.h"
26#include "simple_lazy_temp_seq.h"26#include "zorbatypes/integer.h"
2727
2828
29namespace zorba29namespace zorba
3030
=== modified file 'src/store/naive/simple_pul.cpp'
--- src/store/naive/simple_pul.cpp 2013-04-17 18:37:33 +0000
+++ src/store/naive/simple_pul.cpp 2013-05-08 15:05:31 +0000
@@ -1419,8 +1419,7 @@
14191419
1420 xs_integer pos = position->getIntegerValue();1420 xs_integer pos = position->getIntegerValue();
14211421
1422 if (pos <= xs_integer::zero() ||1422 if (pos.sign() <= 0 || arr->getArraySize() + 1 < pos)
1423 arr->getArraySize() + 1 < pos)
1424 {1423 {
1425 RAISE_ERROR(jerr::JNUP0016, loc,1424 RAISE_ERROR(jerr::JNUP0016, loc,
1426 ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue()));1425 ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue()));
@@ -1557,8 +1556,7 @@
15571556
1558 xs_integer pos = position->getIntegerValue();1557 xs_integer pos = position->getIntegerValue();
15591558
1560 if (pos <= xs_integer::zero() ||1559 if (pos.sign() <= 0 || arr->getArraySize() < pos)
1561 arr->getArraySize() < pos)
1562 {1560 {
1563 RAISE_ERROR(jerr::JNUP0016, loc,1561 RAISE_ERROR(jerr::JNUP0016, loc,
1564 ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue()));1562 ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue()));
@@ -1623,8 +1621,7 @@
16231621
1624 xs_integer pos = position->getIntegerValue();1622 xs_integer pos = position->getIntegerValue();
16251623
1626 if (pos <= xs_integer::zero() ||1624 if (pos.sign() <= 0 || arr->getArraySize() < pos)
1627 arr->getArraySize() < pos)
1628 {1625 {
1629 RAISE_ERROR(jerr::JNUP0016, loc,1626 RAISE_ERROR(jerr::JNUP0016, loc,
1630 ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue()));1627 ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue()));
16311628
=== modified file 'src/store/naive/simple_temp_seq.cpp'
--- src/store/naive/simple_temp_seq.cpp 2013-04-17 18:37:33 +0000
+++ src/store/naive/simple_temp_seq.cpp 2013-05-08 15:05:31 +0000
@@ -24,6 +24,7 @@
24#include "store/api/item.h"24#include "store/api/item.h"
25#include "simple_temp_seq.h"25#include "simple_temp_seq.h"
26#include "store/api/copymode.h"26#include "store/api/copymode.h"
27#include "zorbatypes/integer.h"
2728
28namespace zorba { namespace simplestore {29namespace zorba { namespace simplestore {
2930
3031
=== modified file 'src/system/globalenv.cpp'
--- src/system/globalenv.cpp 2013-02-07 17:24:36 +0000
+++ src/system/globalenv.cpp 2013-05-08 15:05:31 +0000
@@ -42,6 +42,7 @@
4242
43#include "types/schema/schema.h"43#include "types/schema/schema.h"
4444
45#include "zorbatypes/m_apm.h"
45#include "zorbautils/condition.h"46#include "zorbautils/condition.h"
4647
47#include "store/api/collection.h"48#include "store/api/collection.h"
4849
=== modified file 'src/types/casting.cpp'
--- src/types/casting.cpp 2013-05-02 00:18:56 +0000
+++ src/types/casting.cpp 2013-05-08 15:05:31 +0000
@@ -17,10 +17,13 @@
1717
18#include <vector>18#include <vector>
1919
20#include "zorbatypes/numconversions.h"20#include "zorbatypes/chartype.h"
21#include "zorbatypes/datetime.h"21#include "zorbatypes/datetime.h"
22#include "zorbatypes/decimal.h"
22#include "zorbatypes/duration.h"23#include "zorbatypes/duration.h"
23#include "zorbatypes/chartype.h"24#include "zorbatypes/floatimpl.h"
25#include "zorbatypes/integer.h"
26#include "zorbatypes/numconversions.h"
24#include "zorbatypes/URI.h"27#include "zorbatypes/URI.h"
2528
26#include "diagnostics/xquery_diagnostics.h"29#include "diagnostics/xquery_diagnostics.h"
@@ -1433,36 +1436,36 @@
1433T1_TO_T2(bool, flt)1436T1_TO_T2(bool, flt)
1434{1437{
1435 if (aItem->getBooleanValue())1438 if (aItem->getBooleanValue())
1436 aFactory->createFloat(result, xs_float::one());1439 aFactory->createFloat(result, numeric_consts<xs_float>::one());
1437 else1440 else
1438 aFactory->createFloat(result, xs_float::zero());1441 aFactory->createFloat(result, numeric_consts<xs_float>::zero());
1439}1442}
14401443
14411444
1442T1_TO_T2(bool, dbl)1445T1_TO_T2(bool, dbl)
1443{1446{
1444 if (aItem->getBooleanValue())1447 if (aItem->getBooleanValue())
1445 aFactory->createDouble(result, xs_double::one());1448 aFactory->createDouble(result, numeric_consts<xs_double>::one());
1446 else1449 else
1447 aFactory->createDouble(result, xs_double::zero());1450 aFactory->createDouble(result, numeric_consts<xs_double>::zero());
1448}1451}
14491452
14501453
1451T1_TO_T2(bool, dec)1454T1_TO_T2(bool, dec)
1452{1455{
1453 if (aItem->getBooleanValue())1456 if (aItem->getBooleanValue())
1454 aFactory->createDecimal(result, xs_decimal::one());1457 aFactory->createDecimal(result, numeric_consts<xs_decimal>::one());
1455 else1458 else
1456 aFactory->createDecimal(result, xs_decimal::zero());1459 aFactory->createDecimal(result, numeric_consts<xs_decimal>::zero());
1457}1460}
14581461
14591462
1460T1_TO_T2(bool, int)1463T1_TO_T2(bool, int)
1461{1464{
1462 if (aItem->getBooleanValue())1465 if (aItem->getBooleanValue())
1463 aFactory->createInteger(result, xs_integer::one());1466 aFactory->createInteger(result, numeric_consts<xs_integer>::one());
1464 else1467 else
1465 aFactory->createInteger(result, xs_integer::zero());1468 aFactory->createInteger(result, numeric_consts<xs_integer>::zero());
1466}1469}
14671470
14681471
@@ -1666,17 +1669,24 @@
16661669
1667T1_TO_T2(dec, uint)1670T1_TO_T2(dec, uint)
1668{1671{
1669 xs_nonNegativeInteger const n(aItem->getDecimalValue());1672 try
1670 aFactory->createNonNegativeInteger(result, n);1673 {
1674 xs_nonNegativeInteger const n(aItem->getDecimalValue());
1675 aFactory->createNonNegativeInteger(result, n);
1676 }
1677 catch ( const std::exception& )
1678 {
1679 throwFOCA0002Exception(aItem->getStringValue(), errInfo);
1680 }
1671}1681}
16721682
16731683
1674T1_TO_T2(bool, uint)1684T1_TO_T2(bool, uint)
1675{1685{
1676 if (aItem->getBooleanValue())1686 xs_nonNegativeInteger const &i = aItem->getBooleanValue() ?
1677 aFactory->createNonNegativeInteger(result, xs_nonNegativeInteger::one());1687 numeric_consts<xs_nonNegativeInteger>::one() :
1678 else1688 numeric_consts<xs_nonNegativeInteger>::zero();
1679 aFactory->createNonNegativeInteger(result, xs_nonNegativeInteger::zero());1689 aFactory->createNonNegativeInteger(result, i );
1680}1690}
16811691
16821692
@@ -2024,12 +2034,16 @@
2024 }2034 }
2025 case store::XS_POSITIVE_INTEGER:2035 case store::XS_POSITIVE_INTEGER:
2026 {2036 {
2027 xs_positiveInteger const i = aItem->getUnsignedIntegerValue();2037 try
2028 if (i.sign() > 0)
2029 {2038 {
2030 factory->createPositiveInteger(result, i);2039 xs_positiveInteger const n = aItem->getUnsignedIntegerValue();
2040 factory->createPositiveInteger(result, n);
2031 return;2041 return;
2032 }2042 }
2043 catch ( std::exception const& )
2044 {
2045 // ignore
2046 }
2033 break;2047 break;
2034 }2048 }
2035 default:2049 default:
20362050
=== modified file 'src/types/schema/XercesParseUtils.cpp'
--- src/types/schema/XercesParseUtils.cpp 2013-03-05 12:34:19 +0000
+++ src/types/schema/XercesParseUtils.cpp 2013-05-08 15:05:31 +0000
@@ -28,15 +28,18 @@
28#include "LoadSchemaErrorHandler.h"28#include "LoadSchemaErrorHandler.h"
29#include "PrintSchema.h"29#include "PrintSchema.h"
3030
31#include "diagnostics/xquery_diagnostics.h"
31#include "store/api/item.h"32#include "store/api/item.h"
32#include "store/api/item_factory.h"33#include "store/api/item_factory.h"
34#include "system/globalenv.h"
33#include "types/typeimpl.h"35#include "types/typeimpl.h"
34#include "diagnostics/xquery_diagnostics.h"36#include "util/utf8_util.h"
35#include <zorbatypes/numconversions.h>
36#include "system/globalenv.h"
37#include "zorbatypes/datetime.h"37#include "zorbatypes/datetime.h"
38#include "zorbatypes/decimal.h"
38#include "zorbatypes/duration.h"39#include "zorbatypes/duration.h"
39#include "util/utf8_util.h"40#include "zorbatypes/floatimpl.h"
41#include "zorbatypes/integer.h"
42#include "zorbatypes/numconversions.h"
4043
41using namespace std;44using namespace std;
42XERCES_CPP_NAMESPACE_USE;45XERCES_CPP_NAMESPACE_USE;
4346
=== modified file 'src/util/stl_util.h'
--- src/util/stl_util.h 2013-04-17 15:21:56 +0000
+++ src/util/stl_util.h 2013-05-08 15:05:31 +0000
@@ -421,6 +421,13 @@
421 return true;421 return true;
422}422}
423423
424inline std::enable_if<!ZORBA_TR1_NS::is_signed<char>::value
425 && !ZORBA_TR1_NS::is_unsigned<char>::value,
426 bool>::type
427ge0( char c ) {
428 return c >= 0;
429}
430
424template<typename NumericType> inline431template<typename NumericType> inline
425typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type432typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type
426lt0( NumericType n ) {433lt0( NumericType n ) {
@@ -433,6 +440,13 @@
433 return false;440 return false;
434}441}
435442
443inline std::enable_if<!ZORBA_TR1_NS::is_signed<char>::value
444 && !ZORBA_TR1_NS::is_unsigned<char>::value,
445 bool>::type
446lt0( char c ) {
447 return c < 0;
448}
449
436template<typename NumericType> inline450template<typename NumericType> inline
437typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type451typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type
438le0( NumericType n ) {452le0( NumericType n ) {
@@ -445,6 +459,10 @@
445 return n == 0;459 return n == 0;
446}460}
447461
462inline bool le0( char c ) {
463 return c <= 0;
464}
465
448///////////////////////////////////////////////////////////////////////////////466///////////////////////////////////////////////////////////////////////////////
449467
450//468//
451469
=== modified file 'src/zorbaserialization/serialize_basic_types.cpp'
--- src/zorbaserialization/serialize_basic_types.cpp 2013-04-08 00:12:00 +0000
+++ src/zorbaserialization/serialize_basic_types.cpp 2013-05-08 15:05:31 +0000
@@ -22,6 +22,7 @@
22#include "zorbaserialization/archiver.h"22#include "zorbaserialization/archiver.h"
23#include "zorbaserialization/base64impl.h"23#include "zorbaserialization/base64impl.h"
2424
25#include "zorbatypes/m_apm.h"
25#include "zorbatypes/floatimpl.h"26#include "zorbatypes/floatimpl.h"
2627
27#include "diagnostics/xquery_diagnostics.h"28#include "diagnostics/xquery_diagnostics.h"
2829
=== modified file 'src/zorbaserialization/serialize_zorba_types.cpp'
--- src/zorbaserialization/serialize_zorba_types.cpp 2013-03-27 17:11:24 +0000
+++ src/zorbaserialization/serialize_zorba_types.cpp 2013-05-08 15:05:31 +0000
@@ -82,26 +82,21 @@
82/*******************************************************************************82/*******************************************************************************
8383
84********************************************************************************/84********************************************************************************/
85#ifdef ZORBA_WITH_BIG_INTEGER85
8686template<class T>
87void operator&(serialization::Archiver& ar, IntegerImpl& obj)87void operator&(serialization::Archiver& ar, IntegerImpl<T>& obj)
88{88{
89 ar & obj.value_;89 ar & obj.value();
90}90}
9191
92#else92#define INSTANTIATE_INTEGER(I) \
9393 template void operator&<I::traits_type>(serialization::Archiver&, I&)
94void operator&(serialization::Archiver& ar, IntegerImpl<long long>& obj)94
95{95INSTANTIATE_INTEGER( Integer );
96 ar & obj.value();96INSTANTIATE_INTEGER( NegativeInteger );
97}97INSTANTIATE_INTEGER( NonNegativeInteger );
9898INSTANTIATE_INTEGER( NonPositiveInteger );
99void operator&(serialization::Archiver& ar, IntegerImpl<unsigned long long>& obj)99INSTANTIATE_INTEGER( PositiveInteger );
100{
101 ar & obj.value();
102}
103
104#endif
105100
106101
107/*******************************************************************************102/*******************************************************************************
108103
=== modified file 'src/zorbaserialization/serialize_zorba_types.h'
--- src/zorbaserialization/serialize_zorba_types.h 2013-02-07 17:24:36 +0000
+++ src/zorbaserialization/serialize_zorba_types.h 2013-05-08 15:05:31 +0000
@@ -23,6 +23,7 @@
23#include "zorbatypes/rchandle.h"23#include "zorbatypes/rchandle.h"
24#include "zorbatypes/m_apm.h"24#include "zorbatypes/m_apm.h"
25#include "zorbatypes/floatimpl.h"25#include "zorbatypes/floatimpl.h"
26#include "zorbatypes/zorbatypes_decl.h"
2627
27#include "zorbautils/checked_vector.h"28#include "zorbautils/checked_vector.h"
2829
@@ -37,24 +38,16 @@
3738
38namespace zorba39namespace zorba
39{40{
40 class Decimal;
41 class Duration;
42 class Timezone;
43 class DateTime;
44 class Base16;41 class Base16;
45 class Base64;42 class Base64;
46 class QueryLoc;43 class Diagnostic;
44 class function;
47 class HashMapItemPointerCmp;45 class HashMapItemPointerCmp;
48 class HashMapZStringCmp;46 class HashMapZStringCmp;
47 class QueryLoc;
48 class Timezone;
49 class XQType;49 class XQType;
50 class function;
51 class Diagnostic;
52 class ZorbaException;50 class ZorbaException;
53#ifdef ZORBA_WITH_BIG_INTEGER
54 class IntegerImpl;
55#else
56 template<typename IntType> class IntegerImpl;
57#endif /* ZORBA_WITH_BIG_INTEGER */
5851
59namespace serialization52namespace serialization
60{53{
@@ -65,12 +58,8 @@
6558
66void operator&(Archiver& ar, const XQType*& obj);59void operator&(Archiver& ar, const XQType*& obj);
6760
68#ifdef ZORBA_WITH_BIG_INTEGER61template<class C>
69void operator&(Archiver& ar, IntegerImpl& obj);62void operator&(Archiver& ar, IntegerImpl<C>& obj);
70#else
71void operator&(serialization::Archiver& ar, IntegerImpl<long long>& obj);
72void operator&(serialization::Archiver& ar, IntegerImpl<unsigned long long>& obj);
73#endif
7463
75void operator&(Archiver& ar, Decimal& obj);64void operator&(Archiver& ar, Decimal& obj);
7665
7766
=== modified file 'src/zorbatypes/CMakeLists.txt'
--- src/zorbatypes/CMakeLists.txt 2013-02-07 17:24:36 +0000
+++ src/zorbatypes/CMakeLists.txt 2013-05-08 15:05:31 +0000
@@ -17,6 +17,7 @@
17 floatimpl.cpp17 floatimpl.cpp
18 integer.cpp18 integer.cpp
19 numconversions.cpp19 numconversions.cpp
20 numeric_types.cpp
20 binary.cpp21 binary.cpp
21 URI.cpp22 URI.cpp
22 collation_manager.cpp23 collation_manager.cpp
2324
=== modified file 'src/zorbatypes/datetime.h'
--- src/zorbatypes/datetime.h 2013-04-23 06:09:42 +0000
+++ src/zorbatypes/datetime.h 2013-05-08 15:05:31 +0000
@@ -20,11 +20,10 @@
20#include <iostream>20#include <iostream>
2121
22#include <zorba/config.h>22#include <zorba/config.h>
23#include "zorbatypes/timezone.h"
24#include "zorbatypes/duration.h"
25
26#include "util/ascii_util.h"23#include "util/ascii_util.h"
2724
25#include "timezone.h"
26#include "duration.h"
2827
29namespace zorba28namespace zorba
30{29{
@@ -301,7 +300,7 @@
301 300
302 int getMinutes() const;301 int getMinutes() const;
303 302
304 xs_decimal getSeconds() const;303 Decimal getSeconds() const;
305 304
306 int getIntSeconds() const;305 int getIntSeconds() const;
307 306
308307
=== modified file 'src/zorbatypes/datetime/datetimetype.cpp'
--- src/zorbatypes/datetime/datetimetype.cpp 2013-04-24 17:26:02 +0000
+++ src/zorbatypes/datetime/datetimetype.cpp 2013-05-08 15:05:31 +0000
@@ -29,14 +29,15 @@
29#include <time.h>29#include <time.h>
30#endif30#endif
3131
32#include "zorbatypes/datetime.h"
33#include "zorbatypes/datetime/parse.h"
34#include "zorbatypes/decimal.h"
35#include "zorbatypes/duration.h"
36#include "zorbatypes/integer.h"
37#include "zorbatypes/timezone.h"
38#include "zorbatypes/zorbatypes_decl.h"
39#include "zorbatypes/zstring.h"
32#include "zorbautils/hashfun.h"40#include "zorbautils/hashfun.h"
33#include <zorbatypes/datetime.h>
34#include <zorbatypes/duration.h>
35#include <zorbatypes/timezone.h>
36#include <zorbatypes/zorbatypes_decl.h>
37#include <zorbatypes/zstring.h>
38
39#include "zorbatypes/datetime/parse.h"
4041
41#include "util/ascii_util.h"42#include "util/ascii_util.h"
42#include "util/time_util.h"43#include "util/time_util.h"
@@ -1325,7 +1326,7 @@
1325 // validate timezone value (-14 .. +14 H)1326 // validate timezone value (-14 .. +14 H)
1326 if (d->getYears() != 0 || d->getMonths() != 0 ||1327 if (d->getYears() != 0 || d->getMonths() != 0 ||
1327 d->getDays() != 0 ||1328 d->getDays() != 0 ||
1328 d->getSeconds() != Integer::zero() ||1329 d->getSeconds().sign() != 0 ||
1329 d->getHours()*3600 + d->getMinutes()*60 > 14*3600 ||1330 d->getHours()*3600 + d->getMinutes()*60 > 14*3600 ||
1330 d->getHours()*3600 + d->getMinutes()*60 < -14*3600)1331 d->getHours()*3600 + d->getMinutes()*60 < -14*3600)
1331 throw InvalidTimezoneException( d->getHours()*3600 + d->getMinutes()*60 );1332 throw InvalidTimezoneException( d->getHours()*3600 + d->getMinutes()*60 );
13321333
=== modified file 'src/zorbatypes/datetime/duration.cpp'
--- src/zorbatypes/datetime/duration.cpp 2013-04-16 21:12:12 +0000
+++ src/zorbatypes/datetime/duration.cpp 2013-05-08 15:05:31 +0000
@@ -19,11 +19,14 @@
19#include <memory>19#include <memory>
20#include <string>20#include <string>
2121
22#include "zorbautils/hashfun.h"22#include "zorbatypes/datetime.h"
23#include "zorbatypes/datetime/parse.h"
24#include "zorbatypes/decimal.h"
23#include "zorbatypes/duration.h"25#include "zorbatypes/duration.h"
24#include "zorbatypes/datetime/parse.h"26#include "zorbatypes/floatimpl.h"
27#include "zorbatypes/integer.h"
25#include "zorbatypes/numconversions.h"28#include "zorbatypes/numconversions.h"
26#include "zorbatypes/datetime.h"29#include "zorbautils/hashfun.h"
2730
28#include "diagnostics/xquery_diagnostics.h"31#include "diagnostics/xquery_diagnostics.h"
2932
@@ -597,7 +600,8 @@
597600
598xs_double Duration::getTotalSeconds() const601xs_double Duration::getTotalSeconds() const
599{602{
600 return (is_negative ? xs_double::neg_one() : xs_double::one())603 return (is_negative ?
604 numeric_consts<xs_double>::neg_one() : numeric_consts<xs_double>::one())
601 * ((((((((xs_double(data[YEAR_DATA]) * 12605 * ((((((((xs_double(data[YEAR_DATA]) * 12
602 + xs_double(data[MONTH_DATA])) * 30)606 + xs_double(data[MONTH_DATA])) * 30)
603 + xs_double(data[DAY_DATA])) * 24)607 + xs_double(data[DAY_DATA])) * 24)
604608
=== modified file 'src/zorbatypes/datetime/timezone.cpp'
--- src/zorbatypes/datetime/timezone.cpp 2013-03-13 16:19:33 +0000
+++ src/zorbatypes/datetime/timezone.cpp 2013-05-08 15:05:31 +0000
@@ -22,6 +22,7 @@
22#include <zorbatypes/timezone.h>22#include <zorbatypes/timezone.h>
2323
24#include "zorbatypes/datetime/parse.h"24#include "zorbatypes/datetime/parse.h"
25#include "zorbatypes/decimal.h"
2526
26#include "zorbautils/hashfun.h"27#include "zorbautils/hashfun.h"
2728
2829
=== modified file 'src/zorbatypes/decimal.cpp'
--- src/zorbatypes/decimal.cpp 2013-04-11 18:13:48 +0000
+++ src/zorbatypes/decimal.cpp 2013-05-08 15:05:31 +0000
@@ -23,19 +23,10 @@
23#include "util/ascii_util.h"23#include "util/ascii_util.h"
2424
25#include "decimal.h"25#include "decimal.h"
26#include "floatimpl.h"
26#include "integer.h"27#include "integer.h"
27#include "numconversions.h"28#include "numconversions.h"
2829
29#ifdef ZORBA_WITH_BIG_INTEGER
30# define TEMPLATE_DECL(T) /* nothing */
31# define INTEGER_IMPL(I) IntegerImpl
32#else
33# define TEMPLATE_DECL(T) template<typename T> /* spacer */
34# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */
35#endif /* ZORBA_WITH_BIG_INTEGER */
36#define INTEGER_IMPL_LL INTEGER_IMPL(long long)
37#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
38
39namespace zorba {30namespace zorba {
4031
41///////////////////////////////////////////////////////////////////////////////32///////////////////////////////////////////////////////////////////////////////
@@ -79,7 +70,6 @@
79 delete[] copy;70 delete[] copy;
80 } else71 } else
81 *result = first_non_ws;72 *result = first_non_ws;
82
83}73}
8474
85/**75/**
@@ -178,7 +168,6 @@
178 }168 }
179}169}
180170
181
182////////// constructors ///////////////////////////////////////////////////////171////////// constructors ///////////////////////////////////////////////////////
183172
184Decimal::Decimal( long long n ) {173Decimal::Decimal( long long n ) {
@@ -224,14 +213,16 @@
224 value_ = f.getNumber();213 value_ = f.getNumber();
225}214}
226215
227TEMPLATE_DECL(I)216template<class T>
228Decimal::Decimal( INTEGER_IMPL(I) const &i ) :217Decimal::Decimal( IntegerImpl<T> const &i ) : value_( i.itod() ) {
229 value_( i.itod() ) {
230}218}
231#ifndef ZORBA_WITH_BIG_INTEGER219
232template Decimal::Decimal( INTEGER_IMPL_LL const& );220// instantiate Decimal-from-Integer constructors
233template Decimal::Decimal( INTEGER_IMPL_ULL const& );221template Decimal::Decimal( Integer const& );
234#endif /* ZORBA_WITH_BIG_INTEGER */222template Decimal::Decimal( NegativeInteger const& );
223template Decimal::Decimal( NonNegativeInteger const& );
224template Decimal::Decimal( NonPositiveInteger const& );
225template Decimal::Decimal( PositiveInteger const& );
235226
236////////// assignment operators ///////////////////////////////////////////////227////////// assignment operators ///////////////////////////////////////////////
237228
@@ -247,15 +238,17 @@
247 return *this;238 return *this;
248}239}
249240
250TEMPLATE_DECL(I)241template<class T>
251Decimal& Decimal::operator=( INTEGER_IMPL(I) const &i ) {242Decimal& Decimal::operator=( IntegerImpl<T> const &i ) {
252 value_ = i.itod();243 value_ = i.itod();
253 return *this;244 return *this;
254}245}
255#ifndef ZORBA_WITH_BIG_INTEGER246
256template Decimal& Decimal::operator=( INTEGER_IMPL_LL const& );247template Decimal& Decimal::operator=( Integer const& );
257template Decimal& Decimal::operator=( INTEGER_IMPL_ULL const& );248template Decimal& Decimal::operator=( NegativeInteger const& );
258#endif /* ZORBA_WITH_BIG_INTEGER */249template Decimal& Decimal::operator=( NonNegativeInteger const& );
250template Decimal& Decimal::operator=( NonPositiveInteger const& );
251template Decimal& Decimal::operator=( PositiveInteger const& );
259252
260Decimal& Decimal::operator=( Double const &d ) {253Decimal& Decimal::operator=( Double const &d ) {
261 if ( !d.isFinite() )254 if ( !d.isFinite() )
@@ -273,20 +266,19 @@
273266
274////////// arithmetic operators ///////////////////////////////////////////////267////////// arithmetic operators ///////////////////////////////////////////////
275268
276#ifdef ZORBA_WITH_BIG_INTEGER269#define ZORBA_INSTANTIATE(OP,I) \
277# define ZORBA_INSTANTIATE(OP) /* nothing */270 template Decimal operator OP( Decimal const&, I const& )
278#else
279# define ZORBA_INSTANTIATE(OP) \
280 template Decimal operator OP( Decimal const&, INTEGER_IMPL_LL const& ); \
281 template Decimal operator OP( Decimal const&, INTEGER_IMPL_ULL const& )
282#endif /* ZORBA_WITH_BIG_INTEGER */
283271
284#define ZORBA_DECIMAL_OP(OP) \272#define ZORBA_DECIMAL_OP(OP) \
285 TEMPLATE_DECL(I) \273 template<class T> inline \
286 Decimal operator OP( Decimal const &d, INTEGER_IMPL(I) const &i ) { \274 Decimal operator OP( Decimal const &d, IntegerImpl<T> const &i ) { \
287 return d.value_ OP i.itod(); \275 return d.value_ OP i.itod(); \
288 } \276 } \
289 ZORBA_INSTANTIATE(OP)277 ZORBA_INSTANTIATE(OP,Integer); \
278 ZORBA_INSTANTIATE(OP,NegativeInteger); \
279 ZORBA_INSTANTIATE(OP,NonNegativeInteger); \
280 ZORBA_INSTANTIATE(OP,NonPositiveInteger); \
281 ZORBA_INSTANTIATE(OP,PositiveInteger);
290282
291ZORBA_DECIMAL_OP(+);283ZORBA_DECIMAL_OP(+);
292ZORBA_DECIMAL_OP(-);284ZORBA_DECIMAL_OP(-);
@@ -298,20 +290,19 @@
298290
299////////// relational operators ///////////////////////////////////////////////291////////// relational operators ///////////////////////////////////////////////
300292
301#ifdef ZORBA_WITH_BIG_INTEGER293#define ZORBA_INSTANTIATE(OP,I) \
302# define ZORBA_INSTANTIATE(OP) /* nothing */294 template bool operator OP( Decimal const&, I const& )
303#else
304# define ZORBA_INSTANTIATE(OP) \
305 template bool operator OP( Decimal const&, INTEGER_IMPL_LL const& ); \
306 template bool operator OP( Decimal const&, INTEGER_IMPL_ULL const& )
307#endif /* ZORBA_WITH_BIG_INTEGER */
308295
309#define ZORBA_DECIMAL_OP(OP) \296#define ZORBA_DECIMAL_OP(OP) \
310 TEMPLATE_DECL(I) \297 template<class T> inline \
311 bool operator OP( Decimal const &d, INTEGER_IMPL(I) const &i ) { \298 bool operator OP( Decimal const &d, IntegerImpl<T> const &i ) { \
312 return d.value_ OP i.itod(); \299 return d.value_ OP i.itod(); \
313 } \300 } \
314 ZORBA_INSTANTIATE(OP)301 ZORBA_INSTANTIATE( OP, Integer ); \
302 ZORBA_INSTANTIATE( OP, NegativeInteger ); \
303 ZORBA_INSTANTIATE( OP, NonNegativeInteger ); \
304 ZORBA_INSTANTIATE( OP, NonPositiveInteger ); \
305 ZORBA_INSTANTIATE( OP, PositiveInteger );
315306
316ZORBA_DECIMAL_OP(==);307ZORBA_DECIMAL_OP(==);
317ZORBA_DECIMAL_OP(!=);308ZORBA_DECIMAL_OP(!=);
@@ -325,17 +316,19 @@
325////////// math functions /////////////////////////////////////////////////////316////////// math functions /////////////////////////////////////////////////////
326317
327Decimal Decimal::round() const {318Decimal Decimal::round() const {
328 return round( INTEGER_IMPL_LL::zero() );319 return round( numeric_consts<xs_integer>::zero() );
329}320}
330321
331TEMPLATE_DECL(I)322template<class T>
332Decimal Decimal::round( INTEGER_IMPL(I) const &precision ) const {323Decimal Decimal::round( IntegerImpl<T> const &precision ) const {
333 return round2( value_, precision.itod() );324 return round2( value_, precision.itod() );
334}325}
335#ifndef ZORBA_WITH_BIG_INTEGER326
336template Decimal Decimal::round( INTEGER_IMPL_LL const& ) const;327template Decimal Decimal::round( Integer const& ) const;
337template Decimal Decimal::round( INTEGER_IMPL_ULL const& ) const;328template Decimal Decimal::round( NegativeInteger const& ) const;
338#endif /* ZORBA_WITH_BIG_INTEGER */329template Decimal Decimal::round( NonNegativeInteger const& ) const;
330template Decimal Decimal::round( NonPositiveInteger const& ) const;
331template Decimal Decimal::round( PositiveInteger const& ) const;
339332
340Decimal::value_type Decimal::round2( value_type const &v,333Decimal::value_type Decimal::round2( value_type const &v,
341 value_type const &precision ) {334 value_type const &precision ) {
@@ -352,14 +345,16 @@
352 return result;345 return result;
353}346}
354347
355TEMPLATE_DECL(I)348template<class T>
356Decimal Decimal::roundHalfToEven( INTEGER_IMPL(I) const &precision ) const {349Decimal Decimal::roundHalfToEven( IntegerImpl<T> const &precision ) const {
357 return roundHalfToEven2( value_, precision.itod() );350 return roundHalfToEven2( value_, precision.itod() );
358}351}
359#ifndef ZORBA_WITH_BIG_INTEGER352
360template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_LL const& ) const;353template Decimal Decimal::roundHalfToEven( Integer const& ) const;
361template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_ULL const& ) const;354template Decimal Decimal::roundHalfToEven( NegativeInteger const& ) const;
362#endif /* ZORBA_WITH_BIG_INTEGER */355template Decimal Decimal::roundHalfToEven( NonNegativeInteger const& ) const;
356template Decimal Decimal::roundHalfToEven( NonPositiveInteger const& ) const;
357template Decimal Decimal::roundHalfToEven( PositiveInteger const& ) const;
363358
364Decimal::value_type Decimal::roundHalfToEven2( value_type const &v,359Decimal::value_type Decimal::roundHalfToEven2( value_type const &v,
365 value_type const &precision ) {360 value_type const &precision ) {
@@ -425,21 +420,15 @@
425 return static_cast<uint32_t>( n );420 return static_cast<uint32_t>( n );
426}421}
427422
428Decimal const& Decimal::one() {423zstring Decimal::toString( value_type const &value, bool minusZero,
429 static Decimal d(1);424 int precision ) {
430 return d;
431}
432
433zstring Decimal::toString( value_type const &value, int precision ) {
434 return toString(value, false, precision);
435}
436
437zstring Decimal::toString( value_type const &value, bool minusZero, int precision ) {
438 char buf[ 1024 ];425 char buf[ 1024 ];
439426
440 if ( minusZero )427 if ( minusZero ) {
441 {428 if ( value.sign() == 0 )
442 buf[0] = '-';429 buf[0] = '-';
430 else
431 minusZero = false;
443 }432 }
444433
445 value.toFixPtString( buf + minusZero, precision );434 value.toFixPtString( buf + minusZero, precision );
@@ -464,11 +453,6 @@
464 return buf;453 return buf;
465}454}
466455
467Decimal const& Decimal::zero() {
468 static Decimal d(0);
469 return d;
470}
471
472///////////////////////////////////////////////////////////////////////////////456///////////////////////////////////////////////////////////////////////////////
473457
474} // namespace zorba458} // namespace zorba
475459
=== modified file 'src/zorbatypes/decimal.h'
--- src/zorbatypes/decimal.h 2013-04-11 18:13:48 +0000
+++ src/zorbatypes/decimal.h 2013-05-08 15:05:31 +0000
@@ -28,14 +28,6 @@
28#include "zorbatypes_decl.h"28#include "zorbatypes_decl.h"
29#include "zstring.h"29#include "zstring.h"
3030
31#ifdef ZORBA_WITH_BIG_INTEGER
32# define TEMPLATE_DECL(I) /* nothing */
33# define INTEGER_IMPL(I) IntegerImpl
34#else
35# define TEMPLATE_DECL(I) template<typename I> /* spacer */
36# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */
37#endif /* ZORBA_WITH_BIG_INTEGER */
38
39namespace zorba {31namespace zorba {
4032
41class Decimal;33class Decimal;
@@ -72,8 +64,8 @@
72 explicit Decimal( float n );64 explicit Decimal( float n );
73 explicit Decimal( double n );65 explicit Decimal( double n );
7466
75 TEMPLATE_DECL(I)67 template<class T>
76 explicit Decimal( INTEGER_IMPL(I) const &i );68 explicit Decimal( IntegerImpl<T> const &i );
7769
78 /**70 /**
79 * Constructs a %Decimal from a C string.71 * Constructs a %Decimal from a C string.
@@ -133,8 +125,8 @@
133 Decimal& operator=( Double const &d );125 Decimal& operator=( Double const &d );
134 Decimal& operator=( Float const &f );126 Decimal& operator=( Float const &f );
135127
136 TEMPLATE_DECL(I)128 template<class T>
137 Decimal& operator=( INTEGER_IMPL(I) const &i );129 Decimal& operator=( IntegerImpl<T> const &i );
138130
139 ////////// arithmetic operators /////////////////////////////////////////////131 ////////// arithmetic operators /////////////////////////////////////////////
140132
@@ -145,11 +137,11 @@
145 friend Decimal operator%( Decimal const&, Decimal const& );137 friend Decimal operator%( Decimal const&, Decimal const& );
146138
147#define ZORBA_DECIMAL_OP(OP) \139#define ZORBA_DECIMAL_OP(OP) \
148 TEMPLATE_DECL(I) \140 template<class T> \
149 friend Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \141 friend Decimal operator OP( Decimal const&, IntegerImpl<T> const& ); \
150 \142 \
151 TEMPLATE_DECL(I) \143 template<class T> \
152 friend Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& )144 friend Decimal operator OP( IntegerImpl<T> const&, Decimal const& )
153145
154 ZORBA_DECIMAL_OP(+);146 ZORBA_DECIMAL_OP(+);
155 ZORBA_DECIMAL_OP(-);147 ZORBA_DECIMAL_OP(-);
@@ -165,7 +157,7 @@
165 Decimal& operator%=( Decimal const& );157 Decimal& operator%=( Decimal const& );
166158
167#define ZORBA_DECIMAL_OP(OP) \159#define ZORBA_DECIMAL_OP(OP) \
168 TEMPLATE_DECL(I) Decimal& operator OP( INTEGER_IMPL(I) const& )160 template<class T> Decimal& operator OP( IntegerImpl<T> const& )
169161
170 ZORBA_DECIMAL_OP(+=);162 ZORBA_DECIMAL_OP(+=);
171 ZORBA_DECIMAL_OP(-=);163 ZORBA_DECIMAL_OP(-=);
@@ -178,12 +170,12 @@
178170
179 ////////// relational operators /////////////////////////////////////////////171 ////////// relational operators /////////////////////////////////////////////
180172
181#define ZORBA_DECIMAL_OP(OP) \173#define ZORBA_DECIMAL_OP(OP) \
182 friend bool operator OP( Decimal const&, Decimal const& ); \174 friend bool operator OP( Decimal const&, Decimal const& ); \
183 TEMPLATE_DECL(I) \175 template<class T> \
184 friend bool operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \176 friend bool operator OP( Decimal const&, IntegerImpl<T> const& ); \
185 TEMPLATE_DECL(I) \177 template<class T> \
186 friend bool operator OP( INTEGER_IMPL(I) const&, Decimal const& )178 friend bool operator OP( IntegerImpl<T> const&, Decimal const& )
187179
188 ZORBA_DECIMAL_OP(==);180 ZORBA_DECIMAL_OP(==);
189 ZORBA_DECIMAL_OP(!=);181 ZORBA_DECIMAL_OP(!=);
@@ -201,11 +193,11 @@
201 Decimal floor() const;193 Decimal floor() const;
202 Decimal round() const;194 Decimal round() const;
203195
204 TEMPLATE_DECL(I)196 template<class T>
205 Decimal round( INTEGER_IMPL(I) const &precision ) const;197 Decimal round( IntegerImpl<T> const &precision ) const;
206198
207 TEMPLATE_DECL(I)199 template<class T>
208 Decimal roundHalfToEven( INTEGER_IMPL(I) const &precision ) const;200 Decimal roundHalfToEven( IntegerImpl<T> const &precision ) const;
209201
210 Decimal sqrt() const;202 Decimal sqrt() const;
211203
@@ -223,9 +215,6 @@
223215
224 zstring toString( int precision = ZORBA_FLOAT_POINT_PRECISION ) const;216 zstring toString( int precision = ZORBA_FLOAT_POINT_PRECISION ) const;
225217
226 static Decimal const& one();
227 static Decimal const& zero();
228
229 /////////////////////////////////////////////////////////////////////////////218 /////////////////////////////////////////////////////////////////////////////
230219
231private:220private:
@@ -254,13 +243,15 @@
254 static value_type roundHalfToEven2( value_type const &v,243 static value_type roundHalfToEven2( value_type const &v,
255 value_type const &precision );244 value_type const &precision );
256245
257 static zstring toString( value_type const&,246 static zstring toString( value_type const &value,
258 int precision = ZORBA_FLOAT_POINT_PRECISION );247 int precision = ZORBA_FLOAT_POINT_PRECISION ) {
248 return toString( value, false, precision );
249 }
259250
260 static zstring toString( value_type const&, bool,251 static zstring toString( value_type const&, bool,
261 int precision = ZORBA_FLOAT_POINT_PRECISION );252 int precision = ZORBA_FLOAT_POINT_PRECISION );
262253
263 TEMPLATE_DECL(I) friend class IntegerImpl;254 template<class T> friend class IntegerImpl;
264 template<typename F> friend class FloatImpl;255 template<typename F> friend class FloatImpl;
265256
266 friend xs_long to_xs_long( Decimal const& );257 friend xs_long to_xs_long( Decimal const& );
@@ -429,9 +420,6 @@
429420
430} // namespace zorba421} // namespace zorba
431422
432#undef TEMPLATE_DECL
433#undef INTEGER_IMPL
434
435#endif /* ZORBA_DECIMAL_H */423#endif /* ZORBA_DECIMAL_H */
436/*424/*
437 * Local variables:425 * Local variables:
438426
=== modified file 'src/zorbatypes/duration.h'
--- src/zorbatypes/duration.h 2013-02-07 17:24:36 +0000
+++ src/zorbatypes/duration.h 2013-05-08 15:05:31 +0000
@@ -18,10 +18,10 @@
18#define ZORBA_TYPES_DURATION_H18#define ZORBA_TYPES_DURATION_H
1919
20#include <zorba/config.h>20#include <zorba/config.h>
21#include "zorbatypes/zorbatypes_decl.h"21#include "zorbatypes_decl.h"
22#include "zorbatypes/schema_types.h"
2322
24#include "util/ascii_util.h"23#include "util/ascii_util.h"
24#include "zorbatypes/zstring.h"
2525
26namespace zorba26namespace zorba
27{27{
@@ -175,9 +175,9 @@
175175
176 Duration* operator-(const Duration& d) const;176 Duration* operator-(const Duration& d) const;
177177
178 Duration* operator*(const xs_double& value) const;178 Duration* operator*(const Double& value) const;
179179
180 Duration* operator/(const xs_double& value) const;180 Duration* operator/(const Double& value) const;
181181
182 Decimal operator/(const Duration& d) const;182 Decimal operator/(const Duration& d) const;
183183
@@ -195,13 +195,13 @@
195195
196 virtual long getMinutes() const;196 virtual long getMinutes() const;
197197
198 virtual xs_decimal getSeconds() const;198 virtual Decimal getSeconds() const;
199199
200 virtual long getFractionalSeconds() const;200 virtual long getFractionalSeconds() const;
201201
202 virtual long getIntSeconds() const;202 virtual long getIntSeconds() const;
203203
204 xs_double getTotalSeconds() const;204 Double getTotalSeconds() const;
205205
206 long getTotalMilliseconds() const;206 long getTotalMilliseconds() const;
207207
208208
=== modified file 'src/zorbatypes/floatimpl.cpp'
--- src/zorbatypes/floatimpl.cpp 2013-04-02 21:31:04 +0000
+++ src/zorbatypes/floatimpl.cpp 2013-05-08 15:05:31 +0000
@@ -30,16 +30,6 @@
30#include "zorbaserialization/serialize_zorba_types.h"30#include "zorbaserialization/serialize_zorba_types.h"
31#include "zorbaserialization/serialize_template_types.h"31#include "zorbaserialization/serialize_template_types.h"
3232
33#ifdef ZORBA_WITH_BIG_INTEGER
34# define TEMPLATE_DECL(T) /* nothing */
35# define INTEGER_IMPL(I) IntegerImpl
36#else
37# define TEMPLATE_DECL(T) template<typename T> /* spacer */
38# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */
39#endif /* ZORBA_WITH_BIG_INTEGER */
40#define INTEGER_IMPL_LL INTEGER_IMPL(long long)
41#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
42
43///////////////////////////////////////////////////////////////////////////////33///////////////////////////////////////////////////////////////////////////////
4434
45namespace zorba {35namespace zorba {
@@ -72,8 +62,8 @@
72 }62 }
73}63}
7464
75template<typename FloatType>65template<typename F>
76void FloatImpl<FloatType>::parse( char const *s ) {66void FloatImpl<F>::parse( char const *s ) {
77 if ( !*s )67 if ( !*s )
78 throw std::invalid_argument( "empty string" );68 throw std::invalid_argument( "empty string" );
7969
@@ -151,80 +141,87 @@
151141
152////////// constructors ///////////////////////////////////////////////////////142////////// constructors ///////////////////////////////////////////////////////
153143
154template<typename FloatType>144template<typename F>
155FloatImpl<FloatType>::FloatImpl( Decimal const &d ) {145FloatImpl<F>::FloatImpl( Decimal const &d ) {
156 zstring const temp( d.toString() );146 zstring const temp( d.toString() );
157 parse( temp.c_str() );147 parse( temp.c_str() );
158}148}
159149
160template<typename FloatType>150template<typename F>
161TEMPLATE_DECL(IntType)151template<class T>
162FloatImpl<FloatType>::FloatImpl( INTEGER_IMPL(IntType) const &i ) {152FloatImpl<F>::FloatImpl( IntegerImpl<T> const &i ) {
163 zstring const temp( i.toString() );153 zstring const temp( i.toString() );
164 parse( temp.c_str() );154 parse( temp.c_str() );
165}155}
166156
167#ifndef ZORBA_WITH_BIG_INTEGER157template FloatImpl<float>::FloatImpl( Integer const& );
168template FloatImpl<float>::FloatImpl( INTEGER_IMPL_LL const& );158template FloatImpl<float>::FloatImpl( NegativeInteger const& );
169template FloatImpl<float>::FloatImpl( INTEGER_IMPL_ULL const& );159template FloatImpl<float>::FloatImpl( NonNegativeInteger const& );
160template FloatImpl<float>::FloatImpl( NonPositiveInteger const& );
161template FloatImpl<float>::FloatImpl( PositiveInteger const& );
170162
171template FloatImpl<double>::FloatImpl( INTEGER_IMPL_LL const& );163template FloatImpl<double>::FloatImpl( Integer const& );
172template FloatImpl<double>::FloatImpl( INTEGER_IMPL_ULL const& );164template FloatImpl<double>::FloatImpl( NegativeInteger const& );
173#endif /* ZORBA_WITH_BIG_INTEGER */165template FloatImpl<double>::FloatImpl( NonNegativeInteger const& );
166template FloatImpl<double>::FloatImpl( NonPositiveInteger const& );
167template FloatImpl<double>::FloatImpl( PositiveInteger const& );
174168
175////////// assignment operators ///////////////////////////////////////////////169////////// assignment operators ///////////////////////////////////////////////
176170
177template<typename FloatType>171template<typename F>
178FloatImpl<FloatType>& FloatImpl<FloatType>::operator=( Decimal const &d ) {172FloatImpl<F>& FloatImpl<F>::operator=( Decimal const &d ) {
179 zstring const temp( d.toString() );173 zstring const temp( d.toString() );
180 parse( temp.c_str() );174 parse( temp.c_str() );
181 return *this;175 return *this;
182}176}
183177
184template<typename FloatType>178template<typename F>
185TEMPLATE_DECL(IntType)179template<class T>
186FloatImpl<FloatType>&180FloatImpl<F>& FloatImpl<F>::operator=( IntegerImpl<T> const &i ) {
187FloatImpl<FloatType>::operator=( INTEGER_IMPL(IntType) const &i ) {
188 zstring const temp( i.toString() );181 zstring const temp( i.toString() );
189 parse( temp.c_str() );182 parse( temp.c_str() );
190 return *this;183 return *this;
191}184}
192185
193#ifndef ZORBA_WITH_BIG_INTEGER186#define ZORBA_INSTANTIATE(F,I) \
194template187 template FloatImpl<F>& FloatImpl<F>::operator=( I const& )
195FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_LL const& );188
196189ZORBA_INSTANTIATE(float,Integer);
197template190ZORBA_INSTANTIATE(float,NegativeInteger);
198FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_ULL const& );191ZORBA_INSTANTIATE(float,NonNegativeInteger);
199192ZORBA_INSTANTIATE(float,NonPositiveInteger);
200template193ZORBA_INSTANTIATE(float,PositiveInteger);
201FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_LL const& );194
202195ZORBA_INSTANTIATE(double,Integer);
203template196ZORBA_INSTANTIATE(double,NegativeInteger);
204FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_ULL const& );197ZORBA_INSTANTIATE(double,NonNegativeInteger);
205#endif /* ZORBA_WITH_BIG_INTEGER */198ZORBA_INSTANTIATE(double,NonPositiveInteger);
199ZORBA_INSTANTIATE(double,PositiveInteger);
200#undef ZORBA_INSTANTIATE
206201
207////////// math functions /////////////////////////////////////////////////////202////////// math functions /////////////////////////////////////////////////////
208203
209template<typename FloatType>204template<typename F>
210FloatImpl<FloatType> FloatImpl<FloatType>::acos() const {205FloatImpl<F> FloatImpl<F>::acos() const {
211 if ( *this < neg_one() || *this > one() )206 if ( *this < numeric_consts<FloatImpl>::neg_one() ||
207 *this > numeric_consts<FloatImpl>::one() )
212 return nan();208 return nan();
213 return FloatImpl<FloatType>(209 return FloatImpl<F>(
214 isNegZero() ? -std::acos( value_ ): std::acos( value_ )210 isNegZero() ? -std::acos( value_ ) : std::acos( value_ )
215 );211 );
216}212}
217213
218template<typename FloatType>214template<typename F>
219FloatImpl<FloatType> FloatImpl<FloatType>::asin() const {215FloatImpl<F> FloatImpl<F>::asin() const {
220 if ( *this < neg_one() || *this > one() )216 if ( *this < numeric_consts<FloatImpl>::neg_one() ||
217 *this > numeric_consts<FloatImpl>::one() )
221 return nan();218 return nan();
222 return FloatImpl<FloatType>( std::asin( value_ ) );219 return FloatImpl<F>( std::asin( value_ ) );
223}220}
224221
225template<typename FloatType>222template<typename F>
226void FloatImpl<FloatType>::frexp( FloatImpl<FloatType> &out_mantissa,223void FloatImpl<F>::frexp( FloatImpl<F> &out_mantissa,
227 Integer &out_exponent ) const {224 Integer &out_exponent ) const {
228 int expint;225 int expint;
229 out_mantissa = FloatImpl( ::frexp( value_, &expint ) );226 out_mantissa = FloatImpl( ::frexp( value_, &expint ) );
230 out_exponent = Integer( expint );227 out_exponent = Integer( expint );
@@ -246,13 +243,13 @@
246 out_integer = int_part;243 out_integer = int_part;
247}244}
248245
249template<typename FloatType>246template<typename F>
250FloatImpl<FloatType> FloatImpl<FloatType>::round() const {247FloatImpl<F> FloatImpl<F>::round() const {
251 return round( Integer::zero() );248 return round( numeric_consts<xs_integer>::zero() );
252}249}
253250
254template<typename FloatType>251template<typename F>
255FloatImpl<FloatType> FloatImpl<FloatType>::round( Integer const &precision ) const {252FloatImpl<F> FloatImpl<F>::round( Integer const &precision ) const {
256 FloatImpl result;253 FloatImpl result;
257 if ( isFinite() && !isZero() ) {254 if ( isFinite() && !isZero() ) {
258 MAPM m(255 MAPM m(
@@ -274,8 +271,8 @@
274 return result;271 return result;
275}272}
276273
277template<typename FloatType> FloatImpl<FloatType>274template<typename F>
278FloatImpl<FloatType>::roundHalfToEven( Integer const &precision) const {275FloatImpl<F> FloatImpl<F>::roundHalfToEven( Integer const &precision ) const {
279 FloatImpl result;276 FloatImpl result;
280 if ( isFinite() && !isZero() ) {277 if ( isFinite() && !isZero() ) {
281 MAPM m(278 MAPM m(
@@ -318,48 +315,32 @@
318 return false;315 return false;
319}316}
320317
321template<typename FloatType>318template<typename F>
322FloatImpl<FloatType> const& FloatImpl<FloatType>::nan() {319FloatImpl<F> const& FloatImpl<F>::nan() {
323 static FloatImpl<FloatType> const value( std::sqrt( -1.0 ) );320 static FloatImpl<F> const value( std::sqrt( -1.0 ) );
324 return value;321 return value;
325}322}
326323
327template<typename FloatType>324template<typename F>
328FloatImpl<FloatType> const& FloatImpl<FloatType>::neg_inf() {325FloatImpl<F> const& FloatImpl<F>::neg_inf() {
329 static FloatImpl<FloatType> const value(326 static FloatImpl<F> const value( -std::numeric_limits<F>::infinity() );
330 -std::numeric_limits<FloatType>::infinity()327 return value;
331 );328}
332 return value;329
333}330template<typename F>
334331FloatImpl<F> const& FloatImpl<F>::neg_zero() {
335template<typename FloatType>332 static FloatImpl<F> const value( -0.0 );
336FloatImpl<FloatType> const& FloatImpl<FloatType>::neg_one() {333 return value;
337 static FloatImpl<FloatType> const value( -1 );334}
338 return value;335
339}336template<typename F>
340337FloatImpl<F> const& FloatImpl<F>::pos_inf() {
341template<typename FloatType>338 static FloatImpl<F> const value( std::numeric_limits<F>::infinity() );
342FloatImpl<FloatType> const& FloatImpl<FloatType>::neg_zero() {339 return value;
343 static FloatImpl<FloatType> const value( -0.0 );340}
344 return value;341
345}342template<typename F>
346343zstring FloatImpl<F>::toIntegerString() const {
347template<typename FloatType>
348FloatImpl<FloatType> const& FloatImpl<FloatType>::one() {
349 static FloatImpl<FloatType> const value( 1 );
350 return value;
351}
352
353template<typename FloatType>
354FloatImpl<FloatType> const& FloatImpl<FloatType>::pos_inf() {
355 static FloatImpl<FloatType> const value(
356 std::numeric_limits<FloatType>::infinity()
357 );
358 return value;
359}
360
361template<typename FloatType>
362zstring FloatImpl<FloatType>::toIntegerString() const {
363 if ( isNaN() )344 if ( isNaN() )
364 return nan_str();345 return nan_str();
365 if (isPosInf() )346 if (isPosInf() )
@@ -377,8 +358,8 @@
377 return buf;358 return buf;
378}359}
379360
380template<typename FloatType>361template<typename F>
381zstring FloatImpl<FloatType>::toString( bool no_scientific_format ) const {362zstring FloatImpl<F>::toString( bool no_scientific_format ) const {
382 if ( isNaN() )363 if ( isNaN() )
383 return nan_str();364 return nan_str();
384 if ( isPosInf() )365 if ( isPosInf() )
@@ -390,17 +371,17 @@
390 if ( isNegZero() )371 if ( isNegZero() )
391 return "-0";372 return "-0";
392373
393 FloatType const absVal = fabs( value_ );374 value_type const abs_val = fabs( value_ );
394 FloatType const lower = 0.000001f, upper = 1000000.0f;375 value_type const lower = 0.000001f, upper = 1000000.0f;
395376
396 if (no_scientific_format || (absVal < upper && absVal >= lower) || absVal == 0)377 if ( no_scientific_format || (abs_val >= lower && abs_val < upper) ||
397 {378 abs_val == 0 ) {
398#if 1379#if 1
399 // This is the "spec" implementation, i.e., it is an exact application of380 // This is the "spec" implementation, i.e., it is an exact application of
400 // the spec in http://www.w3.org/TR/xpath-functions/#casting381 // the spec in http://www.w3.org/TR/xpath-functions/#casting
401 MAPM decimal_mapm( value_ );382 MAPM decimal_mapm( value_ );
402 decimal_mapm = decimal_mapm.round( precision_ );383 decimal_mapm = decimal_mapm.round( precision_ );
403 return Decimal::toString(decimal_mapm, isNegZero(), max_precision());384 return Decimal::toString( decimal_mapm, isNegZero(), max_precision() );
404#else385#else
405 std::stringstream stream;386 std::stringstream stream;
406 stream.precision(7);387 stream.precision(7);
@@ -471,12 +452,6 @@
471 }452 }
472}453}
473454
474template<typename FloatType>
475FloatImpl<FloatType> const& FloatImpl<FloatType>::zero() {
476 static FloatImpl<FloatType> const value( 0 );
477 return value;
478}
479
480///////////////////////////////////////////////////////////////////////////////455///////////////////////////////////////////////////////////////////////////////
481456
482template class FloatImpl<double>;457template class FloatImpl<double>;
483458
=== modified file 'src/zorbatypes/floatimpl.h'
--- src/zorbatypes/floatimpl.h 2013-04-09 01:29:36 +0000
+++ src/zorbatypes/floatimpl.h 2013-05-08 15:05:31 +0000
@@ -29,14 +29,6 @@
29#include "schema_types.h"29#include "schema_types.h"
30#include "zorbatypes_decl.h"30#include "zorbatypes_decl.h"
3131
32#ifdef ZORBA_WITH_BIG_INTEGER
33# define TEMPLATE_DECL(I) /* nothing */
34# define INTEGER_IMPL(I) IntegerImpl
35#else
36# define TEMPLATE_DECL(I) template<typename I> /* spacer */
37# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */
38#endif /* ZORBA_WITH_BIG_INTEGER */
39
40namespace zorba {32namespace zorba {
4133
42template<typename FloatType>34template<typename FloatType>
@@ -71,8 +63,8 @@
71 explicit FloatImpl( double n );63 explicit FloatImpl( double n );
72 explicit FloatImpl( Decimal const &d );64 explicit FloatImpl( Decimal const &d );
7365
74 TEMPLATE_DECL(IntType)66 template<class T>
75 explicit FloatImpl( INTEGER_IMPL(IntType) const &i );67 explicit FloatImpl( IntegerImpl<T> const &i );
7668
77 /**69 /**
78 * Constructs a %FloatImpl from a C string.70 * Constructs a %FloatImpl from a C string.
@@ -126,8 +118,8 @@
126 FloatImpl& operator=( char const *s );118 FloatImpl& operator=( char const *s );
127 FloatImpl& operator=( Decimal const &d );119 FloatImpl& operator=( Decimal const &d );
128120
129 TEMPLATE_DECL(I)121 template<class T>
130 FloatImpl& operator=( INTEGER_IMPL(I) const &i );122 FloatImpl& operator=( IntegerImpl<T> const &i );
131123
132 ////////// arithmetic operators /////////////////////////////////////////////124 ////////// arithmetic operators /////////////////////////////////////////////
133125
@@ -269,11 +261,9 @@
269 bool isPosZero() const;261 bool isPosZero() const;
270 bool isNegZero() const;262 bool isNegZero() const;
271 bool isInteger() const;263 bool isInteger() const;
264 int sign() const;
272265
273 static FloatImpl const& zero();
274 static FloatImpl const& neg_zero();266 static FloatImpl const& neg_zero();
275 static FloatImpl const& one();
276 static FloatImpl const& neg_one();
277 static FloatImpl const& nan();267 static FloatImpl const& nan();
278 static FloatImpl const& pos_inf();268 static FloatImpl const& pos_inf();
279 static FloatImpl const& neg_inf();269 static FloatImpl const& neg_inf();
@@ -283,7 +273,6 @@
283 }273 }
284274
285 zstring toIntegerString() const;275 zstring toIntegerString() const;
286
287 zstring toString( bool no_scientific_mode = false ) const;276 zstring toString( bool no_scientific_mode = false ) const;
288277
289 /////////////////////////////////////////////////////////////////////////////278 /////////////////////////////////////////////////////////////////////////////
@@ -298,14 +287,12 @@
298 value_type value_;287 value_type value_;
299 precision_type precision_;288 precision_type precision_;
300289
301 FloatImpl( value_type v, precision_type p );
302
303 static precision_type max_precision();290 static precision_type max_precision();
304291
305 void parse( char const* );292 void parse( char const* );
306 bool parse_etc( char const* );293 bool parse_etc( char const* );
307294
308 TEMPLATE_DECL(I) friend class IntegerImpl;295 template<class T> friend class IntegerImpl;
309 friend class Decimal;296 friend class Decimal;
310297
311 friend class FloatImpl<float>;298 friend class FloatImpl<float>;
@@ -412,24 +399,19 @@
412 parse( s );399 parse( s );
413}400}
414401
415template<typename F> template<typename G>402template<typename F>
403template<typename G>
416inline FloatImpl<F>::FloatImpl( FloatImpl<G> const &f ) :404inline FloatImpl<F>::FloatImpl( FloatImpl<G> const &f ) :
417 value_( static_cast<F>( f.value_ ) ), precision_( max_precision() )405 value_( static_cast<F>( f.value_ ) ), precision_( max_precision() )
418{406{
419}407}
420408
421template<typename F>
422inline FloatImpl<F>::FloatImpl( value_type v, precision_type p ) :
423 value_( v ), precision_( p )
424{
425}
426
427////////// assignment operators ///////////////////////////////////////////////409////////// assignment operators ///////////////////////////////////////////////
428410
429template<typename F> template<typename G>411template<typename F>
412template<typename G>
430inline FloatImpl<F>& FloatImpl<F>::operator=( FloatImpl<G> const &f ) {413inline FloatImpl<F>& FloatImpl<F>::operator=( FloatImpl<G> const &f ) {
431 value_ = static_cast<F>( f.value_ );414 value_ = static_cast<F>( f.value_ );
432 precision_ = max_precision();
433 return *this;415 return *this;
434}416}
435417
@@ -437,7 +419,6 @@
437 template<typename F> \419 template<typename F> \
438 inline FloatImpl<F>& FloatImpl<F>::operator=( T n ) { \420 inline FloatImpl<F>& FloatImpl<F>::operator=( T n ) { \
439 value_ = static_cast<F>( n ); \421 value_ = static_cast<F>( n ); \
440 precision_ = max_precision(); \
441 return *this; \422 return *this; \
442 }423 }
443424
@@ -668,7 +649,8 @@
668ZORBA_FLOAT_OP(/=)649ZORBA_FLOAT_OP(/=)
669#undef ZORBA_FLOAT_OP650#undef ZORBA_FLOAT_OP
670651
671template<typename F> template<typename G>652template<typename F>
653template<typename G>
672inline FloatImpl<F>& FloatImpl<F>::operator%=( FloatImpl<G> const &f ) {654inline FloatImpl<F>& FloatImpl<F>::operator%=( FloatImpl<G> const &f ) {
673 value_ = std::fmod( value_, static_cast<F>( f.value_ ) );655 value_ = std::fmod( value_, static_cast<F>( f.value_ ) );
674 return *this;656 return *this;
@@ -676,7 +658,7 @@
676658
677template<typename F>659template<typename F>
678inline FloatImpl<F> FloatImpl<F>::operator-() const {660inline FloatImpl<F> FloatImpl<F>::operator-() const {
679 return FloatImpl<F>( -value_, precision_ );661 return FloatImpl<F>( -value_ );
680}662}
681663
682#define ZORBA_FLOAT_OP(OP) \664#define ZORBA_FLOAT_OP(OP) \
@@ -932,7 +914,8 @@
932914
933////////// miscellaneous //////////////////////////////////////////////////////915////////// miscellaneous //////////////////////////////////////////////////////
934916
935template<typename F> template<typename G>917template<typename F>
918template<typename G>
936inline int FloatImpl<F>::compare( FloatImpl<G> const &f ) const {919inline int FloatImpl<F>::compare( FloatImpl<G> const &f ) const {
937 return value_ < f.value_ ? -1 : value_ > f.value_ ? 1 : 0;920 return value_ < f.value_ ? -1 : value_ > f.value_ ? 1 : 0;
938}921}
@@ -987,12 +970,17 @@
987 return isFinite() && ::floor( value_ ) == value_;970 return isFinite() && ::floor( value_ ) == value_;
988}971}
989972
990template <typename F>973template<typename F>
991inline bool FloatImpl<F>::isZero() const {974inline bool FloatImpl<F>::isZero() const {
992 return value_ == 0;975 return value_ == 0;
993}976}
994977
995template<typename F>978template<typename F>
979inline int FloatImpl<F>::sign() const {
980 return value_ > 0 ? 1 : value_ < 0 ? -1 : 0;
981}
982
983template<typename F>
996inline std::ostream& operator<<( std::ostream &os, FloatImpl<F> const &f ) {984inline std::ostream& operator<<( std::ostream &os, FloatImpl<F> const &f ) {
997 return os << f.toString();985 return os << f.toString();
998}986}
@@ -1001,9 +989,6 @@
1001989
1002} // namespace zorba990} // namespace zorba
1003991
1004#undef TEMPLATE_DECL
1005#undef INTEGER_IMPL
1006
1007#endif // ZORBA_FLOATIMPL_H992#endif // ZORBA_FLOATIMPL_H
1008/*993/*
1009 * Local variables:994 * Local variables:
1010995
=== modified file 'src/zorbatypes/integer.cpp'
--- src/zorbatypes/integer.cpp 2013-04-09 22:38:19 +0000
+++ src/zorbatypes/integer.cpp 2013-05-08 15:05:31 +0000
@@ -16,166 +16,185 @@
1616
17#include "stdafx.h"17#include "stdafx.h"
1818
19// standard
19#include <cerrno>20#include <cerrno>
20#include <cstdlib>21#include <cstdlib>
22#include <sstream>
2123
24// Zorba
22#include <zorba/internal/unique_ptr.h>25#include <zorba/internal/unique_ptr.h>
23#include "util/cxx_util.h"26#include "util/cxx_util.h"
24#include "util/string_util.h"27#include "util/string_util.h"
2528
26#include "integer.h"29// local
27#include "decimal.h"30#include "decimal.h"
28#include "floatimpl.h"31#include "floatimpl.h"
32#include "integer.h"
29#include "numconversions.h"33#include "numconversions.h"
3034
31#ifdef ZORBA_WITH_BIG_INTEGER
32# define TEMPLATE_DECL(T) /* nothing */
33# define INTEGER_IMPL(T) IntegerImpl
34#else
35# define TEMPLATE_DECL(T) template<typename T> /* spacer */
36# define INTEGER_IMPL(T) IntegerImpl<T> /* spacer */
37#endif /* ZORBA_WITH_BIG_INTEGER */
38#define INTEGER_IMPL_LL INTEGER_IMPL(long long)
39#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
40
41using namespace std;35using namespace std;
4236
43#ifndef ZORBA_WITH_BIG_INTEGER
44unsigned long long MaxUIntegerValue = ~0ull >> 1;
45
46inline bool is_too_big( long long ) {
47 return false;
48}
49
50inline bool is_too_big( unsigned long long n ) {
51 return n > MaxUIntegerValue;
52}
53#endif /* ZORBA_WITH_BIG_INTEGER */
54
55namespace zorba {37namespace zorba {
5638
57///////////////////////////////////////////////////////////////////////////////39///////////////////////////////////////////////////////////////////////////////
5840
59TEMPLATE_DECL(I)41ostream& operator<<( ostream &o, MAPM const &m ) {
60void INTEGER_IMPL(I)::parse( char const *s ) {42 unique_ptr<char[]> const buf( new char[ m.exponent() + 3 ] );
43 m.toIntegerString( buf.get() );
44 return o << buf.get();
45}
46
47void integer_traits::throw_error( string const &what, bool throw_range_error ) {
48 if ( throw_range_error )
49 throw range_error( what );
50 throw invalid_argument( what );
51}
52
53void integer_traits::throw_error( MAPM const &n, char const *op,
54 bool throw_range_error ) {
55 ostringstream oss;
56 oss << n;
57 string const what( BUILD_STRING( oss.str(), ": not ", op, " 0" ) );
58 throw_error( what, throw_range_error );
59}
60
61///////////////////////////////////////////////////////////////////////////////
62
63template<class T>
64void IntegerImpl<T>::parse( char const *s, bool throw_range_error ) {
61#ifdef ZORBA_WITH_BIG_INTEGER65#ifdef ZORBA_WITH_BIG_INTEGER
62 Decimal::parse( s, &value_, Decimal::parse_integer );66 Decimal::parse( s, &value_, Decimal::parse_integer );
63#else67#else
64 value_type const temp( ztd::aton<value_type>( s ) );68 try {
65 if ( is_too_big( temp ) )69 value_ = ztd::aton<value_type>( s );
66 throw std::invalid_argument(70 }
67 BUILD_STRING( '"', temp, "\": unsigned integer too big" )71 catch ( std::range_error const &e ) {
68 );72 if ( throw_range_error )
69 value_ = temp;73 throw;
74 throw invalid_argument( e.what() );
75 }
70#endif /* ZORBA_WITH_BIG_INTEGER */76#endif /* ZORBA_WITH_BIG_INTEGER */
77 T::check_value( value_, throw_range_error );
71}78}
7279
73////////// constructors ///////////////////////////////////////////////////////80////////// constructors ///////////////////////////////////////////////////////
7481
75#ifdef ZORBA_WITH_BIG_INTEGER82#ifdef ZORBA_WITH_BIG_INTEGER
76IntegerImpl::IntegerImpl( long long n ) {83template<class T>
84IntegerImpl<T>::IntegerImpl( long long n ) {
77 ascii::itoa_buf_type buf;85 ascii::itoa_buf_type buf;
78 value_ = ascii::itoa( n, buf );86 value_ = ascii::itoa( n, buf );
87 T::check_value( value_, false );
79}88}
8089
81#if ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG90#if ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG
82TEMPLATE_DECL(T)91template<class T>
83INTEGER_IMPL(T)::IntegerImpl( unsigned int n ) {92IntegerImpl<T>::IntegerImpl( unsigned int n ) {
84 ascii::itoa_buf_type buf;93 ascii::itoa_buf_type buf;
85 value_ = ascii::itoa( n, buf );94 value_ = ascii::itoa( n, buf );
95 T::check_value( value_, false );
86}96}
87#endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */97#endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */
8898
89IntegerImpl::IntegerImpl( unsigned long n ) {99template<class T>
100IntegerImpl<T>::IntegerImpl( unsigned long n ) {
90 ascii::itoa_buf_type buf;101 ascii::itoa_buf_type buf;
91 value_ = ascii::itoa( n, buf );102 value_ = ascii::itoa( n, buf );
103 T::check_value( value_, false );
92}104}
93105
94IntegerImpl::IntegerImpl( unsigned long long n ) {106template<class T>
107IntegerImpl<T>::IntegerImpl( unsigned long long n ) {
95 ascii::itoa_buf_type buf;108 ascii::itoa_buf_type buf;
96 value_ = ascii::itoa( n, buf );109 value_ = ascii::itoa( n, buf );
110 T::check_value( value_, false );
97}111}
98#endif /* ZORBA_WITH_BIG_INTEGER */112#endif /* ZORBA_WITH_BIG_INTEGER */
99113
100TEMPLATE_DECL(T)114template<class T>
101INTEGER_IMPL(T)::IntegerImpl( Decimal const &d ) {115IntegerImpl<T>::IntegerImpl( Decimal const &d ) {
102 value_ = ftoi( d.value_ );116 value_ = T::check_value( ftoi( d.value_ ), false );
103}117}
104118
105TEMPLATE_DECL(T)119template<class T>
106INTEGER_IMPL(T)::IntegerImpl( Double const &d ) {120IntegerImpl<T>::IntegerImpl( Double const &d ) {
107 if ( !d.isFinite() )121 if ( !d.isFinite() )
108 throw std::invalid_argument( "not finite" );122 throw std::invalid_argument( "not finite" );
109 value_ = ftoi( d.getNumber() );123 value_ = T::check_value( ftoi( d.getNumber() ), false );
110}124}
111125
112TEMPLATE_DECL(T)126template<class T>
113INTEGER_IMPL(T)::IntegerImpl( Float const &f ) {127IntegerImpl<T>::IntegerImpl( Float const &f ) {
114 if ( !f.isFinite() )128 if ( !f.isFinite() )
115 throw std::invalid_argument( "not finite" );129 throw std::invalid_argument( "not finite" );
116 value_ = ftoi( f.getNumber() );130 value_ = T::check_value( ftoi( f.getNumber() ), false );
117}131}
118132
119////////// assignment operators ///////////////////////////////////////////////133////////// assignment operators ///////////////////////////////////////////////
120134
121#ifdef ZORBA_WITH_BIG_INTEGER135#ifdef ZORBA_WITH_BIG_INTEGER
122IntegerImpl& IntegerImpl::operator=( long long n ) {136template<class T>
123 ascii::itoa_buf_type buf;137IntegerImpl<T>& IntegerImpl<T>::operator=( long long n ) {
124 value_ = ascii::itoa( n, buf );138 ascii::itoa_buf_type buf;
125 return *this;139 value_ = ascii::itoa( n, buf );
126}140 T::check_value( value_, true );
127141 return *this;
128IntegerImpl& IntegerImpl::operator=( unsigned long n ) {142}
129 ascii::itoa_buf_type buf;143
130 value_ = ascii::itoa( n, buf );144template<class T>
131 return *this;145IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long n ) {
132}146 ascii::itoa_buf_type buf;
133147 value_ = ascii::itoa( n, buf );
134IntegerImpl& IntegerImpl::operator=( unsigned long long n ) {148 T::check_value( value_, true );
135 ascii::itoa_buf_type buf;149 return *this;
136 value_ = ascii::itoa( n, buf );150}
151
152template<class T>
153IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long long n ) {
154 ascii::itoa_buf_type buf;
155 value_ = ascii::itoa( n, buf );
156 T::check_value( value_, true );
137 return *this;157 return *this;
138}158}
139#endif /* ZORBA_WITH_BIG_INTEGER */159#endif /* ZORBA_WITH_BIG_INTEGER */
140160
141TEMPLATE_DECL(T)161template<class T>
142INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Decimal const &d ) {162IntegerImpl<T>& IntegerImpl<T>::operator=( Decimal const &d ) {
143 value_ = ftoi( d.value_ );163 value_ = T::check_value( ftoi( d.value_ ), true );
144 return *this;164 return *this;
145}165}
146166
147TEMPLATE_DECL(T)167template<class T>
148INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Double const &d ) {168IntegerImpl<T>& IntegerImpl<T>::operator=( Double const &d ) {
149 if ( !d.isFinite() )169 if ( !d.isFinite() )
150 throw std::invalid_argument( "not finite" );170 throw std::invalid_argument( "not finite" );
151 value_ = ftoi( d.getNumber() );171 value_ = T::check_value( ftoi( d.getNumber() ), true );
152 return *this;172 return *this;
153}173}
154174
155TEMPLATE_DECL(T)175template<class T>
156INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Float const &f ) {176IntegerImpl<T>& IntegerImpl<T>::operator=( Float const &f ) {
157 if ( !f.isFinite() )177 if ( !f.isFinite() )
158 throw std::invalid_argument( "not finite" );178 throw std::invalid_argument( "not finite" );
159 value_ = ftoi( f.getNumber() );179 value_ = T::check_value( ftoi( f.getNumber() ), true );
160 return *this;180 return *this;
161}181}
162182
163////////// arithmetic operators ///////////////////////////////////////////////183////////// arithmetic operators ///////////////////////////////////////////////
164184
165#ifdef ZORBA_WITH_BIG_INTEGER185#define ZORBA_INSTANTIATE(OP,I) \
166# define ZORBA_INSTANTIATE(OP) /* nothing */186 template Decimal operator OP( I const&, Decimal const& );
167#else
168# define ZORBA_INSTANTIATE(OP) \
169 template Decimal operator OP( INTEGER_IMPL_LL const&, Decimal const& ); \
170 template Decimal operator OP( INTEGER_IMPL_ULL const&, Decimal const& );
171#endif /* ZORBA_WITH_BIG_INTEGER */
172187
173#define ZORBA_INTEGER_OP(OP) \188#define ZORBA_INTEGER_OP(OP) \
174 TEMPLATE_DECL(T) \189 template<class T> \
175 Decimal operator OP( INTEGER_IMPL(T) const &i, Decimal const &d ) { \190 Decimal operator OP( IntegerImpl<T> const &i, Decimal const &d ) { \
176 return i.itod() OP d.value_; \191 return i.itod() OP d.value_; \
177 } \192 } \
178 ZORBA_INSTANTIATE(OP)193 ZORBA_INSTANTIATE( OP, Integer ); \
194 ZORBA_INSTANTIATE( OP, NegativeInteger ); \
195 ZORBA_INSTANTIATE( OP, NonNegativeInteger ); \
196 ZORBA_INSTANTIATE( OP, NonPositiveInteger ); \
197 ZORBA_INSTANTIATE( OP, PositiveInteger );
179198
180ZORBA_INTEGER_OP(+)199ZORBA_INTEGER_OP(+)
181ZORBA_INTEGER_OP(-)200ZORBA_INTEGER_OP(-)
@@ -187,15 +206,26 @@
187206
188#ifdef ZORBA_WITH_BIG_INTEGER207#ifdef ZORBA_WITH_BIG_INTEGER
189208
190#define ZORBA_INTEGER_OP(OP,T) \209#define ZORBA_INSTANTIATE(OP,I,N) \
191 IntegerImpl operator OP( IntegerImpl const &i, T n ) { \210 template Integer operator OP( I const&, N ); \
192 ascii::itoa_buf_type buf; \211 template Integer operator OP( N, I const& )
193 return i.value_ OP IntegerImpl::value_type( ascii::itoa( n, buf ) ); \212
194 } \213#define ZORBA_INTEGER_OP(OP,N) \
195 IntegerImpl operator OP( T n, IntegerImpl const &i ) { \214 template<class T> \
196 ascii::itoa_buf_type buf; \215 Integer operator OP( IntegerImpl<T> const &i, N n ) { \
197 return IntegerImpl::value_type( ascii::itoa( n, buf ) ) OP i.value_; \216 ascii::itoa_buf_type buf; \
198 }217 return i.value_ OP MAPM( ascii::itoa( n, buf ) ); \
218 } \
219 template<class T> \
220 Integer operator OP( N n, IntegerImpl<T> const &i ) { \
221 ascii::itoa_buf_type buf; \
222 return MAPM( ascii::itoa( n, buf ) ) OP i.value_; \
223 } \
224 ZORBA_INSTANTIATE( OP, Integer, N ); \
225 ZORBA_INSTANTIATE( OP, NegativeInteger, N ); \
226 ZORBA_INSTANTIATE( OP, NonNegativeInteger, N ); \
227 ZORBA_INSTANTIATE( OP, NonPositiveInteger, N ); \
228 ZORBA_INSTANTIATE( OP, PositiveInteger, N );
199229
200ZORBA_INTEGER_OP(+,long long)230ZORBA_INTEGER_OP(+,long long)
201ZORBA_INTEGER_OP(-,long long)231ZORBA_INTEGER_OP(-,long long)
@@ -210,30 +240,44 @@
210ZORBA_INTEGER_OP(*,unsigned long long)240ZORBA_INTEGER_OP(*,unsigned long long)
211ZORBA_INTEGER_OP(%,unsigned long long)241ZORBA_INTEGER_OP(%,unsigned long long)
212#undef ZORBA_INTEGER_OP242#undef ZORBA_INTEGER_OP
213243#undef ZORBA_INSTANTIATE
214#define ZORBA_INTEGER_OP(T) \244
215 IntegerImpl operator/( IntegerImpl const &i, T n ) { \245#define ZORBA_INSTANTIATE(I,N) \
216 ascii::itoa_buf_type buf; \246 template Integer operator/( I const&, N ); \
217 IntegerImpl::value_type const temp( ascii::itoa( n, buf ) ); \247 template Integer operator/( N, I const& )
218 return IntegerImpl::ftoi( i.value_ / temp ); \248
219 } \249#define ZORBA_INTEGER_OP(N) \
220 IntegerImpl operator/( T n, IntegerImpl const &i ) { \250 template<class T> \
221 ascii::itoa_buf_type buf; \251 Integer operator/( IntegerImpl<T> const &i, N n ) { \
222 IntegerImpl::value_type const temp( ascii::itoa( n, buf ) ); \252 ascii::itoa_buf_type buf; \
223 return IntegerImpl::ftoi( temp / i.value_ ); \253 MAPM const temp( ascii::itoa( n, buf ) ); \
224 }254 return Integer::ftoi( i.value_ / temp ); \
255 } \
256 template<class T> \
257 Integer operator/( N n, IntegerImpl<T> const &i ) { \
258 ascii::itoa_buf_type buf; \
259 MAPM const temp( ascii::itoa( n, buf ) ); \
260 return Integer::ftoi( temp / i.value_ ); \
261 } \
262 ZORBA_INSTANTIATE( Integer, N ); \
263 ZORBA_INSTANTIATE( NegativeInteger, N ); \
264 ZORBA_INSTANTIATE( NonNegativeInteger, N ); \
265 ZORBA_INSTANTIATE( NonPositiveInteger, N ); \
266 ZORBA_INSTANTIATE( PositiveInteger, N );
225267
226ZORBA_INTEGER_OP(long long)268ZORBA_INTEGER_OP(long long)
227ZORBA_INTEGER_OP(unsigned long)269ZORBA_INTEGER_OP(unsigned long)
228ZORBA_INTEGER_OP(unsigned long long)270ZORBA_INTEGER_OP(unsigned long long)
229#undef ZORBA_INTEGER_OP271#undef ZORBA_INTEGER_OP
272#undef ZORBA_INSTANTIATE
230273
231#define ZORBA_INTEGER_OP(OP,T) \274#define ZORBA_INTEGER_OP(OP,N) \
232 IntegerImpl& IntegerImpl::operator OP( T n ) { \275 template<class T> \
233 ascii::itoa_buf_type buf; \276 IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \
234 value_type const temp( ascii::itoa( n, buf ) ); \277 ascii::itoa_buf_type buf; \
235 value_ OP temp; \278 value_type const temp( ascii::itoa( n, buf ) ); \
236 return *this; \279 T::check_value( value_ OP temp, true ); \
280 return *this; \
237 }281 }
238282
239ZORBA_INTEGER_OP(+=,long long)283ZORBA_INTEGER_OP(+=,long long)
@@ -250,12 +294,13 @@
250ZORBA_INTEGER_OP(%=,unsigned long long)294ZORBA_INTEGER_OP(%=,unsigned long long)
251#undef ZORBA_INTEGER_OP295#undef ZORBA_INTEGER_OP
252296
253#define ZORBA_INTEGER_OP(T) \297#define ZORBA_INTEGER_OP(N) \
254 IntegerImpl& IntegerImpl::operator/=( T n ) { \298 template<class T> \
255 ascii::itoa_buf_type buf; \299 IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \
256 value_type const temp( ascii::itoa( n, buf ) ); \300 ascii::itoa_buf_type buf; \
257 value_ = ftoi( value_ / temp ); \301 value_type const temp( ascii::itoa( n, buf ) ); \
258 return *this; \302 T::check_value( value_ = ftoi( value_ / temp ), true ); \
303 return *this; \
259 }304 }
260305
261ZORBA_INTEGER_OP(long long)306ZORBA_INTEGER_OP(long long)
@@ -266,36 +311,63 @@
266311
267////////// relational operators ///////////////////////////////////////////////312////////// relational operators ///////////////////////////////////////////////
268313
269TEMPLATE_DECL(T)314#define ZORBA_INSTANTIATE(OP,I) \
270bool operator==( INTEGER_IMPL(T) const &i, Decimal const &d ) {315 template bool operator OP( I const&, Decimal const& )
316
317template<class T>
318bool operator==( IntegerImpl<T> const &i, Decimal const &d ) {
271 return d.is_xs_integer() && i.itod() == d.value_;319 return d.is_xs_integer() && i.itod() == d.value_;
272}320}
273321
274#define ZORBA_INTEGER_OP(OP) \322ZORBA_INSTANTIATE( ==, Integer );
275 TEMPLATE_DECL(T) \323ZORBA_INSTANTIATE( ==, NegativeInteger );
276 bool operator OP( INTEGER_IMPL(T) const &i, Decimal const &d ) { \324ZORBA_INSTANTIATE( ==, NonNegativeInteger );
277 return i.itod() OP d.value_; \325ZORBA_INSTANTIATE( ==, NonPositiveInteger );
278 }326ZORBA_INSTANTIATE( ==, PositiveInteger );
327
328#define ZORBA_INTEGER_OP(OP) \
329 template<class T> \
330 bool operator OP( IntegerImpl<T> const &i, Decimal const &d ) { \
331 return i.itod() OP d.value_; \
332 } \
333 ZORBA_INSTANTIATE( OP, Integer ); \
334 ZORBA_INSTANTIATE( OP, NegativeInteger ); \
335 ZORBA_INSTANTIATE( OP, NonNegativeInteger ); \
336 ZORBA_INSTANTIATE( OP, NonPositiveInteger ); \
337 ZORBA_INSTANTIATE( OP, PositiveInteger );
279338
280ZORBA_INTEGER_OP(!=)339ZORBA_INTEGER_OP(!=)
281ZORBA_INTEGER_OP(< )340ZORBA_INTEGER_OP(< )
282ZORBA_INTEGER_OP(<=)341ZORBA_INTEGER_OP(<=)
283ZORBA_INTEGER_OP(> )342ZORBA_INTEGER_OP(> )
284ZORBA_INTEGER_OP(>=)343ZORBA_INTEGER_OP(>=)
344#undef ZORBA_INSTANTIATE
285#undef ZORBA_INTEGER_OP345#undef ZORBA_INTEGER_OP
286346
287#ifdef ZORBA_WITH_BIG_INTEGER347#ifdef ZORBA_WITH_BIG_INTEGER
288348
289#define ZORBA_INTEGER_OP(OP,T) \349#define ZORBA_INSTANTIATE(OP,I,N) \
290 bool operator OP( IntegerImpl const &i, T n ) { \350 template bool operator OP( I const&, N ); \
291 ascii::itoa_buf_type buf; \351 template bool operator OP( N, I const& )
292 return i.value_ OP IntegerImpl::value_type( ascii::itoa( n, buf ) ); \352
293 } \353#define ZORBA_INTEGER_OP(OP,N) \
294 \354 template<class T> \
295 bool operator OP( T n, IntegerImpl const &i ) { \355 bool operator OP( IntegerImpl<T> const &i, N n ) { \
296 ascii::itoa_buf_type buf; \356 ascii::itoa_buf_type buf; \
297 return IntegerImpl::value_type( ascii::itoa( n, buf ) ) OP i.value_; \357 return i.value_ OP MAPM( ascii::itoa( n, buf ) ); \
298 }358 } \
359 \
360 template<class T> \
361 bool operator OP( N n, IntegerImpl<T> const &i ) { \
362 ascii::itoa_buf_type buf; \
363 return MAPM( ascii::itoa( n, buf ) ) OP i.value_; \
364 } \
365 \
366 ZORBA_INSTANTIATE( OP, Integer, N ); \
367 ZORBA_INSTANTIATE( OP, NegativeInteger, N ); \
368 ZORBA_INSTANTIATE( OP, NonNegativeInteger, N ); \
369 ZORBA_INSTANTIATE( OP, NonPositiveInteger, N ); \
370 ZORBA_INSTANTIATE( OP, PositiveInteger, N );
299371
300ZORBA_INTEGER_OP(==,long long)372ZORBA_INTEGER_OP(==,long long)
301ZORBA_INTEGER_OP(!=,long long)373ZORBA_INTEGER_OP(!=,long long)
@@ -315,27 +387,14 @@
315ZORBA_INTEGER_OP(<=,unsigned long long)387ZORBA_INTEGER_OP(<=,unsigned long long)
316ZORBA_INTEGER_OP(> ,unsigned long long)388ZORBA_INTEGER_OP(> ,unsigned long long)
317ZORBA_INTEGER_OP(>=,unsigned long long)389ZORBA_INTEGER_OP(>=,unsigned long long)
318
319#else /* ZORBA_WITH_BIG_INTEGER */
320
321#define ZORBA_INSTANTIATE(OP) \
322 template bool operator OP( INTEGER_IMPL_LL const&, Decimal const& ); \
323 template bool operator OP( INTEGER_IMPL_ULL const&, Decimal const& )
324
325ZORBA_INSTANTIATE(==);
326ZORBA_INSTANTIATE(!=);
327ZORBA_INSTANTIATE(< );
328ZORBA_INSTANTIATE(<=);
329ZORBA_INSTANTIATE(> );
330ZORBA_INSTANTIATE(>=);
331#undef ZORBA_INSTANTIATE390#undef ZORBA_INSTANTIATE
332391
333#endif /* ZORBA_WITH_BIG_INTEGER */392#endif /* ZORBA_WITH_BIG_INTEGER */
334393
335////////// math functions /////////////////////////////////////////////////////394////////// math functions /////////////////////////////////////////////////////
336395
337TEMPLATE_DECL(T)396template<class T>
338Double INTEGER_IMPL(T)::pow( INTEGER_IMPL(T) const &power ) const {397Double IntegerImpl<T>::pow( IntegerImpl<T> const &power ) const {
339#ifdef ZORBA_WITH_BIG_INTEGER398#ifdef ZORBA_WITH_BIG_INTEGER
340 value_type const result( value_.pow( power.value_, 15 ) );399 value_type const result( value_.pow( power.value_, 15 ) );
341 char buf[300];400 char buf[300];
@@ -349,30 +408,30 @@
349#endif /* ZORBA_WITH_BIG_INTEGER */408#endif /* ZORBA_WITH_BIG_INTEGER */
350}409}
351410
352TEMPLATE_DECL(T)411template<class T>
353INTEGER_IMPL(T) INTEGER_IMPL(T)::round( IntegerImpl const &precision ) const {412IntegerImpl<T> IntegerImpl<T>::round( IntegerImpl<T> const &precision ) const {
354 return IntegerImpl( Decimal::round2( itod(), precision.itod() ) );413 return IntegerImpl( Decimal::round2( itod(), precision.itod() ) );
355}414}
356415
357TEMPLATE_DECL(T)416template<class T>
358INTEGER_IMPL(T)417IntegerImpl<T>
359INTEGER_IMPL(T)::roundHalfToEven( IntegerImpl const &precision ) const {418IntegerImpl<T>::roundHalfToEven( IntegerImpl const &precision ) const {
360 return IntegerImpl( Decimal::roundHalfToEven2( itod(), precision.itod() ) );419 return IntegerImpl( Decimal::roundHalfToEven2( itod(), precision.itod() ) );
361}420}
362421
363////////// miscellaneous //////////////////////////////////////////////////////422////////// miscellaneous //////////////////////////////////////////////////////
364423
365#ifndef ZORBA_WITH_BIG_INTEGER424#ifndef ZORBA_WITH_BIG_INTEGER
366TEMPLATE_DECL(T)425template<class T>
367typename INTEGER_IMPL(T)::value_type INTEGER_IMPL(T)::ftoi( MAPM const &d ) {426typename IntegerImpl<T>::value_type IntegerImpl<T>::ftoi( MAPM const &d ) {
368 MAPM const temp( d.sign() >= 0 ? d.floor() : d.ceil() );427 MAPM const temp( d.sign() >= 0 ? d.floor() : d.ceil() );
369 unique_ptr<char[]> const buf( new char[ temp.exponent() + 3 ] );428 unique_ptr<char[]> const buf( new char[ temp.exponent() + 3 ] );
370 temp.toIntegerString( buf.get() );429 temp.toIntegerString( buf.get() );
371 return ztd::aton<value_type>( buf.get() );430 return ztd::aton<value_type>( buf.get() );
372}431}
373432
374TEMPLATE_DECL(T)433template<class T>
375MAPM INTEGER_IMPL(T)::itod() const {434MAPM IntegerImpl<T>::itod() const {
376 if ( is_cxx_long() )435 if ( is_cxx_long() )
377 return static_cast<long>( value_ );436 return static_cast<long>( value_ );
378 ascii::itoa_buf_type buf;437 ascii::itoa_buf_type buf;
@@ -381,77 +440,79 @@
381#endif /* ZORBA_WITH_BIG_INTEGER */440#endif /* ZORBA_WITH_BIG_INTEGER */
382441
383#ifdef ZORBA_WITH_BIG_INTEGER442#ifdef ZORBA_WITH_BIG_INTEGER
384size_t IntegerImpl::alloc_size() const {443
444static MAPM xs_byte_min( "-128" );
445static MAPM xs_byte_max( "127" );
446static MAPM xs_short_min( "-32768" );
447static MAPM xs_short_max( "32767" );
448static MAPM xs_unsignedByte_max( "256" );
449static MAPM xs_unsignedInt_max( "4294967295" );
450static MAPM xs_unsignedLong_max( "18446744073709551615" );
451static MAPM xs_unsignedShort_max( "65536" );
452
453template<class T>
454size_t IntegerImpl<T>::alloc_size() const {
385 return value_.significant_digits();455 return value_.significant_digits();
386}456}
387457
388uint32_t IntegerImpl::hash() const {458template<class T>
459uint32_t IntegerImpl<T>::hash() const {
389 return Decimal::hash( value_ );460 return Decimal::hash( value_ );
390}461}
391462
392bool IntegerImpl::is_xs_byte() const {463template<class T>
393 static MAPM xs_byte_min( "-128" );464bool IntegerImpl<T>::is_xs_byte() const {
394 static MAPM xs_byte_max( "127" );
395 return value_ >= xs_byte_min && value_ <= xs_byte_max;465 return value_ >= xs_byte_min && value_ <= xs_byte_max;
396}466}
397467
398bool IntegerImpl::is_xs_short() const {468template<class T>
399 static MAPM xs_short_min( "-32768" );469bool IntegerImpl<T>::is_xs_short() const {
400 static MAPM xs_short_max( "32767" );
401 return value_ >= xs_short_min && value_ <= xs_short_max;470 return value_ >= xs_short_min && value_ <= xs_short_max;
402}471}
403472
404bool IntegerImpl::is_xs_unsignedByte() const {473template<class T>
405 static MAPM xs_unsignedByte_max( "256" );474bool IntegerImpl<T>::is_xs_unsignedByte() const {
406 return value_.sign() >= 0 && value_ <= xs_unsignedByte_max;475 return value_.sign() >= 0 && value_ <= xs_unsignedByte_max;
407}476}
408477
409bool IntegerImpl::is_xs_unsignedInt() const {478template<class T>
410 static MAPM xs_unsignedInt_max( "4294967295" );479bool IntegerImpl<T>::is_xs_unsignedInt() const {
411 return value_.sign() >= 0 && value_ <= xs_unsignedInt_max;480 return value_.sign() >= 0 && value_ <= xs_unsignedInt_max;
412}481}
413482
414bool IntegerImpl::is_xs_unsignedLong() const {483template<class T>
415 static MAPM xs_unsignedLong_max( "18446744073709551615" );484bool IntegerImpl<T>::is_xs_unsignedLong() const {
416 return value_.sign() >= 0 && value_ <= xs_unsignedLong_max;485 return value_.sign() >= 0 && value_ <= xs_unsignedLong_max;
417}486}
418487
419bool IntegerImpl::is_xs_unsignedShort() const {488template<class T>
420 static MAPM xs_unsignedShort_max( "65536" );489bool IntegerImpl<T>::is_xs_unsignedShort() const {
421 return value_.sign() >= 0 && value_ <= xs_unsignedShort_max;490 return value_.sign() >= 0 && value_ <= xs_unsignedShort_max;
422}491}
423#endif /* ZORBA_WITH_BIG_INTEGER */492#endif /* ZORBA_WITH_BIG_INTEGER */
424493
425TEMPLATE_DECL(T)494template<class T>
426INTEGER_IMPL(T) const& INTEGER_IMPL(T)::one() {495zstring IntegerImpl<T>::toString() const {
427 static INTEGER_IMPL(T) const i(1);
428 return i;
429}
430
431TEMPLATE_DECL(T)
432zstring INTEGER_IMPL(T)::toString() const {
433#ifdef ZORBA_WITH_BIG_INTEGER496#ifdef ZORBA_WITH_BIG_INTEGER
434 unique_ptr<char[]> const buf( new char[ value_.exponent() + 3 ] );497 ostringstream oss;
435 value_.toIntegerString( buf.get() );498 oss << value_;
436 return buf.get();499 return oss.str();
437#else500#else
438 ascii::itoa_buf_type buf;501 ascii::itoa_buf_type buf;
439 return ascii::itoa( value_, buf );502 return ascii::itoa( value_, buf );
440#endif /* ZORBA_WITH_BIG_INTEGER */503#endif /* ZORBA_WITH_BIG_INTEGER */
441}504}
442505
443TEMPLATE_DECL(T)506///////////////////////////////////////////////////////////////////////////////
444INTEGER_IMPL(T) const& INTEGER_IMPL(T)::zero() {507
445 static INTEGER_IMPL(T) const i(0);508// instantiate integer types
446 return i;509template class IntegerImpl<integer_traits>;
447}510template class IntegerImpl<negative_traits>;
448511template class IntegerImpl<nonNegative_traits>;
449///////////////////////////////////////////////////////////////////////////////512template class IntegerImpl<nonPositive_traits>;
450513template class IntegerImpl<positive_traits>;
451#ifndef ZORBA_WITH_BIG_INTEGER514
452template class IntegerImpl<long long>;515///////////////////////////////////////////////////////////////////////////////
453template class IntegerImpl<unsigned long long>;
454#endif /* ZORBA_WITH_BIG_INTEGER */
455516
456} // namespace zorba517} // namespace zorba
457/* vim:set et sw=2 ts=2: */518/* vim:set et sw=2 ts=2: */
458519
=== modified file 'src/zorbatypes/integer.h'
--- src/zorbatypes/integer.h 2013-02-26 04:12:43 +0000
+++ src/zorbatypes/integer.h 2013-05-08 15:05:31 +0000
@@ -18,60 +18,142 @@
18#ifndef ZORBA_INTEGER_H18#ifndef ZORBA_INTEGER_H
19#define ZORBA_INTEGER_H19#define ZORBA_INTEGER_H
2020
21// standard
21#include <cmath>22#include <cmath>
22#include <limits>23#include <limits>
24#include <string>
2325
26// Zorba
24#include <zorba/config.h>27#include <zorba/config.h>
25
26#include "common/common.h"28#include "common/common.h"
27#include "util/stl_util.h"29#include "util/stl_util.h"
30#include "util/string_util.h"
2831
32// local
29#include "m_apm.h"33#include "m_apm.h"
34#include "numeric_types.h"
30#include "schema_types_base.h"35#include "schema_types_base.h"
31#include "zorbatypes_decl.h"36#include "zorbatypes_decl.h"
32#include "zstring.h"37#include "zstring.h"
3338
34#ifdef ZORBA_WITH_BIG_INTEGER
35# define TEMPLATE_DECL(I) /* nothing */
36# define INTEGER_IMPL(I) IntegerImpl
37# define TEMPLATE_TYPENAME /* nothing */
38#else
39# define TEMPLATE_DECL(I) template<typename I> /* spacer */
40# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */
41# define TEMPLATE_TYPENAME typename
42#endif /* ZORBA_WITH_BIG_INTEGER */
43#define INTEGER_IMPL_LL INTEGER_IMPL(long long)
44#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
45
46namespace zorba {39namespace zorba {
4740
48TEMPLATE_DECL(I)41template<class TraitsType>
49class IntegerImpl;42class IntegerImpl;
5043
51namespace serialization 44namespace serialization {
52{
53 class Archiver;45 class Archiver;
54 TEMPLATE_DECL(I) void operator&( Archiver&, INTEGER_IMPL(I)& );46
47 template<class T>
48 void operator&( Archiver&, IntegerImpl<T>& );
55}49}
5650
57///////////////////////////////////////////////////////////////////////////////51///////////////////////////////////////////////////////////////////////////////
5852
59TEMPLATE_DECL(IntType)53std::ostream& operator<<( std::ostream&, MAPM const& );
60class IntegerImpl 54
61{55struct integer_traits {
56 static int const default_value = 0;
57
58 template<typename ValueType>
59 static ValueType check_value( ValueType n, bool ) {
60 return n;
61 }
62
63 static MAPM const& check_value( MAPM const &n, bool ) {
64 return n;
65 }
66
67protected:
68 static void throw_error( std::string const&, bool );
69
70 template<typename ValueType>
71 static void throw_error( ValueType n, char const *op,
72 bool throw_range_error ) {
73 std::string const what( BUILD_STRING( n, ": not ", op, " 0" ) );
74 throw_error( what, throw_range_error );
75 }
76
77 static void throw_error( MAPM const &n, char const *op,
78 bool throw_range_error );
79};
80
81struct nonPositive_traits : integer_traits {
82 template<typename ValueType>
83 static ValueType check_value( ValueType n, bool throw_range_error ) {
84 if ( !ztd::le0( n ) )
85 throw_error( n, "<=", throw_range_error );
86 return n;
87 }
88 static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {
89 if ( !(n.sign() <= 0) )
90 throw_error( n, "<=", throw_range_error );
91 return n;
92 }
93};
94
95struct negative_traits : nonPositive_traits {
96 static int const default_value = -1;
97
98 template<typename ValueType>
99 static ValueType check_value( ValueType n, bool throw_range_error ) {
100 if ( !ztd::lt0( n ) )
101 throw_error( n, "<", throw_range_error );
102 return n;
103 }
104 static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {
105 if ( !(n.sign() < 0) )
106 throw_error( n, "<", throw_range_error );
107 return n;
108 }
109};
110
111struct nonNegative_traits : integer_traits {
112 template<typename ValueType>
113 static ValueType check_value( ValueType n, bool throw_range_error ) {
114 if ( !ztd::ge0( n ) )
115 throw_error( n, ">=", throw_range_error );
116 return n;
117 }
118 static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {
119 if ( !(n.sign() >= 0) )
120 throw_error( n, ">=", throw_range_error );
121 return n;
122 }
123};
124
125struct positive_traits : nonNegative_traits {
126 static int const default_value = 1;
127
128 template<typename ValueType>
129 static ValueType check_value( ValueType n, bool throw_range_error ) {
130 if ( !ztd::gt0( n ) )
131 throw_error( n, ">", throw_range_error );
132 return n;
133 }
134 static MAPM const& check_value( MAPM const &n, bool throw_range_error ) {
135 if ( !(n.sign() > 0) )
136 throw_error( n, ">", throw_range_error );
137 return n;
138 }
139};
140
141template<class TraitsType>
142class IntegerImpl {
62public:143public:
63#ifdef ZORBA_WITH_BIG_INTEGER144#ifdef ZORBA_WITH_BIG_INTEGER
64 typedef MAPM value_type;145 typedef MAPM value_type;
65#else146#else
66 typedef IntType value_type;147 typedef long long value_type;
67#endif /* ZORBA_WITH_BIG_INTEGER */148#endif /* ZORBA_WITH_BIG_INTEGER */
149 typedef TraitsType traits_type;
68150
69 ////////// constructors /////////////////////////////////////////////////////151 ////////// constructors /////////////////////////////////////////////////////
70152
71 explicit IntegerImpl( char c );153 explicit IntegerImpl( char c );
72 explicit IntegerImpl( signed char c );154 explicit IntegerImpl( signed char c );
73 explicit IntegerImpl( short n );155 explicit IntegerImpl( short n );
74 explicit IntegerImpl( int n = 0 );156 explicit IntegerImpl( int n = traits_type::default_value );
75 explicit IntegerImpl( long n );157 explicit IntegerImpl( long n );
76 explicit IntegerImpl( long long n );158 explicit IntegerImpl( long long n );
77 explicit IntegerImpl( unsigned char c );159 explicit IntegerImpl( unsigned char c );
@@ -112,27 +194,27 @@
112 explicit IntegerImpl( Float const &f );194 explicit IntegerImpl( Float const &f );
113195
114 /**196 /**
115 * Constructs from another %IntegerImpl even if its \c IntType is different.197 * Constructs from another %IntegerImpl even if its \c TraitsType is
116 * (This subsumes the conventional copy constructor.)198 * different. (This subsumes the conventional copy constructor.)
117 *199 *
118 * @tparam IntType2 the integer type of \a i.200 * @tparam TraitsType2 The traits type of \a i.
119 * @param i The %IntegerImpl to copy from.201 * @param i The %IntegerImpl to copy from.
120 */202 */
121 TEMPLATE_DECL(IntType2)203 template<class TraitsType2>
122 IntegerImpl( INTEGER_IMPL(IntType2) const &i );204 IntegerImpl( IntegerImpl<TraitsType2> const &i );
123205
124 ////////// assignment operators /////////////////////////////////////////////206 ////////// assignment operators /////////////////////////////////////////////
125207
126 /**208 /**
127 * Assign from an %IntegerImpl even if its \c IntType is different.209 * Assign from an %IntegerImpl even if its \c TraitsType is different.
128 * (This subsumes the conventional assignment operator.)210 * (This subsumes the conventional assignment operator.)
129 *211 *
130 * @tparam IntType2 the integer type of \a i.212 * @tparam TraitsType2 The traits type of \a i.
131 * @param i The %IntegerImpl to assign from.213 * @param i The %IntegerImpl to assign from.
132 * @return Returns \c *this.214 * @return Returns \c *this.
133 */215 */
134 TEMPLATE_DECL(IntType2)216 template<class TraitsType2>
135 IntegerImpl& operator=( INTEGER_IMPL(IntType2) const &i );217 IntegerImpl& operator=( IntegerImpl<TraitsType2> const &i );
136218
137 IntegerImpl& operator=( char c );219 IntegerImpl& operator=( char c );
138 IntegerImpl& operator=( signed char c );220 IntegerImpl& operator=( signed char c );
@@ -155,16 +237,15 @@
155237
156 ////////// arithmetic operators /////////////////////////////////////////////238 ////////// arithmetic operators /////////////////////////////////////////////
157239
158#define ZORBA_INTEGER_OP(OP) \240#define ZORBA_INTEGER_OP(OP) \
159 TEMPLATE_DECL(I) friend \241 template<class T,class U> friend \
160 INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const&, \242 Integer operator OP( IntegerImpl<T> const&, IntegerImpl<U> const& ); \
161 INTEGER_IMPL(I) const& ); \243 \
162 \244 template<class T> friend \
163 TEMPLATE_DECL(I) friend \245 Decimal operator OP( IntegerImpl<T> const&, Decimal const& ); \
164 Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \246 \
165 \247 template<class T> friend \
166 TEMPLATE_DECL(I) friend \248 Decimal operator OP( Decimal const&, IntegerImpl<T> const& )
167 Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& )
168249
169 ZORBA_INTEGER_OP(+);250 ZORBA_INTEGER_OP(+);
170 ZORBA_INTEGER_OP(-);251 ZORBA_INTEGER_OP(-);
@@ -173,12 +254,12 @@
173 ZORBA_INTEGER_OP(%);254 ZORBA_INTEGER_OP(%);
174#undef ZORBA_INTEGER_OP255#undef ZORBA_INTEGER_OP
175256
176#define ZORBA_INTEGER_OP(OP,T) \257#define ZORBA_INTEGER_OP(OP,N) \
177 TEMPLATE_DECL(I) friend \258 template<class T> friend \
178 INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const&, T ); \259 Integer operator OP( IntegerImpl<T> const&, N ); \
179 \260 \
180 TEMPLATE_DECL(I) friend \261 template<class T> friend \
181 INTEGER_IMPL(I) operator OP( T, INTEGER_IMPL(I) const& )262 Integer operator OP( N, IntegerImpl<T> const& )
182263
183 ZORBA_INTEGER_OP(+,char);264 ZORBA_INTEGER_OP(+,char);
184 ZORBA_INTEGER_OP(-,char);265 ZORBA_INTEGER_OP(-,char);
@@ -247,19 +328,14 @@
247 ZORBA_INTEGER_OP(%,double);328 ZORBA_INTEGER_OP(%,double);
248#undef ZORBA_INTEGER_OP329#undef ZORBA_INTEGER_OP
249330
250#define ZORBA_INTEGER_OP(OP,TYPE) \331#define ZORBA_INTEGER_OP(OP,T) \
251 IntegerImpl& operator OP( TYPE )332 IntegerImpl& operator OP( T )
252333
253 ZORBA_INTEGER_OP(+=,IntegerImpl const&);334 ZORBA_INTEGER_OP(+=,IntegerImpl const&);
254 ZORBA_INTEGER_OP(-=,IntegerImpl const&);335 ZORBA_INTEGER_OP(-=,IntegerImpl const&);
255 ZORBA_INTEGER_OP(*=,IntegerImpl const&);336 ZORBA_INTEGER_OP(*=,IntegerImpl const&);
256 ZORBA_INTEGER_OP(/=,IntegerImpl const&);337 ZORBA_INTEGER_OP(/=,IntegerImpl const&);
257 ZORBA_INTEGER_OP(%=,IntegerImpl const&);338 ZORBA_INTEGER_OP(%=,IntegerImpl const&);
258#undef ZORBA_INTEGER_OP
259
260#define ZORBA_INTEGER_OP(OP,T) \
261 IntegerImpl& operator OP( T )
262
263 ZORBA_INTEGER_OP(+=,char);339 ZORBA_INTEGER_OP(+=,char);
264 ZORBA_INTEGER_OP(-=,char);340 ZORBA_INTEGER_OP(-=,char);
265 ZORBA_INTEGER_OP(*=,char);341 ZORBA_INTEGER_OP(*=,char);
@@ -327,7 +403,7 @@
327 ZORBA_INTEGER_OP(%=,double);403 ZORBA_INTEGER_OP(%=,double);
328#undef ZORBA_INTEGER_OP404#undef ZORBA_INTEGER_OP
329405
330 IntegerImpl operator-() const;406 Integer operator-() const;
331407
332 IntegerImpl& operator++();408 IntegerImpl& operator++();
333 IntegerImpl operator++(int);409 IntegerImpl operator++(int);
@@ -336,107 +412,107 @@
336412
337 ////////// relational operators /////////////////////////////////////////////413 ////////// relational operators /////////////////////////////////////////////
338414
339#define ZORBA_INTEGER_OP(OP) \415#define ZORBA_REL_OP(OP) \
340 TEMPLATE_DECL(I) friend \416 template<class T,class U> friend \
341 bool operator OP( INTEGER_IMPL(I) const&, INTEGER_IMPL(I) const& ); \417 bool operator OP( IntegerImpl<T> const&, IntegerImpl<U> const& ); \
342 \418 \
343 TEMPLATE_DECL(I) friend \419 template<class T> friend \
344 bool operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \420 bool operator OP( IntegerImpl<T> const&, Decimal const& ); \
345 \421 \
346 TEMPLATE_DECL(I) friend \422 template<class T> friend \
347 bool operator OP( Decimal const&, INTEGER_IMPL(I) const& )423 bool operator OP( Decimal const&, IntegerImpl<T> const& )
348424
349 ZORBA_INTEGER_OP(==);425 ZORBA_REL_OP(==);
350 ZORBA_INTEGER_OP(!=);426 ZORBA_REL_OP(!=);
351 ZORBA_INTEGER_OP(< );427 ZORBA_REL_OP(< );
352 ZORBA_INTEGER_OP(<=);428 ZORBA_REL_OP(<=);
353 ZORBA_INTEGER_OP(> );429 ZORBA_REL_OP(> );
354 ZORBA_INTEGER_OP(>=);430 ZORBA_REL_OP(>=);
355#undef ZORBA_INTEGER_OP431#undef ZORBA_REL_OP
356432
357#define ZORBA_INTEGER_OP(OP,T) \433#define ZORBA_REL_OP(OP,N) \
358 TEMPLATE_DECL(I) friend bool operator OP( INTEGER_IMPL(I) const&, T ); \434 template<class T> friend bool operator OP( IntegerImpl<T> const&, N ); \
359 TEMPLATE_DECL(I) friend bool operator OP( T, INTEGER_IMPL(I) const& )435 template<class T> friend bool operator OP( N, IntegerImpl<T> const& )
360436
361 ZORBA_INTEGER_OP(==,char);437 ZORBA_REL_OP(==,char);
362 ZORBA_INTEGER_OP(!=,char);438 ZORBA_REL_OP(!=,char);
363 ZORBA_INTEGER_OP(< ,char);439 ZORBA_REL_OP(< ,char);
364 ZORBA_INTEGER_OP(<=,char);440 ZORBA_REL_OP(<=,char);
365 ZORBA_INTEGER_OP(> ,char);441 ZORBA_REL_OP(> ,char);
366 ZORBA_INTEGER_OP(>=,char);442 ZORBA_REL_OP(>=,char);
367 ZORBA_INTEGER_OP(==,signed char);443 ZORBA_REL_OP(==,signed char);
368 ZORBA_INTEGER_OP(!=,signed char);444 ZORBA_REL_OP(!=,signed char);
369 ZORBA_INTEGER_OP(< ,signed char);445 ZORBA_REL_OP(< ,signed char);
370 ZORBA_INTEGER_OP(<=,signed char);446 ZORBA_REL_OP(<=,signed char);
371 ZORBA_INTEGER_OP(> ,signed char);447 ZORBA_REL_OP(> ,signed char);
372 ZORBA_INTEGER_OP(>=,signed char);448 ZORBA_REL_OP(>=,signed char);
373 ZORBA_INTEGER_OP(==,short);449 ZORBA_REL_OP(==,short);
374 ZORBA_INTEGER_OP(!=,short);450 ZORBA_REL_OP(!=,short);
375 ZORBA_INTEGER_OP(< ,short);451 ZORBA_REL_OP(< ,short);
376 ZORBA_INTEGER_OP(<=,short);452 ZORBA_REL_OP(<=,short);
377 ZORBA_INTEGER_OP(> ,short);453 ZORBA_REL_OP(> ,short);
378 ZORBA_INTEGER_OP(>=,short);454 ZORBA_REL_OP(>=,short);
379 ZORBA_INTEGER_OP(==,int);455 ZORBA_REL_OP(==,int);
380 ZORBA_INTEGER_OP(!=,int);456 ZORBA_REL_OP(!=,int);
381 ZORBA_INTEGER_OP(< ,int);457 ZORBA_REL_OP(< ,int);
382 ZORBA_INTEGER_OP(<=,int);458 ZORBA_REL_OP(<=,int);
383 ZORBA_INTEGER_OP(> ,int);459 ZORBA_REL_OP(> ,int);
384 ZORBA_INTEGER_OP(>=,int);460 ZORBA_REL_OP(>=,int);
385 ZORBA_INTEGER_OP(==,long);461 ZORBA_REL_OP(==,long);
386 ZORBA_INTEGER_OP(!=,long);462 ZORBA_REL_OP(!=,long);
387 ZORBA_INTEGER_OP(< ,long);463 ZORBA_REL_OP(< ,long);
388 ZORBA_INTEGER_OP(<=,long);464 ZORBA_REL_OP(<=,long);
389 ZORBA_INTEGER_OP(> ,long);465 ZORBA_REL_OP(> ,long);
390 ZORBA_INTEGER_OP(>=,long);466 ZORBA_REL_OP(>=,long);
391 ZORBA_INTEGER_OP(==,long long);467 ZORBA_REL_OP(==,long long);
392 ZORBA_INTEGER_OP(!=,long long);468 ZORBA_REL_OP(!=,long long);
393 ZORBA_INTEGER_OP(< ,long long);469 ZORBA_REL_OP(< ,long long);
394 ZORBA_INTEGER_OP(<=,long long);470 ZORBA_REL_OP(<=,long long);
395 ZORBA_INTEGER_OP(> ,long long);471 ZORBA_REL_OP(> ,long long);
396 ZORBA_INTEGER_OP(>=,long long);472 ZORBA_REL_OP(>=,long long);
397 ZORBA_INTEGER_OP(==,unsigned char);473 ZORBA_REL_OP(==,unsigned char);
398 ZORBA_INTEGER_OP(!=,unsigned char);474 ZORBA_REL_OP(!=,unsigned char);
399 ZORBA_INTEGER_OP(< ,unsigned char);475 ZORBA_REL_OP(< ,unsigned char);
400 ZORBA_INTEGER_OP(<=,unsigned char);476 ZORBA_REL_OP(<=,unsigned char);
401 ZORBA_INTEGER_OP(> ,unsigned char);477 ZORBA_REL_OP(> ,unsigned char);
402 ZORBA_INTEGER_OP(>=,unsigned char);478 ZORBA_REL_OP(>=,unsigned char);
403 ZORBA_INTEGER_OP(==,unsigned short);479 ZORBA_REL_OP(==,unsigned short);
404 ZORBA_INTEGER_OP(!=,unsigned short);480 ZORBA_REL_OP(!=,unsigned short);
405 ZORBA_INTEGER_OP(< ,unsigned short);481 ZORBA_REL_OP(< ,unsigned short);
406 ZORBA_INTEGER_OP(<=,unsigned short);482 ZORBA_REL_OP(<=,unsigned short);
407 ZORBA_INTEGER_OP(> ,unsigned short);483 ZORBA_REL_OP(> ,unsigned short);
408 ZORBA_INTEGER_OP(>=,unsigned short);484 ZORBA_REL_OP(>=,unsigned short);
409 ZORBA_INTEGER_OP(==,unsigned int);485 ZORBA_REL_OP(==,unsigned int);
410 ZORBA_INTEGER_OP(!=,unsigned int);486 ZORBA_REL_OP(!=,unsigned int);
411 ZORBA_INTEGER_OP(< ,unsigned int);487 ZORBA_REL_OP(< ,unsigned int);
412 ZORBA_INTEGER_OP(<=,unsigned int);488 ZORBA_REL_OP(<=,unsigned int);
413 ZORBA_INTEGER_OP(> ,unsigned int);489 ZORBA_REL_OP(> ,unsigned int);
414 ZORBA_INTEGER_OP(>=,unsigned int);490 ZORBA_REL_OP(>=,unsigned int);
415 ZORBA_INTEGER_OP(==,unsigned long);491 ZORBA_REL_OP(==,unsigned long);
416 ZORBA_INTEGER_OP(!=,unsigned long);492 ZORBA_REL_OP(!=,unsigned long);
417 ZORBA_INTEGER_OP(< ,unsigned long);493 ZORBA_REL_OP(< ,unsigned long);
418 ZORBA_INTEGER_OP(<=,unsigned long);494 ZORBA_REL_OP(<=,unsigned long);
419 ZORBA_INTEGER_OP(> ,unsigned long);495 ZORBA_REL_OP(> ,unsigned long);
420 ZORBA_INTEGER_OP(>=,unsigned long);496 ZORBA_REL_OP(>=,unsigned long);
421 ZORBA_INTEGER_OP(==,unsigned long long);497 ZORBA_REL_OP(==,unsigned long long);
422 ZORBA_INTEGER_OP(!=,unsigned long long);498 ZORBA_REL_OP(!=,unsigned long long);
423 ZORBA_INTEGER_OP(< ,unsigned long long);499 ZORBA_REL_OP(< ,unsigned long long);
424 ZORBA_INTEGER_OP(<=,unsigned long long);500 ZORBA_REL_OP(<=,unsigned long long);
425 ZORBA_INTEGER_OP(> ,unsigned long long);501 ZORBA_REL_OP(> ,unsigned long long);
426 ZORBA_INTEGER_OP(>=,unsigned long long);502 ZORBA_REL_OP(>=,unsigned long long);
427 ZORBA_INTEGER_OP(==,float);503 ZORBA_REL_OP(==,float);
428 ZORBA_INTEGER_OP(!=,float);504 ZORBA_REL_OP(!=,float);
429 ZORBA_INTEGER_OP(< ,float);505 ZORBA_REL_OP(< ,float);
430 ZORBA_INTEGER_OP(<=,float);506 ZORBA_REL_OP(<=,float);
431 ZORBA_INTEGER_OP(> ,float);507 ZORBA_REL_OP(> ,float);
432 ZORBA_INTEGER_OP(>=,float);508 ZORBA_REL_OP(>=,float);
433 ZORBA_INTEGER_OP(==,double);509 ZORBA_REL_OP(==,double);
434 ZORBA_INTEGER_OP(!=,double);510 ZORBA_REL_OP(!=,double);
435 ZORBA_INTEGER_OP(< ,double);511 ZORBA_REL_OP(< ,double);
436 ZORBA_INTEGER_OP(<=,double);512 ZORBA_REL_OP(<=,double);
437 ZORBA_INTEGER_OP(> ,double);513 ZORBA_REL_OP(> ,double);
438 ZORBA_INTEGER_OP(>=,double);514 ZORBA_REL_OP(>=,double);
439#undef ZORBA_INTEGER_OP515#undef ZORBA_REL_OP
440516
441 ////////// math functions ///////////////////////////////////////////////////517 ////////// math functions ///////////////////////////////////////////////////
442518
@@ -464,8 +540,6 @@
464 zstring toString() const;540 zstring toString() const;
465 value_type& value();541 value_type& value();
466 value_type const& value() const;542 value_type const& value() const;
467 static IntegerImpl const& one();
468 static IntegerImpl const& zero();
469543
470 /////////////////////////////////////////////////////////////////////////////544 /////////////////////////////////////////////////////////////////////////////
471545
@@ -473,20 +547,18 @@
473#ifdef ZORBA_WITH_BIG_INTEGER547#ifdef ZORBA_WITH_BIG_INTEGER
474 typedef long int_cast_type;548 typedef long int_cast_type;
475#else549#else
476 typedef IntType int_cast_type;550 typedef value_type int_cast_type;
477#endif /* ZORBA_WITH_BIG_INTEGER */551#endif /* ZORBA_WITH_BIG_INTEGER */
478552
479 value_type value_;553 value_type value_;
480554
481#ifdef ZORBA_WITH_BIG_INTEGER
482 IntegerImpl( value_type const &v ) : value_( v ) { }
483#endif /* ZORBA_WITH_BIG_INTEGER */
484
485 static value_type ftoi( double d ) {555 static value_type ftoi( double d ) {
486 return value_type( d >= 0 ? floor( d ) : ceil( d ) );556 return value_type( d >= 0 ? floor( d ) : ceil( d ) );
487 }557 }
488558
489#ifdef ZORBA_WITH_BIG_INTEGER559#ifdef ZORBA_WITH_BIG_INTEGER
560 IntegerImpl( value_type const &v ) : value_( v ) { }
561
490 static value_type ftoi( MAPM const &d ) {562 static value_type ftoi( MAPM const &d ) {
491 return d.sign() >= 0 ? d.floor() : d.ceil();563 return d.sign() >= 0 ? d.floor() : d.ceil();
492 }564 }
@@ -499,7 +571,6 @@
499 static value_type make_value_type( T n ) {571 static value_type make_value_type( T n ) {
500 return value_type( static_cast<int_cast_type>( n ) );572 return value_type( static_cast<int_cast_type>( n ) );
501 }573 }
502
503#else /* ZORBA_WITH_BIG_INTEGER */574#else /* ZORBA_WITH_BIG_INTEGER */
504575
505 static value_type ftoi( value_type v ) {576 static value_type ftoi( value_type v ) {
@@ -516,148 +587,149 @@
516 }587 }
517#endif /* ZORBA_WITH_BIG_INTEGER */588#endif /* ZORBA_WITH_BIG_INTEGER */
518589
519 void parse( char const *s );590 void parse( char const *s, bool throw_range_error );
520591
521 friend class Decimal;592 friend class Decimal;
522 template<typename T> friend class FloatImpl;593 template<typename F> friend class FloatImpl;
523594 template<class T> friend class IntegerImpl;
524#ifndef ZORBA_WITH_BIG_INTEGER595
525 template<typename T> friend class IntegerImpl;596 friend xs_int to_xs_int( Integer const& );
526#endif /* ZORBA_WITH_BIG_INTEGER */597 friend xs_long to_xs_long( Integer const& );
527598 friend xs_unsignedByte to_xs_unsignedByte( Integer const& );
528 friend xs_int to_xs_int( INTEGER_IMPL_LL const& );599 friend xs_unsignedShort to_xs_unsignedShort( Integer const& );
529 friend xs_long to_xs_long( INTEGER_IMPL_LL const& );600 friend xs_unsignedInt to_xs_unsignedInt( Integer const& );
530 friend xs_unsignedByte to_xs_unsignedByte( INTEGER_IMPL_LL const& );601 friend xs_unsignedLong to_xs_unsignedLong( Integer const& );
531 friend xs_unsignedShort to_xs_unsignedShort( INTEGER_IMPL_LL const& );602
532 friend xs_unsignedInt to_xs_unsignedInt( INTEGER_IMPL_LL const& );603 template<class T> friend
533 friend xs_unsignedLong to_xs_unsignedLong( INTEGER_IMPL_LL const& );604 void serialization::operator&( serialization::Archiver&, IntegerImpl<T>& );
534
535 TEMPLATE_DECL(I) friend
536 void serialization::operator&( serialization::Archiver&, INTEGER_IMPL(I)& );
537};605};
538606
539typedef INTEGER_IMPL_LL Integer;607typedef IntegerImpl<integer_traits> Integer;
540typedef INTEGER_IMPL_ULL UInteger;608typedef IntegerImpl<negative_traits> NegativeInteger;
609typedef IntegerImpl<nonNegative_traits> NonNegativeInteger;
610typedef IntegerImpl<nonPositive_traits> NonPositiveInteger;
611typedef IntegerImpl<positive_traits> PositiveInteger;
541612
542////////// constructors ///////////////////////////////////////////////////////613////////// constructors ///////////////////////////////////////////////////////
543614
544TEMPLATE_DECL(I)615template<class T>
545inline INTEGER_IMPL(I)::IntegerImpl( char c ) :616inline IntegerImpl<T>::IntegerImpl( char c ) :
546 value_( static_cast<long>( c ) )617 value_( static_cast<long>( T::check_value( c, false ) ) )
547{618{
548}619}
549620
550TEMPLATE_DECL(I)621template<class T>
551inline INTEGER_IMPL(I)::IntegerImpl( signed char c ) :622inline IntegerImpl<T>::IntegerImpl( signed char c ) :
552 value_( static_cast<long>( c ) )623 value_( static_cast<long>( T::check_value( c, false ) ) )
553{624{
554}625}
555626
556TEMPLATE_DECL(I)627template<class T>
557inline INTEGER_IMPL(I)::IntegerImpl( short n ) :628inline IntegerImpl<T>::IntegerImpl( short n ) :
558 value_( static_cast<long>( n ) )629 value_( static_cast<long>( T::check_value( n, false ) ) )
559{630{
560}631}
561632
562TEMPLATE_DECL(I)633template<class T>
563inline INTEGER_IMPL(I)::IntegerImpl( int n ) :634inline IntegerImpl<T>::IntegerImpl( int n ) :
564 value_( static_cast<long>( n ) )635 value_( static_cast<long>( T::check_value( n, false ) ) )
565{636{
566}637}
567638
568TEMPLATE_DECL(I)639template<class T>
569inline INTEGER_IMPL(I)::IntegerImpl( long n ) :640inline IntegerImpl<T>::IntegerImpl( long n ) :
570 value_( n )641 value_( T::check_value( n, false ) )
571{642{
572}643}
573644
574#ifndef ZORBA_WITH_BIG_INTEGER645#ifndef ZORBA_WITH_BIG_INTEGER
575TEMPLATE_DECL(I)646template<class T>
576inline INTEGER_IMPL(I)::IntegerImpl( long long n ) :647inline IntegerImpl<T>::IntegerImpl( long long n ) :
577 value_( n )648 value_( T::check_value( n, false ) )
578{649{
579}650}
580#endif /* ZORBA_WITH_BIG_INTEGER */651#endif /* ZORBA_WITH_BIG_INTEGER */
581652
582TEMPLATE_DECL(I)653template<class T>
583inline INTEGER_IMPL(I)::IntegerImpl( unsigned char c ) :654inline IntegerImpl<T>::IntegerImpl( unsigned char c ) :
584 value_( static_cast<long>( (unsigned long)c ) )655 value_( static_cast<long>( (unsigned long)T::check_value( c, false ) ) )
585{656{
586}657}
587658
588TEMPLATE_DECL(I)659template<class T>
589inline INTEGER_IMPL(I)::IntegerImpl( unsigned short n ) :660inline IntegerImpl<T>::IntegerImpl( unsigned short n ) :
590 value_( static_cast<long>( (unsigned long)n ) )661 value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) )
591{662{
592}663}
593664
594#ifdef ZORBA_WITH_BIG_INTEGER665#ifdef ZORBA_WITH_BIG_INTEGER
595#if ZORBA_SIZEOF_INT != ZORBA_SIZEOF_LONG666#if ZORBA_SIZEOF_INT != ZORBA_SIZEOF_LONG
596TEMPLATE_DECL(T)667template<class T>
597inline INTEGER_IMPL(T)::IntegerImpl( unsigned int n ) :668inline IntegerImpl<T>::IntegerImpl( unsigned int n ) :
598 value_( static_cast<long>( (unsigned long)n ) )669 value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) )
599{670{
600}671}
601#endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */672#endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */
602#else /* ZORBA_WITH_BIG_INTEGER */673#else /* ZORBA_WITH_BIG_INTEGER */
603TEMPLATE_DECL(I)674
604inline INTEGER_IMPL(I)::IntegerImpl( unsigned int n ) :675template<class T>
605 value_( static_cast<value_type>( n ) )676inline IntegerImpl<T>::IntegerImpl( unsigned int n ) :
606{677 value_( static_cast<value_type>( T::check_value( n, false ) ) )
607}678{
608679}
609TEMPLATE_DECL(I)680
610inline INTEGER_IMPL(I)::IntegerImpl( unsigned long n ) :681template<class T>
611 value_( static_cast<value_type>( n ) )682inline IntegerImpl<T>::IntegerImpl( unsigned long n ) :
612{683 value_( static_cast<value_type>( T::check_value( n, false ) ) )
613}684{
614685}
615TEMPLATE_DECL(I)686
616inline INTEGER_IMPL(I)::IntegerImpl( unsigned long long n ) :687template<class T>
617 value_( static_cast<value_type>( n ) )688inline IntegerImpl<T>::IntegerImpl( unsigned long long n ) :
618{689 value_( static_cast<value_type>( T::check_value( n, false ) ) )
619}690{
620#endif /* ZORBA_WITH_BIG_INTEGER */691}
621692#endif /* ZORBA_WITH_BIG_INTEGER */
622TEMPLATE_DECL(I)693
623inline INTEGER_IMPL(I)::IntegerImpl( float n ) :694template<class T>
624#ifdef ZORBA_WITH_BIG_INTEGER695inline IntegerImpl<T>::IntegerImpl( float n ) :
625 value_( static_cast<double>( n ) )696#ifdef ZORBA_WITH_BIG_INTEGER
626#else697 value_( static_cast<double>( T::check_value( n, false ) ) )
627 value_( static_cast<value_type>( n ) )698#else
628#endif /* ZORBA_WITH_BIG_INTEGER */699 value_( static_cast<value_type>( T::check_value( n, false ) ) )
629{700#endif /* ZORBA_WITH_BIG_INTEGER */
630}701{
631702}
632TEMPLATE_DECL(I)703
633inline INTEGER_IMPL(I)::IntegerImpl( double n ) :704template<class T>
634#ifdef ZORBA_WITH_BIG_INTEGER705inline IntegerImpl<T>::IntegerImpl( double n ) :
635 value_( n )706#ifdef ZORBA_WITH_BIG_INTEGER
636#else707 value_( T::check_value( n, false ) )
637 value_( static_cast<value_type>( n ) )708#else
638#endif /* ZORBA_WITH_BIG_INTEGER */709 value_( static_cast<value_type>( T::check_value( n, false ) ) )
639{710#endif /* ZORBA_WITH_BIG_INTEGER */
640}711{
641712}
642TEMPLATE_DECL(I)713
643inline INTEGER_IMPL(I)::IntegerImpl( char const *s ) {714template<class T>
644 parse( s );715inline IntegerImpl<T>::IntegerImpl( char const *s ) {
645}716 parse( s, false );
646717}
647TEMPLATE_DECL(I)718
648TEMPLATE_DECL(J)719template<class T>
649inline INTEGER_IMPL(I)::IntegerImpl( INTEGER_IMPL(J) const &i ) :720template<class U>
650 value_( i.value_ )721inline IntegerImpl<T>::IntegerImpl( IntegerImpl<U> const &i ) :
722 value_( T::check_value( i.value_, false ) )
651{723{
652}724}
653725
654////////// assignment operators ///////////////////////////////////////////////726////////// assignment operators ///////////////////////////////////////////////
655727
656#define ZORBA_ASSIGN_OP(T) \728#define ZORBA_ASSIGN_OP(N) \
657 TEMPLATE_DECL(I) inline \729 template<class T> inline \
658 INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( T n ) { \730 IntegerImpl<T>& IntegerImpl<T>::operator=( N n ) { \
659 value_ = static_cast<int_cast_type>( n ); \731 value_ = static_cast<int_cast_type>( T::check_value( n, false ) ); \
660 return *this; \732 return *this; \
661 }733 }
662734
663ZORBA_ASSIGN_OP(char)735ZORBA_ASSIGN_OP(char)
@@ -677,25 +749,25 @@
677#endif /* ZORBA_WITH_BIG_INTEGER */749#endif /* ZORBA_WITH_BIG_INTEGER */
678#undef ZORBA_ASSIGN_OP750#undef ZORBA_ASSIGN_OP
679751
680TEMPLATE_DECL(I)752template<class T>
681inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( char const *s ) {753inline IntegerImpl<T>& IntegerImpl<T>::operator=( char const *s ) {
682 parse( s );754 parse( s, false );
683 return *this;755 return *this;
684}756}
685757
686TEMPLATE_DECL(I) TEMPLATE_DECL(J)758template<class T>
687inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( INTEGER_IMPL(J) const &i ) {759template<class U>
688 value_ = i.value_;760inline IntegerImpl<T>& IntegerImpl<T>::operator=( IntegerImpl<U> const &i ) {
761 T::check_value( value_ = i.value_, false );
689 return *this;762 return *this;
690}763}
691764
692////////// arithmetic operators ///////////////////////////////////////////////765////////// arithmetic operators ///////////////////////////////////////////////
693766
694#define ZORBA_INTEGER_OP(OP) \767#define ZORBA_INTEGER_OP(OP) \
695 TEMPLATE_DECL(I) inline \768 template<class T,class U> inline \
696 INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const &i, \769 Integer operator OP( IntegerImpl<T> const &i, IntegerImpl<U> const &j ) { \
697 INTEGER_IMPL(I) const &j ) { \770 return Integer( i.value_ OP j.value_ ); \
698 return INTEGER_IMPL(I)( i.value_ OP j.value_ ); \
699 }771 }
700772
701ZORBA_INTEGER_OP(+)773ZORBA_INTEGER_OP(+)
@@ -704,21 +776,20 @@
704ZORBA_INTEGER_OP(%)776ZORBA_INTEGER_OP(%)
705#undef ZORBA_INTEGER_OP777#undef ZORBA_INTEGER_OP
706778
707TEMPLATE_DECL(I) inline779template<class T,class U>
708INTEGER_IMPL(I) operator/( INTEGER_IMPL(I) const &i,780inline Integer operator/( IntegerImpl<T> const &i, IntegerImpl<U> const &j ) {
709 INTEGER_IMPL(I) const &j ) {781 return Integer( Integer::ftoi( i.value_ / j.value_ ) );
710 return INTEGER_IMPL(I)( INTEGER_IMPL(I)::ftoi( i.value_ / j.value_ ) );
711}782}
712783
713#define ZORBA_INTEGER_OP(OP,T) \784#define ZORBA_INTEGER_OP(OP,N) \
714 TEMPLATE_DECL(I) inline \785 template<class T> inline \
715 INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const &i, T n ) { \786 Integer operator OP( IntegerImpl<T> const &i, N n ) { \
716 return INTEGER_IMPL(I)( i.value_ OP INTEGER_IMPL(I)::make_value_type( n ) ); \787 return Integer( i.value_ OP Integer::make_value_type( n ) ); \
717 } \788 } \
718 \789 \
719 TEMPLATE_DECL(I) inline \790 template<class T> inline \
720 INTEGER_IMPL(I) operator OP( T n, INTEGER_IMPL(I) const &i ) { \791 Integer operator OP( N n, IntegerImpl<T> const &i ) { \
721 return INTEGER_IMPL(I)( INTEGER_IMPL(I)::make_value_type( n ) OP i.value_ ); \792 return Integer( Integer::make_value_type( n ) OP i.value_ ); \
722 }793 }
723794
724ZORBA_INTEGER_OP(+,char)795ZORBA_INTEGER_OP(+,char)
@@ -777,15 +848,15 @@
777#endif /* ZORBA_WITH_BIG_INTEGER */848#endif /* ZORBA_WITH_BIG_INTEGER */
778#undef ZORBA_INTEGER_OP849#undef ZORBA_INTEGER_OP
779850
780#define ZORBA_INTEGER_OP(T) \851#define ZORBA_INTEGER_OP(N) \
781 TEMPLATE_DECL(I) inline \852 template<class T> inline \
782 INTEGER_IMPL(I) operator/( INTEGER_IMPL(I) const &i, T n ) { \853 Integer operator/( IntegerImpl<T> const &i, N n ) { \
783 return INTEGER_IMPL(I)( INTEGER_IMPL(I)::ftoi( i.value_ / INTEGER_IMPL(I)::make_value_type( n ) ) ); \854 return Integer( Integer::ftoi( i.value_ / Integer::make_value_type( n ) ) ); \
784 } \855 } \
785 \856 \
786 TEMPLATE_DECL(I) inline \857 template<class T> inline \
787 INTEGER_IMPL(I) operator/( T n, INTEGER_IMPL(I) const &i ) { \858 Integer operator/( N n, IntegerImpl<T> const &i ) { \
788 return INTEGER_IMPL(I)( INTEGER_IMPL(I)::ftoi( INTEGER_IMPL(I)::make_value_type( n ) / i.value_ ) ); \859 return Integer( Integer::ftoi( Integer::make_value_type( n ) / i.value_ ) ); \
789 }860 }
790861
791ZORBA_INTEGER_OP(signed char)862ZORBA_INTEGER_OP(signed char)
@@ -805,11 +876,11 @@
805#endif /* ZORBA_WITH_BIG_INTEGER */876#endif /* ZORBA_WITH_BIG_INTEGER */
806#undef ZORBA_INTEGER_OP877#undef ZORBA_INTEGER_OP
807878
808#define ZORBA_INTEGER_OP(OP) \879#define ZORBA_INTEGER_OP(OP) \
809 TEMPLATE_DECL(I) inline \880 template<class T> inline \
810 INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator OP( IntegerImpl const &i ) { \881 IntegerImpl<T>& IntegerImpl<T>::operator OP( IntegerImpl<T> const &i ) { \
811 value_ OP i.value_; \882 T::check_value( value_ OP i.value_, true ); \
812 return *this; \883 return *this; \
813 }884 }
814885
815ZORBA_INTEGER_OP(+=)886ZORBA_INTEGER_OP(+=)
@@ -818,17 +889,17 @@
818ZORBA_INTEGER_OP(%=)889ZORBA_INTEGER_OP(%=)
819#undef ZORBA_INTEGER_OP890#undef ZORBA_INTEGER_OP
820891
821TEMPLATE_DECL(I)892template<class T>
822inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator/=( IntegerImpl const &i ) {893inline IntegerImpl<T>& IntegerImpl<T>::operator/=( IntegerImpl<T> const &i ) {
823 value_ = ftoi( value_ / i.value_ );894 value_ = T::check_value( ftoi( value_ / i.value_ ), true );
824 return *this;895 return *this;
825}896}
826897
827#define ZORBA_INTEGER_OP(OP,T) \898#define ZORBA_INTEGER_OP(OP,N) \
828 TEMPLATE_DECL(I) inline \899 template<class T> inline \
829 INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator OP( T n ) { \900 IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \
830 value_ OP make_value_type( n ); \901 T::check_value( value_ OP make_value_type( n ), true ); \
831 return *this; \902 return *this; \
832 }903 }
833904
834ZORBA_INTEGER_OP(+=,char)905ZORBA_INTEGER_OP(+=,char)
@@ -887,11 +958,11 @@
887#endif /* ZORBA_WITH_BIG_INTEGER */958#endif /* ZORBA_WITH_BIG_INTEGER */
888#undef ZORBA_INTEGER_OP959#undef ZORBA_INTEGER_OP
889960
890#define ZORBA_INTEGER_OP(T) \961#define ZORBA_INTEGER_OP(N) \
891 TEMPLATE_DECL(I) inline \962 template<class T> inline \
892 INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator/=( T n ) { \963 IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \
893 value_ = ftoi( value_ / make_value_type( n ) ); \964 value_ = T::check_value( ftoi( value_ / make_value_type( n ) ), true ); \
894 return *this; \965 return *this; \
895 }966 }
896967
897ZORBA_INTEGER_OP(char)968ZORBA_INTEGER_OP(char)
@@ -911,243 +982,247 @@
911#endif /* ZORBA_WITH_BIG_INTEGER */982#endif /* ZORBA_WITH_BIG_INTEGER */
912#undef ZORBA_INTEGER_OP983#undef ZORBA_INTEGER_OP
913984
914TEMPLATE_DECL(I)985template<class T>
915inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator-() const {986inline Integer IntegerImpl<T>::operator-() const {
916 return INTEGER_IMPL(I)( -value_ );987 return Integer( -value_ );
917}988}
918989