Merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba
- bug-1090089
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Matthias Brantner |
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matthias Brantner | Approve | ||
Paul J. Lucas | Approve | ||
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:nonNegativeI
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:nonNegativeI
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.
Paul J. Lucas (paul-lucas) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
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/
Validation queue job bug-1090089-2013-04-
final status was:
No tests were run - build or configure step must have failed.
Not commiting changes.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
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/
Validation queue job bug-1090089-2013-04-
final status was:
No tests were run - build or configure step must have failed.
Not commiting changes.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
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/
Validation queue job bug-1090089-2013-04-
final status was:
25 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
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/
Validation queue job bug-1090089-2013-04-
final status was:
25 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
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/
Validation queue job bug-1090089-2013-05-
final status was:
8 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
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/
Validation queue job bug-1090089-2013-05-
final status was:
3 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
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/
Validation queue job bug-1090089-2013-05-
final status was:
2 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
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/
Validation queue job bug-1090089-2013-05-
final status was:
1 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job bug-1090089-2013-05-
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.
- 11442. By Paul J. Lucas
-
Merge from trunk.
- 11443. By Paul J. Lucas
-
Cosmetic change.
- 11444. By Paul J. Lucas
-
Now always returning Integer for binary operators.
- 11445. By Paul J. Lucas
-
Merge from trunk.
- 11446. By Paul J. Lucas
-
Updated ChangeLog.
- 11447. By Paul J. Lucas
-
Undid change.
Matthias Brantner (matthias-brantner) : | # |
Matthias Brantner (matthias-brantner) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job bug-1090089-2013-05-
All tests succeeded!
Preview Diff
1 | === modified file 'ChangeLog' | |||
2 | --- ChangeLog 2013-05-08 03:22:27 +0000 | |||
3 | +++ ChangeLog 2013-05-08 15:05:31 +0000 | |||
4 | @@ -1,5 +1,6 @@ | |||
5 | 1 | Zorba - The XQuery Processor | 1 | Zorba - The XQuery Processor |
6 | 2 | 2 | ||
7 | 3 | |||
8 | 3 | version 2.9 | 4 | version 2.9 |
9 | 4 | 5 | ||
10 | 5 | New Features: | 6 | New Features: |
11 | 6 | 7 | ||
12 | === modified file 'src/api/dynamiccontextimpl.cpp' | |||
13 | --- src/api/dynamiccontextimpl.cpp 2013-05-08 03:19:57 +0000 | |||
14 | +++ src/api/dynamiccontextimpl.cpp 2013-05-08 15:05:31 +0000 | |||
15 | @@ -27,6 +27,7 @@ | |||
16 | 27 | #include "types/typemanager.h" | 27 | #include "types/typemanager.h" |
17 | 28 | #include "types/root_typemanager.h" | 28 | #include "types/root_typemanager.h" |
18 | 29 | #include "types/schema/validate.h" | 29 | #include "types/schema/validate.h" |
19 | 30 | #include "zorbatypes/integer.h" | ||
20 | 30 | 31 | ||
21 | 31 | #include "api/unmarshaller.h" | 32 | #include "api/unmarshaller.h" |
22 | 32 | #include "api/zorbaimpl.h" | 33 | #include "api/zorbaimpl.h" |
23 | 33 | 34 | ||
24 | === modified file 'src/api/item.cpp' | |||
25 | --- src/api/item.cpp 2013-02-26 04:12:43 +0000 | |||
26 | +++ src/api/item.cpp 2013-05-08 15:05:31 +0000 | |||
27 | @@ -38,7 +38,9 @@ | |||
28 | 38 | #include "store/api/iterator.h" | 38 | #include "store/api/iterator.h" |
29 | 39 | #include "store/api/collection.h" | 39 | #include "store/api/collection.h" |
30 | 40 | 40 | ||
32 | 41 | #include <zorbatypes/numconversions.h> | 41 | #include "zorbatypes/floatimpl.h" |
33 | 42 | #include "zorbatypes/integer.h" | ||
34 | 43 | #include "zorbatypes/numconversions.h" | ||
35 | 42 | 44 | ||
36 | 43 | namespace zorba { | 45 | namespace zorba { |
37 | 44 | 46 | ||
38 | 45 | 47 | ||
39 | === modified file 'src/api/itemfactoryimpl.cpp' | |||
40 | --- src/api/itemfactoryimpl.cpp 2013-03-27 03:30:14 +0000 | |||
41 | +++ src/api/itemfactoryimpl.cpp 2013-05-08 15:05:31 +0000 | |||
42 | @@ -25,14 +25,17 @@ | |||
43 | 25 | 25 | ||
44 | 26 | #include "api/itemfactoryimpl.h" | 26 | #include "api/itemfactoryimpl.h" |
45 | 27 | 27 | ||
47 | 28 | #include "zorbatypes/duration.h" | 28 | #include "zorbatypes/decimal.h" |
48 | 29 | #include "zorbatypes/floatimpl.h" | ||
49 | 30 | #include "zorbatypes/integer.h" | ||
50 | 31 | #include "zorbatypes/schema_types.h" | ||
51 | 29 | 32 | ||
52 | 30 | #include "system/globalenv.h" | 33 | #include "system/globalenv.h" |
53 | 31 | 34 | ||
54 | 35 | #include "store/api/copymode.h" | ||
55 | 36 | #include "store/api/item.h" | ||
56 | 32 | #include "store/api/item_factory.h" | 37 | #include "store/api/item_factory.h" |
57 | 33 | #include "store/api/store.h" | 38 | #include "store/api/store.h" |
58 | 34 | #include "store/api/copymode.h" | ||
59 | 35 | #include "store/api/item.h" | ||
60 | 36 | 39 | ||
61 | 37 | #include "api/unmarshaller.h" | 40 | #include "api/unmarshaller.h" |
62 | 38 | 41 | ||
63 | 39 | 42 | ||
64 | === modified file 'src/api/serialization/serializer.cpp' | |||
65 | --- src/api/serialization/serializer.cpp 2013-04-25 02:05:20 +0000 | |||
66 | +++ src/api/serialization/serializer.cpp 2013-05-08 15:05:31 +0000 | |||
67 | @@ -39,6 +39,7 @@ | |||
68 | 39 | 39 | ||
69 | 40 | #include "system/globalenv.h" | 40 | #include "system/globalenv.h" |
70 | 41 | #include "zorbamisc/ns_consts.h" | 41 | #include "zorbamisc/ns_consts.h" |
71 | 42 | #include "zorbatypes/integer.h" | ||
72 | 42 | #include "zorbatypes/numconversions.h" | 43 | #include "zorbatypes/numconversions.h" |
73 | 43 | 44 | ||
74 | 44 | #include "store/api/iterator.h" | 45 | #include "store/api/iterator.h" |
75 | 45 | 46 | ||
76 | === modified file 'src/capi/csequence.cpp' | |||
77 | --- src/capi/csequence.cpp 2013-02-07 17:24:36 +0000 | |||
78 | +++ src/capi/csequence.cpp 2013-05-08 15:05:31 +0000 | |||
79 | @@ -18,16 +18,17 @@ | |||
80 | 18 | #include "capi/csequence.h" | 18 | #include "capi/csequence.h" |
81 | 19 | 19 | ||
82 | 20 | #include <cassert> | 20 | #include <cassert> |
84 | 21 | #include <string.h> | 21 | #include <cstring> |
85 | 22 | 22 | ||
86 | 23 | #include <zorba/zorba.h> | 23 | #include <zorba/zorba.h> |
87 | 24 | #include <zorba/diagnostic_list.h> | 24 | #include <zorba/diagnostic_list.h> |
88 | 25 | #include <zorba/iterator.h> | 25 | #include <zorba/iterator.h> |
89 | 26 | #include <zorba/store_consts.h> | 26 | #include <zorba/store_consts.h> |
90 | 27 | #include <zorbamisc/ns_consts.h> | ||
91 | 28 | #include <zorbatypes/numconversions.h> | ||
92 | 29 | 27 | ||
93 | 30 | #include "util/string_util.h" | 28 | #include "util/string_util.h" |
94 | 29 | #include "zorbamisc/ns_consts.h" | ||
95 | 30 | #include "zorbatypes/floatimpl.h" | ||
96 | 31 | #include "zorbatypes/numconversions.h" | ||
97 | 31 | 32 | ||
98 | 32 | #include "error.h" | 33 | #include "error.h" |
99 | 33 | 34 | ||
100 | 34 | 35 | ||
101 | === modified file 'src/common/shared_types.h' | |||
102 | --- src/common/shared_types.h 2013-04-26 04:44:36 +0000 | |||
103 | +++ src/common/shared_types.h 2013-05-08 15:05:31 +0000 | |||
104 | @@ -133,18 +133,20 @@ | |||
105 | 133 | typedef rchandle<GMonth> GMonth_t; | 133 | typedef rchandle<GMonth> GMonth_t; |
106 | 134 | 134 | ||
107 | 135 | /* numerics */ | 135 | /* numerics */ |
109 | 136 | template<typename FloatType> class FloatImpl; | 136 | template<typename F> class FloatImpl; |
110 | 137 | typedef FloatImpl<double> Double; | 137 | typedef FloatImpl<double> Double; |
111 | 138 | typedef FloatImpl<float> Float; | 138 | typedef FloatImpl<float> Float; |
121 | 139 | #ifdef ZORBA_WITH_BIG_INTEGER | 139 | class integer_traits; |
122 | 140 | class IntegerImpl; | 140 | class negative_traits; |
123 | 141 | typedef IntegerImpl Integer; | 141 | class nonNegative_traits; |
124 | 142 | typedef IntegerImpl UInteger; | 142 | class nonPositive_traits; |
125 | 143 | #else | 143 | class positive_traits; |
126 | 144 | template<typename IntType> class IntegerImpl; | 144 | template<class T> class IntegerImpl; |
127 | 145 | typedef IntegerImpl<long long> Integer; | 145 | typedef IntegerImpl<integer_traits> Integer; |
128 | 146 | typedef IntegerImpl<unsigned long long> UInteger; | 146 | typedef IntegerImpl<negative_traits> NegativeInteger; |
129 | 147 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 147 | typedef IntegerImpl<nonNegative_traits> NonNegativeInteger; |
130 | 148 | typedef IntegerImpl<nonPositive_traits> NonPositiveInteger; | ||
131 | 149 | typedef IntegerImpl<positive_traits> PositiveInteger; | ||
132 | 148 | 150 | ||
133 | 149 | /* api */ | 151 | /* api */ |
134 | 150 | class serializer; | 152 | class serializer; |
135 | 151 | 153 | ||
136 | === modified file 'src/compiler/expression/expr.cpp' | |||
137 | --- src/compiler/expression/expr.cpp 2013-03-07 10:10:10 +0000 | |||
138 | +++ src/compiler/expression/expr.cpp 2013-05-08 15:05:31 +0000 | |||
139 | @@ -49,6 +49,9 @@ | |||
140 | 49 | 49 | ||
141 | 50 | #include "store/api/store.h" | 50 | #include "store/api/store.h" |
142 | 51 | #include "store/api/item_factory.h" | 51 | #include "store/api/item_factory.h" |
143 | 52 | #include "zorbatypes/decimal.h" | ||
144 | 53 | #include "zorbatypes/floatimpl.h" | ||
145 | 54 | #include "zorbatypes/integer.h" | ||
146 | 52 | 55 | ||
147 | 53 | 56 | ||
148 | 54 | namespace zorba | 57 | namespace zorba |
149 | 55 | 58 | ||
150 | === modified file 'src/compiler/expression/expr_manager.cpp' | |||
151 | --- src/compiler/expression/expr_manager.cpp 2013-04-16 20:06:08 +0000 | |||
152 | +++ src/compiler/expression/expr_manager.cpp 2013-05-08 15:05:31 +0000 | |||
153 | @@ -15,22 +15,24 @@ | |||
154 | 15 | */ | 15 | */ |
155 | 16 | 16 | ||
156 | 17 | #include "stdafx.h" | 17 | #include "stdafx.h" |
157 | 18 | |||
158 | 19 | #include "zorbatypes/decimal.h" | ||
159 | 20 | #include "zorbatypes/integer.h" | ||
160 | 21 | |||
161 | 22 | #include "expr.h" | ||
162 | 18 | #include "expr_manager.h" | 23 | #include "expr_manager.h" |
163 | 19 | |||
164 | 20 | #include "mem_manager.h" | ||
165 | 21 | |||
166 | 22 | #include "expr.h" | ||
167 | 23 | #include "ftnode.h" | ||
168 | 24 | #include "var_expr.h" | ||
169 | 25 | #include "flwor_expr.h" | 24 | #include "flwor_expr.h" |
170 | 26 | #include "fo_expr.h" | 25 | #include "fo_expr.h" |
171 | 27 | #include "ft_expr.h" | 26 | #include "ft_expr.h" |
172 | 27 | #include "ftnode.h" | ||
173 | 28 | #include "function_item_expr.h" | 28 | #include "function_item_expr.h" |
174 | 29 | #include "json_exprs.h" | ||
175 | 30 | #include "mem_manager.h" | ||
176 | 29 | #include "path_expr.h" | 31 | #include "path_expr.h" |
177 | 32 | #include "pragma.h" | ||
178 | 30 | #include "script_exprs.h" | 33 | #include "script_exprs.h" |
179 | 31 | #include "update_exprs.h" | 34 | #include "update_exprs.h" |
182 | 32 | #include "json_exprs.h" | 35 | #include "var_expr.h" |
181 | 33 | #include "pragma.h" | ||
183 | 34 | 36 | ||
184 | 35 | namespace zorba | 37 | namespace zorba |
185 | 36 | { | 38 | { |
186 | 37 | 39 | ||
187 | === modified file 'src/compiler/parser/jsoniq_parser.cpp' | |||
188 | --- src/compiler/parser/jsoniq_parser.cpp 2013-04-24 17:26:02 +0000 | |||
189 | +++ src/compiler/parser/jsoniq_parser.cpp 2013-05-08 15:05:31 +0000 | |||
190 | @@ -50,14 +50,13 @@ | |||
191 | 50 | #pragma warning(disable: 4786) | 50 | #pragma warning(disable: 4786) |
192 | 51 | #endif | 51 | #endif |
193 | 52 | 52 | ||
194 | 53 | #include "compiler/api/compilercb.h" | ||
195 | 54 | #include "compiler/parser/parse_constants.h" | ||
196 | 55 | #include "compiler/parser/parser_helpers.h" | ||
197 | 56 | #include "compiler/parser/xquery_driver.h" | ||
198 | 53 | #include "compiler/parsetree/parsenodes.h" | 57 | #include "compiler/parsetree/parsenodes.h" |
199 | 54 | #include "compiler/parser/parse_constants.h" | ||
200 | 55 | #include "compiler/api/compilercb.h" | ||
201 | 56 | #include "store/api/update_consts.h" | 58 | #include "store/api/update_consts.h" |
206 | 57 | 59 | #include "zorbatypes/integer.h" | |
203 | 58 | #include "compiler/parser/xquery_driver.h" | ||
204 | 59 | |||
205 | 60 | #include "compiler/parser/parser_helpers.h" | ||
207 | 61 | 60 | ||
208 | 62 | #define SYMTAB( n ) driver.symtab.get( (off_t)n ) | 61 | #define SYMTAB( n ) driver.symtab.get( (off_t)n ) |
209 | 63 | #define SYMTAB_PUT( s ) driver.symtab.put( s ) | 62 | #define SYMTAB_PUT( s ) driver.symtab.put( s ) |
210 | 64 | 63 | ||
211 | === modified file 'src/compiler/parser/parser_helpers.h' | |||
212 | --- src/compiler/parser/parser_helpers.h 2013-03-16 00:58:28 +0000 | |||
213 | +++ src/compiler/parser/parser_helpers.h 2013-05-08 15:05:31 +0000 | |||
214 | @@ -23,6 +23,8 @@ | |||
215 | 23 | 23 | ||
216 | 24 | namespace zorba { | 24 | namespace zorba { |
217 | 25 | 25 | ||
218 | 26 | class location; | ||
219 | 27 | |||
220 | 26 | namespace parser { | 28 | namespace parser { |
221 | 27 | 29 | ||
222 | 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; |
223 | 29 | 31 | ||
224 | === modified file 'src/compiler/parser/parser_y_includes.h' | |||
225 | --- src/compiler/parser/parser_y_includes.h 2013-04-17 18:08:27 +0000 | |||
226 | +++ src/compiler/parser/parser_y_includes.h 2013-05-08 15:05:31 +0000 | |||
227 | @@ -60,14 +60,14 @@ | |||
228 | 60 | #pragma warning(disable: 4786) | 60 | #pragma warning(disable: 4786) |
229 | 61 | #endif | 61 | #endif |
230 | 62 | 62 | ||
232 | 63 | #include "compiler/parsetree/parsenodes.h" | 63 | #include "compiler/api/compilercb.h" |
233 | 64 | #include "compiler/parser/parse_constants.h" | 64 | #include "compiler/parser/parse_constants.h" |
235 | 65 | #include "compiler/api/compilercb.h" | 65 | #include "compiler/parser/parser_helpers.h" |
236 | 66 | #include "compiler/parser/xquery_driver.h" | ||
237 | 67 | #include "compiler/parsetree/parsenodes.h" | ||
238 | 66 | #include "store/api/update_consts.h" | 68 | #include "store/api/update_consts.h" |
243 | 67 | 69 | #include "zorbatypes/decimal.h" | |
244 | 68 | #include "compiler/parser/xquery_driver.h" | 70 | #include "zorbatypes/integer.h" |
241 | 69 | |||
242 | 70 | #include "compiler/parser/parser_helpers.h" | ||
245 | 71 | 71 | ||
246 | 72 | #define SYMTAB( n ) driver.symtab.get( (off_t)n ) | 72 | #define SYMTAB( n ) driver.symtab.get( (off_t)n ) |
247 | 73 | #define SYMTAB_PUT( s ) driver.symtab.put( s ) | 73 | #define SYMTAB_PUT( s ) driver.symtab.put( s ) |
248 | 74 | 74 | ||
249 | === modified file 'src/compiler/parser/symbol_table.cpp' | |||
250 | --- src/compiler/parser/symbol_table.cpp 2013-03-25 19:47:18 +0000 | |||
251 | +++ src/compiler/parser/symbol_table.cpp 2013-05-08 15:05:31 +0000 | |||
252 | @@ -15,6 +15,9 @@ | |||
253 | 15 | */ | 15 | */ |
254 | 16 | #include "stdafx.h" | 16 | #include "stdafx.h" |
255 | 17 | 17 | ||
256 | 18 | #include "zorbatypes/decimal.h" | ||
257 | 19 | #include "zorbatypes/floatimpl.h" | ||
258 | 20 | #include "zorbatypes/integer.h" | ||
259 | 18 | #include "zorbatypes/numconversions.h" | 21 | #include "zorbatypes/numconversions.h" |
260 | 19 | 22 | ||
261 | 20 | #include "compiler/parser/symbol_table.h" | 23 | #include "compiler/parser/symbol_table.h" |
262 | 21 | 24 | ||
263 | === modified file 'src/compiler/parser/xquery_parser.cpp' | |||
264 | --- src/compiler/parser/xquery_parser.cpp 2013-04-24 17:26:02 +0000 | |||
265 | +++ src/compiler/parser/xquery_parser.cpp 2013-05-08 15:05:31 +0000 | |||
266 | @@ -50,14 +50,13 @@ | |||
267 | 50 | #pragma warning(disable: 4786) | 50 | #pragma warning(disable: 4786) |
268 | 51 | #endif | 51 | #endif |
269 | 52 | 52 | ||
270 | 53 | #include "compiler/api/compilercb.h" | ||
271 | 54 | #include "compiler/parser/parse_constants.h" | ||
272 | 55 | #include "compiler/parser/parser_helpers.h" | ||
273 | 56 | #include "compiler/parser/xquery_driver.h" | ||
274 | 53 | #include "compiler/parsetree/parsenodes.h" | 57 | #include "compiler/parsetree/parsenodes.h" |
275 | 54 | #include "compiler/parser/parse_constants.h" | ||
276 | 55 | #include "compiler/api/compilercb.h" | ||
277 | 56 | #include "store/api/update_consts.h" | 58 | #include "store/api/update_consts.h" |
282 | 57 | 59 | #include "zorbatypes/integer.h" | |
279 | 58 | #include "compiler/parser/xquery_driver.h" | ||
280 | 59 | |||
281 | 60 | #include "compiler/parser/parser_helpers.h" | ||
283 | 61 | 60 | ||
284 | 62 | #define SYMTAB( n ) driver.symtab.get( (off_t)n ) | 61 | #define SYMTAB( n ) driver.symtab.get( (off_t)n ) |
285 | 63 | #define SYMTAB_PUT( s ) driver.symtab.put( s ) | 62 | #define SYMTAB_PUT( s ) driver.symtab.put( s ) |
286 | 64 | 63 | ||
287 | === modified file 'src/compiler/parsetree/parsenode_print_xml_visitor.cpp' | |||
288 | --- src/compiler/parsetree/parsenode_print_xml_visitor.cpp 2013-03-22 00:38:18 +0000 | |||
289 | +++ src/compiler/parsetree/parsenode_print_xml_visitor.cpp 2013-05-08 15:05:31 +0000 | |||
290 | @@ -16,9 +16,12 @@ | |||
291 | 16 | #include "stdafx.h" | 16 | #include "stdafx.h" |
292 | 17 | 17 | ||
293 | 18 | #include <ostream> | 18 | #include <ostream> |
296 | 19 | #include "compiler/parsetree/parsenode_print_xml_visitor.h" | 19 | |
295 | 20 | #include "compiler/parsetree/parsenode_visitor.h" | ||
297 | 21 | #include "types/typemanager.h" | 20 | #include "types/typemanager.h" |
298 | 21 | #include "zorbatypes/integer.h" | ||
299 | 22 | |||
300 | 23 | #include "parsenode_print_xml_visitor.h" | ||
301 | 24 | #include "parsenode_visitor.h" | ||
302 | 22 | 25 | ||
303 | 23 | using namespace std; | 26 | using namespace std; |
304 | 24 | 27 | ||
305 | 25 | 28 | ||
306 | === modified file 'src/compiler/parsetree/parsenodes.cpp' | |||
307 | --- src/compiler/parsetree/parsenodes.cpp 2013-04-17 22:41:05 +0000 | |||
308 | +++ src/compiler/parsetree/parsenodes.cpp 2013-05-08 15:05:31 +0000 | |||
309 | @@ -29,6 +29,7 @@ | |||
310 | 29 | #include "compiler/parsetree/parsenodes.h" | 29 | #include "compiler/parsetree/parsenodes.h" |
311 | 30 | #include "compiler/parser/parse_constants.h" | 30 | #include "compiler/parser/parse_constants.h" |
312 | 31 | #include "compiler/parsetree/parsenode_visitor.h" | 31 | #include "compiler/parsetree/parsenode_visitor.h" |
313 | 32 | #include "zorbatypes/integer.h" | ||
314 | 32 | 33 | ||
315 | 33 | #include <iostream> | 34 | #include <iostream> |
316 | 34 | #include <sstream> | 35 | #include <sstream> |
317 | 35 | 36 | ||
318 | === modified file 'src/compiler/parsetree/parsenodes.h' | |||
319 | --- src/compiler/parsetree/parsenodes.h 2013-05-08 03:19:57 +0000 | |||
320 | +++ src/compiler/parsetree/parsenodes.h 2013-05-08 15:05:31 +0000 | |||
321 | @@ -32,6 +32,9 @@ | |||
322 | 32 | 32 | ||
323 | 33 | #include "store/api/item.h" | 33 | #include "store/api/item.h" |
324 | 34 | 34 | ||
325 | 35 | #include "zorbatypes/decimal.h" | ||
326 | 36 | #include "zorbatypes/integer.h" | ||
327 | 37 | #include "zorbatypes/floatimpl.h" | ||
328 | 35 | #include "zorbatypes/rchandle.h" | 38 | #include "zorbatypes/rchandle.h" |
329 | 36 | #include "zorbatypes/schema_types.h" | 39 | #include "zorbatypes/schema_types.h" |
330 | 37 | #include "zorbatypes/zstring.h" | 40 | #include "zorbatypes/zstring.h" |
331 | 38 | 41 | ||
332 | === modified file 'src/compiler/rewriter/rules/flwor_rules.cpp' | |||
333 | --- src/compiler/rewriter/rules/flwor_rules.cpp 2013-04-15 12:07:41 +0000 | |||
334 | +++ src/compiler/rewriter/rules/flwor_rules.cpp 2013-05-08 15:05:31 +0000 | |||
335 | @@ -37,6 +37,8 @@ | |||
336 | 37 | 37 | ||
337 | 38 | #include "system/properties.h" | 38 | #include "system/properties.h" |
338 | 39 | 39 | ||
339 | 40 | #include "zorbatypes/integer.h" | ||
340 | 41 | |||
341 | 40 | #include <memory> | 42 | #include <memory> |
342 | 41 | #include <iterator> | 43 | #include <iterator> |
343 | 42 | 44 | ||
344 | @@ -300,7 +302,7 @@ | |||
345 | 300 | if (pvar != NULL) | 302 | if (pvar != NULL) |
346 | 301 | { | 303 | { |
347 | 302 | expr* constExpr = rCtx.theEM-> | 304 | expr* constExpr = rCtx.theEM-> |
349 | 303 | create_const_expr(sctx, udf, loc, xs_integer::zero()); | 305 | create_const_expr(sctx, udf, loc, numeric_consts<xs_integer>::zero()); |
350 | 304 | 306 | ||
351 | 305 | subst_vars(rCtx, pvar, constExpr, 2); | 307 | subst_vars(rCtx, pvar, constExpr, 2); |
352 | 306 | fc->set_pos_var(NULL); | 308 | fc->set_pos_var(NULL); |
353 | @@ -318,7 +320,7 @@ | |||
354 | 318 | if (pvar != NULL && (domQuant == TypeConstants::QUANT_ONE || ! outerFor)) | 320 | if (pvar != NULL && (domQuant == TypeConstants::QUANT_ONE || ! outerFor)) |
355 | 319 | { | 321 | { |
356 | 320 | expr* constExpr = rCtx.theEM-> | 322 | expr* constExpr = rCtx.theEM-> |
358 | 321 | create_const_expr(sctx, udf, loc, xs_integer::one()); | 323 | create_const_expr(sctx, udf, loc, numeric_consts<xs_integer>::one()); |
359 | 322 | 324 | ||
360 | 323 | subst_vars(rCtx, pvar, constExpr, 2); | 325 | subst_vars(rCtx, pvar, constExpr, 2); |
361 | 324 | fc->set_pos_var(NULL); | 326 | fc->set_pos_var(NULL); |
362 | @@ -461,7 +463,7 @@ | |||
363 | 461 | // since one value is still returned, count variables are changed to 1 | 463 | // since one value is still returned, count variables are changed to 1 |
364 | 462 | subst_vars(rCtx, | 464 | subst_vars(rCtx, |
365 | 463 | static_cast<count_clause*>(clause)->get_var(), | 465 | static_cast<count_clause*>(clause)->get_var(), |
367 | 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()), |
368 | 465 | 2); | 467 | 2); |
369 | 466 | 468 | ||
370 | 467 | theFlwor->remove_clause(0); | 469 | theFlwor->remove_clause(0); |
371 | 468 | 470 | ||
372 | === modified file 'src/compiler/rewriter/rules/fold_rules.cpp' | |||
373 | --- src/compiler/rewriter/rules/fold_rules.cpp 2013-05-04 20:20:05 +0000 | |||
374 | +++ src/compiler/rewriter/rules/fold_rules.cpp 2013-05-08 15:05:31 +0000 | |||
375 | @@ -47,6 +47,8 @@ | |||
376 | 47 | #include "store/api/store.h" | 47 | #include "store/api/store.h" |
377 | 48 | #include "store/api/item_factory.h" | 48 | #include "store/api/item_factory.h" |
378 | 49 | 49 | ||
379 | 50 | #include "zorbatypes/integer.h" | ||
380 | 51 | |||
381 | 50 | #include <iterator> | 52 | #include <iterator> |
382 | 51 | 53 | ||
383 | 52 | namespace zorba { | 54 | namespace zorba { |
384 | 53 | 55 | ||
385 | === modified file 'src/compiler/translator/translator.cpp' | |||
386 | --- src/compiler/translator/translator.cpp 2013-05-08 08:01:05 +0000 | |||
387 | +++ src/compiler/translator/translator.cpp 2013-05-08 15:05:31 +0000 | |||
388 | @@ -88,9 +88,12 @@ | |||
389 | 88 | #include "types/typemanagerimpl.h" | 88 | #include "types/typemanagerimpl.h" |
390 | 89 | #include "types/schema/schema.h" | 89 | #include "types/schema/schema.h" |
391 | 90 | 90 | ||
392 | 91 | #include "zorbamisc/ns_consts.h" | ||
393 | 92 | #include "zorbatypes/decimal.h" | ||
394 | 93 | #include "zorbatypes/floatimpl.h" | ||
395 | 94 | #include "zorbatypes/integer.h" | ||
396 | 95 | #include "zorbatypes/numconversions.h" | ||
397 | 91 | #include "zorbatypes/URI.h" | 96 | #include "zorbatypes/URI.h" |
398 | 92 | #include "zorbatypes/numconversions.h" | ||
399 | 93 | #include "zorbamisc/ns_consts.h" | ||
400 | 94 | 97 | ||
401 | 95 | #ifdef ZORBA_WITH_DEBUGGER | 98 | #ifdef ZORBA_WITH_DEBUGGER |
402 | 96 | #include "debugger/debugger_commons.h" | 99 | #include "debugger/debugger_commons.h" |
403 | @@ -11932,8 +11935,8 @@ | |||
404 | 11932 | } | 11935 | } |
405 | 11933 | case FunctionConsts::FN_HEAD_1: | 11936 | case FunctionConsts::FN_HEAD_1: |
406 | 11934 | { | 11937 | { |
409 | 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())); |
410 | 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())); |
411 | 11937 | 11940 | ||
412 | 11938 | function* f = BUILTIN_FUNC(OP_ZORBA_SUBSEQUENCE_INT_3); | 11941 | function* f = BUILTIN_FUNC(OP_ZORBA_SUBSEQUENCE_INT_3); |
413 | 11939 | 11942 | ||
414 | 11940 | 11943 | ||
415 | === modified file 'src/functions/udf.cpp' | |||
416 | --- src/functions/udf.cpp 2013-04-24 01:35:58 +0000 | |||
417 | +++ src/functions/udf.cpp 2013-05-08 15:05:31 +0000 | |||
418 | @@ -36,6 +36,7 @@ | |||
419 | 36 | #include "diagnostics/assert.h" | 36 | #include "diagnostics/assert.h" |
420 | 37 | 37 | ||
421 | 38 | #include "types/typeops.h" | 38 | #include "types/typeops.h" |
422 | 39 | #include "zorbatypes/integer.h" | ||
423 | 39 | 40 | ||
424 | 40 | #include "zorbaserialization/serialize_template_types.h" | 41 | #include "zorbaserialization/serialize_template_types.h" |
425 | 41 | #include "zorbaserialization/serialize_zorba_types.h" | 42 | #include "zorbaserialization/serialize_zorba_types.h" |
426 | 42 | 43 | ||
427 | === modified file 'src/runtime/base/plan_iterator.cpp' | |||
428 | --- src/runtime/base/plan_iterator.cpp 2013-03-24 20:40:03 +0000 | |||
429 | +++ src/runtime/base/plan_iterator.cpp 2013-05-08 15:05:31 +0000 | |||
430 | @@ -15,18 +15,14 @@ | |||
431 | 15 | */ | 15 | */ |
432 | 16 | #include "stdafx.h" | 16 | #include "stdafx.h" |
433 | 17 | 17 | ||
434 | 18 | #include "compiler/api/compilercb.h" | ||
435 | 18 | #include "context/static_context.h" | 19 | #include "context/static_context.h" |
436 | 19 | |||
437 | 20 | #include "compiler/api/compilercb.h" | ||
438 | 21 | |||
439 | 22 | #include "runtime/base/plan_iterator.h" | 20 | #include "runtime/base/plan_iterator.h" |
440 | 23 | |||
441 | 24 | #include "runtime/util/flowctl_exception.h" | 21 | #include "runtime/util/flowctl_exception.h" |
443 | 25 | 22 | #include "store/api/item_factory.h" | |
444 | 23 | #include "store/api/store.h" | ||
445 | 26 | #include "system/globalenv.h" | 24 | #include "system/globalenv.h" |
449 | 27 | 25 | #include "zorbatypes/integer.h" | |
447 | 28 | #include "store/api/store.h" | ||
448 | 29 | #include "store/api/item_factory.h" | ||
450 | 30 | 26 | ||
451 | 31 | 27 | ||
452 | 32 | namespace zorba | 28 | namespace zorba |
453 | 33 | 29 | ||
454 | === modified file 'src/runtime/booleans/BooleanImpl.cpp' | |||
455 | --- src/runtime/booleans/BooleanImpl.cpp 2013-05-02 00:18:56 +0000 | |||
456 | +++ src/runtime/booleans/BooleanImpl.cpp 2013-05-08 15:05:31 +0000 | |||
457 | @@ -20,6 +20,7 @@ | |||
458 | 20 | 20 | ||
459 | 21 | #include "zorbatypes/collation_manager.h" | 21 | #include "zorbatypes/collation_manager.h" |
460 | 22 | #include "zorbatypes/datetime.h" | 22 | #include "zorbatypes/datetime.h" |
461 | 23 | #include "zorbatypes/integer.h" | ||
462 | 23 | 24 | ||
463 | 24 | #include "system/globalenv.h" | 25 | #include "system/globalenv.h" |
464 | 25 | 26 | ||
465 | 26 | 27 | ||
466 | === modified file 'src/runtime/collections/collections_base.h' | |||
467 | --- src/runtime/collections/collections_base.h 2013-02-07 17:24:36 +0000 | |||
468 | +++ src/runtime/collections/collections_base.h 2013-05-08 15:05:31 +0000 | |||
469 | @@ -31,6 +31,7 @@ | |||
470 | 31 | #include "types/typeimpl.h" | 31 | #include "types/typeimpl.h" |
471 | 32 | 32 | ||
472 | 33 | #include "diagnostics/util_macros.h" | 33 | #include "diagnostics/util_macros.h" |
473 | 34 | #include "zorbatypes/integer.h" | ||
474 | 34 | 35 | ||
475 | 35 | 36 | ||
476 | 36 | namespace zorba { | 37 | namespace zorba { |
477 | 37 | 38 | ||
478 | === modified file 'src/runtime/collections/collections_impl.cpp' | |||
479 | --- src/runtime/collections/collections_impl.cpp 2013-03-24 20:40:03 +0000 | |||
480 | +++ src/runtime/collections/collections_impl.cpp 2013-05-08 15:05:31 +0000 | |||
481 | @@ -307,9 +307,9 @@ | |||
482 | 307 | lSkip = lSkipItem->getIntegerValue(); | 307 | lSkip = lSkipItem->getIntegerValue(); |
483 | 308 | 308 | ||
484 | 309 | // negative skip is not allowed | 309 | // negative skip is not allowed |
486 | 310 | if (lSkip < xs_integer::zero()) | 310 | if (lSkip.sign() < 0) |
487 | 311 | { | 311 | { |
489 | 312 | lSkip = xs_integer::zero(); | 312 | lSkip = numeric_consts<xs_integer>::zero(); |
490 | 313 | } | 313 | } |
491 | 314 | 314 | ||
492 | 315 | if (!lRefPassed) | 315 | if (!lRefPassed) |
493 | @@ -381,11 +381,10 @@ | |||
494 | 381 | // skip parameter passed | 381 | // skip parameter passed |
495 | 382 | store::Item_t skipItem; | 382 | store::Item_t skipItem; |
496 | 383 | consumeNext(skipItem, theChildren[1].getp(), planState); | 383 | consumeNext(skipItem, theChildren[1].getp(), planState); |
502 | 384 | xs_integer skip = skipItem->getIntegerValue(); | 384 | xs_integer skip( skipItem->getIntegerValue() ); |
503 | 385 | 385 | ||
504 | 386 | count -= (skip <= xs_integer::zero() ? xs_integer::zero() : skip); | 386 | count -= (skip.sign() <= 0 ? numeric_consts<xs_integer>::zero() : skip); |
505 | 387 | 387 | count = (count.sign() < 0 ? numeric_consts<xs_integer>::zero() : count); | |
501 | 388 | count = (count < xs_integer::zero() ? xs_integer::zero() : count); | ||
506 | 389 | } | 388 | } |
507 | 390 | 389 | ||
508 | 391 | STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, count), state); | 390 | STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, count), state); |
509 | 392 | 391 | ||
510 | === modified file 'src/runtime/core/arithmetic_impl.cpp' | |||
511 | --- src/runtime/core/arithmetic_impl.cpp 2013-04-08 21:32:54 +0000 | |||
512 | +++ src/runtime/core/arithmetic_impl.cpp 2013-05-08 15:05:31 +0000 | |||
513 | @@ -21,6 +21,7 @@ | |||
514 | 21 | #include "diagnostics/util_macros.h" | 21 | #include "diagnostics/util_macros.h" |
515 | 22 | 22 | ||
516 | 23 | #include "zorbatypes/datetime.h" | 23 | #include "zorbatypes/datetime.h" |
517 | 24 | #include "zorbatypes/decimal.h" | ||
518 | 24 | #include "zorbatypes/duration.h" | 25 | #include "zorbatypes/duration.h" |
519 | 25 | 26 | ||
520 | 26 | #include "system/globalenv.h" | 27 | #include "system/globalenv.h" |
521 | 27 | 28 | ||
522 | === modified file 'src/runtime/core/var_iterators.h' | |||
523 | --- src/runtime/core/var_iterators.h 2013-05-08 08:01:05 +0000 | |||
524 | +++ src/runtime/core/var_iterators.h 2013-05-08 15:05:31 +0000 | |||
525 | @@ -23,7 +23,7 @@ | |||
526 | 23 | #include "runtime/base/unarybase.h" | 23 | #include "runtime/base/unarybase.h" |
527 | 24 | #include "runtime/base/narybase.h" | 24 | #include "runtime/base/narybase.h" |
528 | 25 | 25 | ||
530 | 26 | #include "zorbatypes/schema_types.h" | 26 | #include "zorbatypes/integer.h" |
531 | 27 | 27 | ||
532 | 28 | 28 | ||
533 | 29 | namespace zorba | 29 | namespace zorba |
534 | 30 | 30 | ||
535 | === modified file 'src/runtime/durations_dates_times/durations_dates_times_impl.cpp' | |||
536 | --- src/runtime/durations_dates_times/durations_dates_times_impl.cpp 2013-02-07 17:24:36 +0000 | |||
537 | +++ src/runtime/durations_dates_times/durations_dates_times_impl.cpp 2013-05-08 15:05:31 +0000 | |||
538 | @@ -17,6 +17,8 @@ | |||
539 | 17 | 17 | ||
540 | 18 | #include "zorbatypes/datetime.h" | 18 | #include "zorbatypes/datetime.h" |
541 | 19 | #include "zorbatypes/duration.h" | 19 | #include "zorbatypes/duration.h" |
542 | 20 | #include "zorbatypes/decimal.h" | ||
543 | 21 | #include "zorbatypes/integer.h" | ||
544 | 20 | #include "zorbatypes/numconversions.h" | 22 | #include "zorbatypes/numconversions.h" |
545 | 21 | #include "zorbatypes/datetime/parse.h" | 23 | #include "zorbatypes/datetime/parse.h" |
546 | 22 | 24 | ||
547 | 23 | 25 | ||
548 | === modified file 'src/runtime/full_text/ft_module_impl.cpp' | |||
549 | --- src/runtime/full_text/ft_module_impl.cpp 2013-04-16 22:12:03 +0000 | |||
550 | +++ src/runtime/full_text/ft_module_impl.cpp 2013-05-08 15:05:31 +0000 | |||
551 | @@ -46,6 +46,7 @@ | |||
552 | 46 | #include "types/typeops.h" | 46 | #include "types/typeops.h" |
553 | 47 | #include "util/stl_util.h" | 47 | #include "util/stl_util.h" |
554 | 48 | #include "util/utf8_util.h" | 48 | #include "util/utf8_util.h" |
555 | 49 | #include "zorbatypes/integer.h" | ||
556 | 49 | #include "zorbatypes/URI.h" | 50 | #include "zorbatypes/URI.h" |
557 | 50 | #include "zorbautils/locale.h" | 51 | #include "zorbautils/locale.h" |
558 | 51 | 52 | ||
559 | 52 | 53 | ||
560 | === modified file 'src/runtime/full_text/ft_util.cpp' | |||
561 | --- src/runtime/full_text/ft_util.cpp 2013-02-07 17:24:36 +0000 | |||
562 | +++ src/runtime/full_text/ft_util.cpp 2013-05-08 15:05:31 +0000 | |||
563 | @@ -20,6 +20,7 @@ | |||
564 | 20 | 20 | ||
565 | 21 | #include "diagnostics/xquery_diagnostics.h" | 21 | #include "diagnostics/xquery_diagnostics.h" |
566 | 22 | #include "zorbamisc/ns_consts.h" | 22 | #include "zorbamisc/ns_consts.h" |
567 | 23 | #include "zorbatypes/integer.h" | ||
568 | 23 | #include "zorbatypes/numconversions.h" | 24 | #include "zorbatypes/numconversions.h" |
569 | 24 | #include "zorbautils/locale.h" | 25 | #include "zorbautils/locale.h" |
570 | 25 | 26 | ||
571 | 26 | 27 | ||
572 | === modified file 'src/runtime/full_text/ftcontains_visitor.cpp' | |||
573 | --- src/runtime/full_text/ftcontains_visitor.cpp 2013-02-07 17:24:36 +0000 | |||
574 | +++ src/runtime/full_text/ftcontains_visitor.cpp 2013-05-08 15:05:31 +0000 | |||
575 | @@ -24,12 +24,11 @@ | |||
576 | 24 | #include "compiler/parser/query_loc.h" | 24 | #include "compiler/parser/query_loc.h" |
577 | 25 | #include "diagnostics/xquery_diagnostics.h" | 25 | #include "diagnostics/xquery_diagnostics.h" |
578 | 26 | #include "store/api/store.h" | 26 | #include "store/api/store.h" |
579 | 27 | |||
580 | 28 | #include "system/globalenv.h" | 27 | #include "system/globalenv.h" |
581 | 29 | |||
582 | 30 | #include "util/cxx_util.h" | 28 | #include "util/cxx_util.h" |
583 | 31 | #include "util/indent.h" | 29 | #include "util/indent.h" |
584 | 32 | #include "util/stl_util.h" | 30 | #include "util/stl_util.h" |
585 | 31 | #include "zorbatypes/integer.h" | ||
586 | 33 | 32 | ||
587 | 34 | #ifndef NDEBUG | 33 | #ifndef NDEBUG |
588 | 35 | #include "system/properties.h" | 34 | #include "system/properties.h" |
589 | 36 | 35 | ||
590 | === modified file 'src/runtime/hof/dynamic_fncall_iterator.cpp' | |||
591 | --- src/runtime/hof/dynamic_fncall_iterator.cpp 2013-05-05 04:49:50 +0000 | |||
592 | +++ src/runtime/hof/dynamic_fncall_iterator.cpp 2013-05-08 15:05:31 +0000 | |||
593 | @@ -34,6 +34,7 @@ | |||
594 | 34 | #include "types/root_typemanager.h" | 34 | #include "types/root_typemanager.h" |
595 | 35 | #include "types/casting.h" | 35 | #include "types/casting.h" |
596 | 36 | #include "types/typeops.h" | 36 | #include "types/typeops.h" |
597 | 37 | #include "zorbatypes/integer.h" | ||
598 | 37 | 38 | ||
599 | 38 | #include "system/globalenv.h" | 39 | #include "system/globalenv.h" |
600 | 39 | 40 | ||
601 | 40 | 41 | ||
602 | === modified file 'src/runtime/hof/fn_hof_functions_impl.cpp' | |||
603 | --- src/runtime/hof/fn_hof_functions_impl.cpp 2013-04-24 01:35:58 +0000 | |||
604 | +++ src/runtime/hof/fn_hof_functions_impl.cpp 2013-05-08 15:05:31 +0000 | |||
605 | @@ -42,6 +42,7 @@ | |||
606 | 42 | #include "system/globalenv.h" | 42 | #include "system/globalenv.h" |
607 | 43 | 43 | ||
608 | 44 | #include "zorbamisc/ns_consts.h" | 44 | #include "zorbamisc/ns_consts.h" |
609 | 45 | #include "zorbatypes/integer.h" | ||
610 | 45 | 46 | ||
611 | 46 | 47 | ||
612 | 47 | #include "compiler/expression/expr_manager.h" | 48 | #include "compiler/expression/expr_manager.h" |
613 | 48 | 49 | ||
614 | === modified file 'src/runtime/indexing/index_ddl.cpp' | |||
615 | --- src/runtime/indexing/index_ddl.cpp 2013-03-24 20:40:03 +0000 | |||
616 | +++ src/runtime/indexing/index_ddl.cpp 2013-05-08 15:05:31 +0000 | |||
617 | @@ -34,6 +34,8 @@ | |||
618 | 34 | #include "types/typeimpl.h" | 34 | #include "types/typeimpl.h" |
619 | 35 | #include "types/typeops.h" | 35 | #include "types/typeops.h" |
620 | 36 | #include "types/casting.h" | 36 | #include "types/casting.h" |
621 | 37 | #include "zorbatypes/decimal.h" | ||
622 | 38 | #include "zorbatypes/integer.h" | ||
623 | 37 | 39 | ||
624 | 38 | #include "context/static_context.h" | 40 | #include "context/static_context.h" |
625 | 39 | #include "context/dynamic_context.h" | 41 | #include "context/dynamic_context.h" |
626 | @@ -623,7 +625,7 @@ | |||
627 | 623 | PlanState& planState) const | 625 | PlanState& planState) const |
628 | 624 | { | 626 | { |
629 | 625 | store::IndexCondition_t cond; | 627 | store::IndexCondition_t cond; |
631 | 626 | xs_integer skip = xs_integer::zero(); | 628 | xs_integer skip( numeric_consts<xs_integer>::zero() ); |
632 | 627 | 629 | ||
633 | 628 | try | 630 | try |
634 | 629 | { | 631 | { |
635 | @@ -641,8 +643,8 @@ | |||
636 | 641 | store::Item_t skipItem; | 643 | store::Item_t skipItem; |
637 | 642 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); | 644 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); |
638 | 643 | skip = skipItem->getIntegerValue(); | 645 | skip = skipItem->getIntegerValue(); |
641 | 644 | if (skip < xs_integer::zero()) | 646 | if (skip.sign() < 0) |
642 | 645 | skip = xs_integer::zero(); | 647 | skip = numeric_consts<xs_integer>::zero(); |
643 | 646 | } | 648 | } |
644 | 647 | 649 | ||
645 | 648 | state->theIterator->init(cond, skip); | 650 | state->theIterator->init(cond, skip); |
646 | @@ -687,8 +689,8 @@ | |||
647 | 687 | store::Item_t skipItem; | 689 | store::Item_t skipItem; |
648 | 688 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); | 690 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); |
649 | 689 | skip = skipItem->getIntegerValue(); | 691 | skip = skipItem->getIntegerValue(); |
652 | 690 | if (skip < xs_integer::zero()) | 692 | if (skip.sign() < 0) |
653 | 691 | skip = xs_integer::zero(); | 693 | skip = numeric_consts<xs_integer>::zero(); |
654 | 692 | } | 694 | } |
655 | 693 | 695 | ||
656 | 694 | state->theIterator->init(cond, skip); | 696 | state->theIterator->init(cond, skip); |
657 | @@ -1071,7 +1073,7 @@ | |||
658 | 1071 | PlanState& planState) const | 1073 | PlanState& planState) const |
659 | 1072 | { | 1074 | { |
660 | 1073 | store::IndexCondition_t cond; | 1075 | store::IndexCondition_t cond; |
662 | 1074 | xs_integer skip = xs_integer::zero(); | 1076 | xs_integer skip( numeric_consts<xs_integer>::zero() ); |
663 | 1075 | 1077 | ||
664 | 1076 | try | 1078 | try |
665 | 1077 | { | 1079 | { |
666 | @@ -1087,8 +1089,8 @@ | |||
667 | 1087 | store::Item_t skipItem; | 1089 | store::Item_t skipItem; |
668 | 1088 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); | 1090 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); |
669 | 1089 | skip = skipItem->getIntegerValue(); | 1091 | skip = skipItem->getIntegerValue(); |
672 | 1090 | if (skip < xs_integer::zero()) | 1092 | if (skip.sign() < 0) |
673 | 1091 | skip = xs_integer::zero(); | 1093 | skip = numeric_consts<xs_integer>::zero(); |
674 | 1092 | } | 1094 | } |
675 | 1093 | 1095 | ||
676 | 1094 | state->theIterator->init(cond, skip); | 1096 | state->theIterator->init(cond, skip); |
677 | @@ -1114,7 +1116,7 @@ | |||
678 | 1114 | PlanState& planState) const | 1116 | PlanState& planState) const |
679 | 1115 | { | 1117 | { |
680 | 1116 | store::IndexCondition_t cond; | 1118 | store::IndexCondition_t cond; |
682 | 1117 | xs_integer skip = xs_integer::zero(); | 1119 | xs_integer skip( numeric_consts<xs_integer>::zero() ); |
683 | 1118 | 1120 | ||
684 | 1119 | try | 1121 | try |
685 | 1120 | { | 1122 | { |
686 | @@ -1130,8 +1132,8 @@ | |||
687 | 1130 | store::Item_t skipItem; | 1132 | store::Item_t skipItem; |
688 | 1131 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); | 1133 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); |
689 | 1132 | skip = skipItem->getIntegerValue(); | 1134 | skip = skipItem->getIntegerValue(); |
692 | 1133 | if (skip < xs_integer::zero()) | 1135 | if (skip.sign() < 0) |
693 | 1134 | skip = xs_integer::zero(); | 1136 | skip = numeric_consts<xs_integer>::zero(); |
694 | 1135 | } | 1137 | } |
695 | 1136 | 1138 | ||
696 | 1137 | state->theIterator->init(cond, skip); | 1139 | state->theIterator->init(cond, skip); |
697 | 1138 | 1140 | ||
698 | === modified file 'src/runtime/introspection/sctx_impl.cpp' | |||
699 | --- src/runtime/introspection/sctx_impl.cpp 2013-02-07 17:24:36 +0000 | |||
700 | +++ src/runtime/introspection/sctx_impl.cpp 2013-05-08 15:05:31 +0000 | |||
701 | @@ -19,6 +19,7 @@ | |||
702 | 19 | 19 | ||
703 | 20 | #include "diagnostics/assert.h" | 20 | #include "diagnostics/assert.h" |
704 | 21 | #include "diagnostics/xquery_diagnostics.h" | 21 | #include "diagnostics/xquery_diagnostics.h" |
705 | 22 | #include "zorbatypes/integer.h" | ||
706 | 22 | #include "zorbatypes/numconversions.h" | 23 | #include "zorbatypes/numconversions.h" |
707 | 23 | 24 | ||
708 | 24 | #include "system/globalenv.h" | 25 | #include "system/globalenv.h" |
709 | 25 | 26 | ||
710 | === modified file 'src/runtime/item/item_impl.cpp' | |||
711 | --- src/runtime/item/item_impl.cpp 2012-07-17 18:47:54 +0000 | |||
712 | +++ src/runtime/item/item_impl.cpp 2013-05-08 15:05:31 +0000 | |||
713 | @@ -25,6 +25,7 @@ | |||
714 | 25 | #include "store/api/store.h" | 25 | #include "store/api/store.h" |
715 | 26 | 26 | ||
716 | 27 | #include "util/mem_sizeof.h" | 27 | #include "util/mem_sizeof.h" |
717 | 28 | #include "zorbatypes/integer.h" | ||
718 | 28 | 29 | ||
719 | 29 | using namespace std; | 30 | using namespace std; |
720 | 30 | 31 | ||
721 | 31 | 32 | ||
722 | === modified file 'src/runtime/json/jsoniq_functions_impl.cpp' | |||
723 | --- src/runtime/json/jsoniq_functions_impl.cpp 2013-05-05 04:49:50 +0000 | |||
724 | +++ src/runtime/json/jsoniq_functions_impl.cpp 2013-05-08 15:05:31 +0000 | |||
725 | @@ -46,6 +46,7 @@ | |||
726 | 46 | #include "types/typeimpl.h" | 46 | #include "types/typeimpl.h" |
727 | 47 | #include "types/typeops.h" | 47 | #include "types/typeops.h" |
728 | 48 | #include "types/root_typemanager.h" | 48 | #include "types/root_typemanager.h" |
729 | 49 | #include "zorbatypes/integer.h" | ||
730 | 49 | 50 | ||
731 | 50 | #include <runtime/util/doc_uri_heuristics.h> | 51 | #include <runtime/util/doc_uri_heuristics.h> |
732 | 51 | 52 | ||
733 | 52 | 53 | ||
734 | === modified file 'src/runtime/maths/pregenerated/maths.cpp' | |||
735 | --- src/runtime/maths/pregenerated/maths.cpp 2013-03-05 23:11:50 +0000 | |||
736 | +++ src/runtime/maths/pregenerated/maths.cpp 2013-05-08 15:05:31 +0000 | |||
737 | @@ -640,12 +640,12 @@ | |||
738 | 640 | 640 | ||
739 | 641 | void ModfIteratorState::init(PlanState& planState) { | 641 | void ModfIteratorState::init(PlanState& planState) { |
740 | 642 | PlanIteratorState::init(planState); | 642 | PlanIteratorState::init(planState); |
742 | 643 | theDoubInteger = xs_double::zero(); | 643 | theDoubInteger = numeric_consts<xs_double>::zero(); |
743 | 644 | } | 644 | } |
744 | 645 | 645 | ||
745 | 646 | void ModfIteratorState::reset(PlanState& planState) { | 646 | void ModfIteratorState::reset(PlanState& planState) { |
746 | 647 | PlanIteratorState::reset(planState); | 647 | PlanIteratorState::reset(planState); |
748 | 648 | theDoubInteger = xs_double::zero(); | 648 | theDoubInteger = numeric_consts<xs_double>::zero(); |
749 | 649 | } | 649 | } |
750 | 650 | // </ModfIterator> | 650 | // </ModfIterator> |
751 | 651 | 651 | ||
752 | @@ -678,12 +678,12 @@ | |||
753 | 678 | 678 | ||
754 | 679 | void FrexpIteratorState::init(PlanState& planState) { | 679 | void FrexpIteratorState::init(PlanState& planState) { |
755 | 680 | PlanIteratorState::init(planState); | 680 | PlanIteratorState::init(planState); |
757 | 681 | theIntExponent = xs_integer::zero(); | 681 | theIntExponent = numeric_consts<xs_integer>::zero(); |
758 | 682 | } | 682 | } |
759 | 683 | 683 | ||
760 | 684 | void FrexpIteratorState::reset(PlanState& planState) { | 684 | void FrexpIteratorState::reset(PlanState& planState) { |
761 | 685 | PlanIteratorState::reset(planState); | 685 | PlanIteratorState::reset(planState); |
763 | 686 | theIntExponent = xs_integer::zero(); | 686 | theIntExponent = numeric_consts<xs_integer>::zero(); |
764 | 687 | } | 687 | } |
765 | 688 | // </FrexpIterator> | 688 | // </FrexpIterator> |
766 | 689 | 689 | ||
767 | 690 | 690 | ||
768 | === modified file 'src/runtime/maths/pregenerated/maths.h' | |||
769 | --- src/runtime/maths/pregenerated/maths.h 2013-03-05 23:11:50 +0000 | |||
770 | +++ src/runtime/maths/pregenerated/maths.h 2013-05-08 15:05:31 +0000 | |||
771 | @@ -29,6 +29,7 @@ | |||
772 | 29 | #include "runtime/base/binarybase.h" | 29 | #include "runtime/base/binarybase.h" |
773 | 30 | #include "runtime/base/noarybase.h" | 30 | #include "runtime/base/noarybase.h" |
774 | 31 | 31 | ||
775 | 32 | #include "zorbatypes/integer.h" | ||
776 | 32 | #include "zorbatypes/schema_types.h" | 33 | #include "zorbatypes/schema_types.h" |
777 | 33 | 34 | ||
778 | 34 | 35 | ||
779 | 35 | 36 | ||
780 | === modified file 'src/runtime/numerics/NumericsImpl.cpp' | |||
781 | --- src/runtime/numerics/NumericsImpl.cpp 2013-02-07 17:24:36 +0000 | |||
782 | +++ src/runtime/numerics/NumericsImpl.cpp 2013-05-08 15:05:31 +0000 | |||
783 | @@ -20,6 +20,8 @@ | |||
784 | 20 | #include "diagnostics/assert.h" | 20 | #include "diagnostics/assert.h" |
785 | 21 | #include "diagnostics/util_macros.h" | 21 | #include "diagnostics/util_macros.h" |
786 | 22 | #include "diagnostics/xquery_diagnostics.h" | 22 | #include "diagnostics/xquery_diagnostics.h" |
787 | 23 | #include "zorbatypes/decimal.h" | ||
788 | 24 | #include "zorbatypes/integer.h" | ||
789 | 23 | #include "zorbatypes/zorbatypes_decl.h" | 25 | #include "zorbatypes/zorbatypes_decl.h" |
790 | 24 | 26 | ||
791 | 25 | #include "system/globalenv.h" | 27 | #include "system/globalenv.h" |
792 | @@ -393,7 +395,7 @@ | |||
793 | 393 | { | 395 | { |
794 | 394 | xs_decimal ld0 = i0->getDecimalValue(); | 396 | xs_decimal ld0 = i0->getDecimalValue(); |
795 | 395 | xs_decimal ld1 = i1->getDecimalValue(); | 397 | xs_decimal ld1 = i1->getDecimalValue(); |
797 | 396 | if ( ld1 == Integer::zero() ) | 398 | if ( ld1.sign() == 0 ) |
798 | 397 | { | 399 | { |
799 | 398 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); | 400 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); |
800 | 399 | } | 401 | } |
801 | @@ -412,7 +414,7 @@ | |||
802 | 412 | { | 414 | { |
803 | 413 | xs_decimal const ll0(i0->getIntegerValue()); | 415 | xs_decimal const ll0(i0->getIntegerValue()); |
804 | 414 | xs_decimal const ll1(i1->getIntegerValue()); | 416 | xs_decimal const ll1(i1->getIntegerValue()); |
806 | 415 | if ( ll1 == Integer::zero() ) | 417 | if ( ll1.sign() == 0 ) |
807 | 416 | { | 418 | { |
808 | 417 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); | 419 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); |
809 | 418 | } | 420 | } |
810 | @@ -435,7 +437,7 @@ | |||
811 | 435 | xs_double d0 = i0->getDoubleValue(); | 437 | xs_double d0 = i0->getDoubleValue(); |
812 | 436 | xs_double d1 = i1->getDoubleValue(); | 438 | xs_double d1 = i1->getDoubleValue(); |
813 | 437 | 439 | ||
815 | 438 | if ( d1 == xs_double::zero() ) | 440 | if ( d1 == numeric_consts<xs_double>::zero() ) |
816 | 439 | { | 441 | { |
817 | 440 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); | 442 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); |
818 | 441 | } | 443 | } |
819 | @@ -455,7 +457,7 @@ | |||
820 | 455 | 457 | ||
821 | 456 | if (i0->isPosOrNegInf()) { | 458 | if (i0->isPosOrNegInf()) { |
822 | 457 | // idiv with +-INF divisor has 0 as result | 459 | // idiv with +-INF divisor has 0 as result |
824 | 458 | return GENV_ITEMFACTORY->createInteger(result, Integer::zero()); | 460 | return GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
825 | 459 | } | 461 | } |
826 | 460 | 462 | ||
827 | 461 | xs_integer const lInteger( d0 / d1 ); | 463 | xs_integer const lInteger( d0 / d1 ); |
828 | @@ -474,7 +476,7 @@ | |||
829 | 474 | { | 476 | { |
830 | 475 | xs_float f0 = i0->getFloatValue(); | 477 | xs_float f0 = i0->getFloatValue(); |
831 | 476 | xs_float f1 = i1->getFloatValue(); | 478 | xs_float f1 = i1->getFloatValue(); |
833 | 477 | if ( f1 == xs_float::zero() ) | 479 | if ( f1 == numeric_consts<xs_float>::zero() ) |
834 | 478 | { | 480 | { |
835 | 479 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); | 481 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); |
836 | 480 | } | 482 | } |
837 | @@ -494,7 +496,7 @@ | |||
838 | 494 | if (i0->isPosOrNegInf()) | 496 | if (i0->isPosOrNegInf()) |
839 | 495 | { | 497 | { |
840 | 496 | // idiv with +-INF divisor has 0 as result | 498 | // idiv with +-INF divisor has 0 as result |
842 | 497 | return GENV_ITEMFACTORY->createInteger(result, Integer::zero()); | 499 | return GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
843 | 498 | } | 500 | } |
844 | 499 | 501 | ||
845 | 500 | xs_integer const lInteger( f0 / f1 ); | 502 | xs_integer const lInteger( f0 / f1 ); |
846 | @@ -606,7 +608,7 @@ | |||
847 | 606 | xs_integer ll0 = i0->getIntegerValue(); | 608 | xs_integer ll0 = i0->getIntegerValue(); |
848 | 607 | xs_integer ll1 = i1->getIntegerValue(); | 609 | xs_integer ll1 = i1->getIntegerValue(); |
849 | 608 | 610 | ||
851 | 609 | if (ll1 == Integer::zero()) | 611 | if ( ll1.sign() == 0 ) |
852 | 610 | { | 612 | { |
853 | 611 | throw XQUERY_EXCEPTION(err::FOAR0001, ERROR_LOC(loc)); | 613 | throw XQUERY_EXCEPTION(err::FOAR0001, ERROR_LOC(loc)); |
854 | 612 | } | 614 | } |
855 | 613 | 615 | ||
856 | === modified file 'src/runtime/numerics/format_integer.cpp' | |||
857 | --- src/runtime/numerics/format_integer.cpp 2013-05-04 20:27:31 +0000 | |||
858 | +++ src/runtime/numerics/format_integer.cpp 2013-05-08 15:05:31 +0000 | |||
859 | @@ -34,6 +34,7 @@ | |||
860 | 34 | #include "util/stream_util.h" | 34 | #include "util/stream_util.h" |
861 | 35 | #include "util/unicode_util.h" | 35 | #include "util/unicode_util.h" |
862 | 36 | #include "util/utf8_string.h" | 36 | #include "util/utf8_string.h" |
863 | 37 | #include "zorbatypes/integer.h" | ||
864 | 37 | #include "zorbatypes/numconversions.h" | 38 | #include "zorbatypes/numconversions.h" |
865 | 38 | 39 | ||
866 | 39 | using namespace std; | 40 | using namespace std; |
867 | 40 | 41 | ||
868 | === modified file 'src/runtime/numerics/format_number.cpp' | |||
869 | --- src/runtime/numerics/format_number.cpp 2013-05-03 23:19:41 +0000 | |||
870 | +++ src/runtime/numerics/format_number.cpp 2013-05-08 15:05:31 +0000 | |||
871 | @@ -31,7 +31,8 @@ | |||
872 | 31 | #include "types/typeconstants.h" | 31 | #include "types/typeconstants.h" |
873 | 32 | #include "types/typeops.h" | 32 | #include "types/typeops.h" |
874 | 33 | #include "util/xml_util.h" | 33 | #include "util/xml_util.h" |
876 | 34 | #include "zorbatypes/zorbatypes_decl.h" | 34 | #include "zorbatypes/floatimpl.h" |
877 | 35 | #include "zorbatypes/integer.h" | ||
878 | 35 | 36 | ||
879 | 36 | namespace zorba { | 37 | namespace zorba { |
880 | 37 | 38 | ||
881 | @@ -258,7 +259,7 @@ | |||
882 | 258 | ); | 259 | ); |
883 | 259 | 260 | ||
884 | 260 | store::Item_t zero; | 261 | store::Item_t zero; |
886 | 261 | GENV_ITEMFACTORY->createDouble( zero, xs_double::zero() ); | 262 | GENV_ITEMFACTORY->createDouble( zero, numeric_consts<xs_double>::zero() ); |
887 | 262 | 263 | ||
888 | 263 | // | 264 | // |
889 | 264 | // Ibid: [T]he positive sub-picture and its associated variables are used if | 265 | // Ibid: [T]he positive sub-picture and its associated variables are used if |
890 | 265 | 266 | ||
891 | === modified file 'src/runtime/numerics/numerics_impl.cpp' | |||
892 | --- src/runtime/numerics/numerics_impl.cpp 2013-04-11 17:37:16 +0000 | |||
893 | +++ src/runtime/numerics/numerics_impl.cpp 2013-05-08 15:05:31 +0000 | |||
894 | @@ -22,6 +22,8 @@ | |||
895 | 22 | #include "diagnostics/assert.h" | 22 | #include "diagnostics/assert.h" |
896 | 23 | #include "diagnostics/util_macros.h" | 23 | #include "diagnostics/util_macros.h" |
897 | 24 | #include "diagnostics/xquery_diagnostics.h" | 24 | #include "diagnostics/xquery_diagnostics.h" |
898 | 25 | #include "zorbatypes/decimal.h" | ||
899 | 26 | #include "zorbatypes/integer.h" | ||
900 | 25 | #include "zorbatypes/zorbatypes_decl.h" | 27 | #include "zorbatypes/zorbatypes_decl.h" |
901 | 26 | 28 | ||
902 | 27 | #include "system/globalenv.h" | 29 | #include "system/globalenv.h" |
903 | @@ -97,7 +99,7 @@ | |||
904 | 97 | } | 99 | } |
905 | 98 | else if (TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE)) | 100 | else if (TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE)) |
906 | 99 | { | 101 | { |
908 | 100 | if (result->getIntegerValue() >= xs_decimal::zero()) | 102 | if (result->getIntegerValue().sign() >= 0) |
909 | 101 | { | 103 | { |
910 | 102 | if ( !TypeOps::is_equal(tm, *type, *rtm.INTEGER_TYPE_ONE)) | 104 | if ( !TypeOps::is_equal(tm, *type, *rtm.INTEGER_TYPE_ONE)) |
911 | 103 | GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue()); | 105 | GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue()); |
912 | @@ -109,7 +111,7 @@ | |||
913 | 109 | } | 111 | } |
914 | 110 | else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE)) | 112 | else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE)) |
915 | 111 | { | 113 | { |
917 | 112 | if ( result->getDecimalValue() >= xs_decimal::zero()) | 114 | if ( result->getDecimalValue().sign() >= 0) |
918 | 113 | { | 115 | { |
919 | 114 | if ( !TypeOps::is_equal(tm, *type, *rtm.DECIMAL_TYPE_ONE)) | 116 | if ( !TypeOps::is_equal(tm, *type, *rtm.DECIMAL_TYPE_ONE)) |
920 | 115 | GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue()); | 117 | GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue()); |
921 | @@ -301,7 +303,7 @@ | |||
922 | 301 | //item type is subtype of INTEGER | 303 | //item type is subtype of INTEGER |
923 | 302 | else if(TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE)) | 304 | else if(TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE)) |
924 | 303 | { | 305 | { |
926 | 304 | if(precision_integer < Integer::zero()) | 306 | if(precision_integer.sign() < 0) |
927 | 305 | GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue().round(precision_integer)); | 307 | GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue().round(precision_integer)); |
928 | 306 | } | 308 | } |
929 | 307 | 309 | ||
930 | 308 | 310 | ||
931 | === modified file 'src/runtime/random/pregenerated/random.h' | |||
932 | --- src/runtime/random/pregenerated/random.h 2013-03-05 23:11:50 +0000 | |||
933 | +++ src/runtime/random/pregenerated/random.h 2013-05-08 15:05:31 +0000 | |||
934 | @@ -29,6 +29,7 @@ | |||
935 | 29 | 29 | ||
936 | 30 | 30 | ||
937 | 31 | #include "runtime/base/narybase.h" | 31 | #include "runtime/base/narybase.h" |
938 | 32 | #include "zorbatypes/integer.h" | ||
939 | 32 | 33 | ||
940 | 33 | 34 | ||
941 | 34 | namespace zorba { | 35 | namespace zorba { |
942 | 35 | 36 | ||
943 | === modified file 'src/runtime/sequences/pregenerated/sequences.cpp' | |||
944 | --- src/runtime/sequences/pregenerated/sequences.cpp 2013-04-15 20:57:28 +0000 | |||
945 | +++ src/runtime/sequences/pregenerated/sequences.cpp 2013-05-08 15:05:31 +0000 | |||
946 | @@ -238,15 +238,15 @@ | |||
947 | 238 | 238 | ||
948 | 239 | void FnInsertBeforeIteratorState::init(PlanState& planState) { | 239 | void FnInsertBeforeIteratorState::init(PlanState& planState) { |
949 | 240 | PlanIteratorState::init(planState); | 240 | PlanIteratorState::init(planState); |
952 | 241 | theCurrentPos = xs_integer::zero(); | 241 | theCurrentPos = numeric_consts<xs_integer>::zero(); |
953 | 242 | thePosition = xs_integer::zero(); | 242 | thePosition = numeric_consts<xs_integer>::zero(); |
954 | 243 | theTargetItem = NULL; | 243 | theTargetItem = NULL; |
955 | 244 | } | 244 | } |
956 | 245 | 245 | ||
957 | 246 | void FnInsertBeforeIteratorState::reset(PlanState& planState) { | 246 | void FnInsertBeforeIteratorState::reset(PlanState& planState) { |
958 | 247 | PlanIteratorState::reset(planState); | 247 | PlanIteratorState::reset(planState); |
961 | 248 | theCurrentPos = xs_integer::zero(); | 248 | theCurrentPos = numeric_consts<xs_integer>::zero(); |
962 | 249 | thePosition = xs_integer::zero(); | 249 | thePosition = numeric_consts<xs_integer>::zero(); |
963 | 250 | theTargetItem = NULL; | 250 | theTargetItem = NULL; |
964 | 251 | } | 251 | } |
965 | 252 | // </FnInsertBeforeIterator> | 252 | // </FnInsertBeforeIterator> |
966 | @@ -284,15 +284,15 @@ | |||
967 | 284 | 284 | ||
968 | 285 | void FnRemoveIteratorState::init(PlanState& planState) { | 285 | void FnRemoveIteratorState::init(PlanState& planState) { |
969 | 286 | PlanIteratorState::init(planState); | 286 | PlanIteratorState::init(planState); |
972 | 287 | theCurrentPos = xs_integer::zero(); | 287 | theCurrentPos = numeric_consts<xs_integer>::zero(); |
973 | 288 | thePosition = xs_integer::zero(); | 288 | thePosition = numeric_consts<xs_integer>::zero(); |
974 | 289 | theCollator = 0; | 289 | theCollator = 0; |
975 | 290 | } | 290 | } |
976 | 291 | 291 | ||
977 | 292 | void FnRemoveIteratorState::reset(PlanState& planState) { | 292 | void FnRemoveIteratorState::reset(PlanState& planState) { |
978 | 293 | PlanIteratorState::reset(planState); | 293 | PlanIteratorState::reset(planState); |
981 | 294 | theCurrentPos = xs_integer::zero(); | 294 | theCurrentPos = numeric_consts<xs_integer>::zero(); |
982 | 295 | thePosition = xs_integer::zero(); | 295 | thePosition = numeric_consts<xs_integer>::zero(); |
983 | 296 | theCollator = 0; | 296 | theCollator = 0; |
984 | 297 | } | 297 | } |
985 | 298 | // </FnRemoveIterator> | 298 | // </FnRemoveIterator> |
986 | @@ -863,16 +863,16 @@ | |||
987 | 863 | 863 | ||
988 | 864 | void OpToIteratorState::init(PlanState& planState) { | 864 | void OpToIteratorState::init(PlanState& planState) { |
989 | 865 | PlanIteratorState::init(planState); | 865 | PlanIteratorState::init(planState); |
993 | 866 | theCurInt = xs_integer::zero(); | 866 | theCurInt = numeric_consts<xs_integer>::zero(); |
994 | 867 | theFirstVal = xs_integer::zero(); | 867 | theFirstVal = numeric_consts<xs_integer>::zero(); |
995 | 868 | theLastVal = xs_integer::zero(); | 868 | theLastVal = numeric_consts<xs_integer>::zero(); |
996 | 869 | } | 869 | } |
997 | 870 | 870 | ||
998 | 871 | void OpToIteratorState::reset(PlanState& planState) { | 871 | void OpToIteratorState::reset(PlanState& planState) { |
999 | 872 | PlanIteratorState::reset(planState); | 872 | PlanIteratorState::reset(planState); |
1003 | 873 | theCurInt = xs_integer::zero(); | 873 | theCurInt = numeric_consts<xs_integer>::zero(); |
1004 | 874 | theFirstVal = xs_integer::zero(); | 874 | theFirstVal = numeric_consts<xs_integer>::zero(); |
1005 | 875 | theLastVal = xs_integer::zero(); | 875 | theLastVal = numeric_consts<xs_integer>::zero(); |
1006 | 876 | } | 876 | } |
1007 | 877 | // </OpToIterator> | 877 | // </OpToIterator> |
1008 | 878 | 878 | ||
1009 | 879 | 879 | ||
1010 | === modified file 'src/runtime/sequences/pregenerated/sequences.h' | |||
1011 | --- src/runtime/sequences/pregenerated/sequences.h 2013-04-15 20:57:28 +0000 | |||
1012 | +++ src/runtime/sequences/pregenerated/sequences.h 2013-05-08 15:05:31 +0000 | |||
1013 | @@ -31,6 +31,7 @@ | |||
1014 | 31 | #include "runtime/base/narybase.h" | 31 | #include "runtime/base/narybase.h" |
1015 | 32 | #include "runtime/base/narybase.h" | 32 | #include "runtime/base/narybase.h" |
1016 | 33 | #include "runtime/core/path_iterators.h" | 33 | #include "runtime/core/path_iterators.h" |
1017 | 34 | #include "zorbatypes/integer.h" | ||
1018 | 34 | 35 | ||
1019 | 35 | 36 | ||
1020 | 36 | namespace zorba { | 37 | namespace zorba { |
1021 | 37 | 38 | ||
1022 | === modified file 'src/runtime/sequences/sequences_impl.cpp' | |||
1023 | --- src/runtime/sequences/sequences_impl.cpp 2013-05-01 23:06:33 +0000 | |||
1024 | +++ src/runtime/sequences/sequences_impl.cpp 2013-05-08 15:05:31 +0000 | |||
1025 | @@ -20,12 +20,13 @@ | |||
1026 | 20 | #include <vector> | 20 | #include <vector> |
1027 | 21 | #include <sstream> | 21 | #include <sstream> |
1028 | 22 | 22 | ||
1029 | 23 | #include <zorbautils/fatal.h> | ||
1030 | 24 | #include "diagnostics/xquery_diagnostics.h" | 23 | #include "diagnostics/xquery_diagnostics.h" |
1031 | 25 | #include "diagnostics/util_macros.h" | 24 | #include "diagnostics/util_macros.h" |
1032 | 26 | 25 | ||
1035 | 27 | #include <zorbatypes/URI.h> | 26 | #include "zorbatypes/decimal.h" |
1036 | 28 | #include <zorbamisc/ns_consts.h> | 27 | #include "zorbatypes/URI.h" |
1037 | 28 | #include "zorbamisc/ns_consts.h" | ||
1038 | 29 | #include "zorbautils/fatal.h" | ||
1039 | 29 | 30 | ||
1040 | 30 | // For timing | 31 | // For timing |
1041 | 31 | #include <zorba/util/time.h> | 32 | #include <zorba/util/time.h> |
1042 | @@ -1599,7 +1600,10 @@ | |||
1043 | 1599 | else | 1600 | else |
1044 | 1600 | { | 1601 | { |
1045 | 1601 | STACK_PUSH( | 1602 | STACK_PUSH( |
1047 | 1602 | GENV_ITEMFACTORY->createInteger( result, Integer::zero() ), state | 1603 | GENV_ITEMFACTORY->createInteger( |
1048 | 1604 | result, numeric_consts<xs_integer>::zero() | ||
1049 | 1605 | ), | ||
1050 | 1606 | state | ||
1051 | 1603 | ); | 1607 | ); |
1052 | 1604 | } | 1608 | } |
1053 | 1605 | } | 1609 | } |
1054 | @@ -1648,7 +1652,7 @@ | |||
1055 | 1648 | } | 1652 | } |
1056 | 1649 | else | 1653 | else |
1057 | 1650 | { | 1654 | { |
1059 | 1651 | GENV_ITEMFACTORY->createInteger(result, Integer::zero()); | 1655 | GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
1060 | 1652 | STACK_PUSH(true, state); | 1656 | STACK_PUSH(true, state); |
1061 | 1653 | } | 1657 | } |
1062 | 1654 | 1658 | ||
1063 | @@ -1697,7 +1701,7 @@ | |||
1064 | 1697 | } | 1701 | } |
1065 | 1698 | else | 1702 | else |
1066 | 1699 | { | 1703 | { |
1068 | 1700 | GENV_ITEMFACTORY->createInteger(result, Integer::zero()); | 1704 | GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
1069 | 1701 | STACK_PUSH(true, state); | 1705 | STACK_PUSH(true, state); |
1070 | 1702 | } | 1706 | } |
1071 | 1703 | 1707 | ||
1072 | @@ -1745,7 +1749,7 @@ | |||
1073 | 1745 | } | 1749 | } |
1074 | 1746 | else | 1750 | else |
1075 | 1747 | { | 1751 | { |
1077 | 1748 | GENV_ITEMFACTORY->createInteger(result, Integer::zero()); | 1752 | GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
1078 | 1749 | STACK_PUSH(true, state); | 1753 | STACK_PUSH(true, state); |
1079 | 1750 | } | 1754 | } |
1080 | 1751 | 1755 | ||
1081 | @@ -1803,7 +1807,7 @@ | |||
1082 | 1803 | } | 1807 | } |
1083 | 1804 | else | 1808 | else |
1084 | 1805 | { | 1809 | { |
1086 | 1806 | GENV_ITEMFACTORY->createInteger(result, Integer::zero()); | 1810 | GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
1087 | 1807 | STACK_PUSH(true, state); | 1811 | STACK_PUSH(true, state); |
1088 | 1808 | } | 1812 | } |
1089 | 1809 | 1813 | ||
1090 | 1810 | 1814 | ||
1091 | === modified file 'src/runtime/spec/maths/maths.xml' | |||
1092 | --- src/runtime/spec/maths/maths.xml 2013-02-07 17:24:36 +0000 | |||
1093 | +++ src/runtime/spec/maths/maths.xml 2013-05-08 15:05:31 +0000 | |||
1094 | @@ -6,6 +6,7 @@ | |||
1095 | 6 | xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd"> | 6 | xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd"> |
1096 | 7 | 7 | ||
1097 | 8 | <zorba:header> | 8 | <zorba:header> |
1098 | 9 | <zorba:include form="Quoted">zorbatypes/integer.h</zorba:include> | ||
1099 | 9 | <zorba:include form="Quoted">zorbatypes/schema_types.h</zorba:include> | 10 | <zorba:include form="Quoted">zorbatypes/schema_types.h</zorba:include> |
1100 | 10 | </zorba:header> | 11 | </zorba:header> |
1101 | 11 | 12 | ||
1102 | @@ -462,7 +463,7 @@ | |||
1103 | 462 | </zorba:function> | 463 | </zorba:function> |
1104 | 463 | 464 | ||
1105 | 464 | <zorba:state generateInit="true" generateReset="true"> | 465 | <zorba:state generateInit="true" generateReset="true"> |
1107 | 465 | <zorba:member type="xs_double" name="theDoubInteger" defaultValue="xs_double::zero()" | 466 | <zorba:member type="xs_double" name="theDoubInteger" defaultValue="numeric_consts<xs_double>::zero()" |
1108 | 466 | brief=""/> | 467 | brief=""/> |
1109 | 467 | </zorba:state> | 468 | </zorba:state> |
1110 | 468 | 469 | ||
1111 | @@ -485,7 +486,7 @@ | |||
1112 | 485 | </zorba:function> | 486 | </zorba:function> |
1113 | 486 | 487 | ||
1114 | 487 | <zorba:state generateInit="true" generateReset="true"> | 488 | <zorba:state generateInit="true" generateReset="true"> |
1116 | 488 | <zorba:member type="xs_integer" name="theIntExponent" defaultValue="xs_integer::zero()" | 489 | <zorba:member type="xs_integer" name="theIntExponent" defaultValue="numeric_consts<xs_integer>::zero()" |
1117 | 489 | brief=""/> | 490 | brief=""/> |
1118 | 490 | </zorba:state> | 491 | </zorba:state> |
1119 | 491 | 492 | ||
1120 | 492 | 493 | ||
1121 | === modified file 'src/runtime/spec/random/random.xml' | |||
1122 | --- src/runtime/spec/random/random.xml 2013-02-07 17:24:36 +0000 | |||
1123 | +++ src/runtime/spec/random/random.xml 2013-05-08 15:05:31 +0000 | |||
1124 | @@ -12,6 +12,10 @@ | |||
1125 | 12 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | 12 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
1126 | 13 | xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd"> | 13 | xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd"> |
1127 | 14 | 14 | ||
1128 | 15 | <zorba:header> | ||
1129 | 16 | <zorba:include form="Quoted">zorbatypes/integer.h</zorba:include> | ||
1130 | 17 | </zorba:header> | ||
1131 | 18 | |||
1132 | 15 | <!-- | 19 | <!-- |
1133 | 16 | /******************************************************************************* | 20 | /******************************************************************************* |
1134 | 17 | ********************************************************************************/ | 21 | ********************************************************************************/ |
1135 | 18 | 22 | ||
1136 | === modified file 'src/runtime/spec/sequences/sequences.xml' | |||
1137 | --- src/runtime/spec/sequences/sequences.xml 2013-04-15 20:57:28 +0000 | |||
1138 | +++ src/runtime/spec/sequences/sequences.xml 2013-05-08 15:05:31 +0000 | |||
1139 | @@ -15,6 +15,7 @@ | |||
1140 | 15 | <zorba:header> | 15 | <zorba:header> |
1141 | 16 | <zorba:include form="Quoted">runtime/base/narybase.h</zorba:include> | 16 | <zorba:include form="Quoted">runtime/base/narybase.h</zorba:include> |
1142 | 17 | <zorba:include form="Quoted">runtime/core/path_iterators.h</zorba:include> | 17 | <zorba:include form="Quoted">runtime/core/path_iterators.h</zorba:include> |
1143 | 18 | <zorba:include form="Quoted">zorbatypes/integer.h</zorba:include> | ||
1144 | 18 | <zorba:fwd-decl ns="zorba">NodeHandleHashSet</zorba:fwd-decl> | 19 | <zorba:fwd-decl ns="zorba">NodeHandleHashSet</zorba:fwd-decl> |
1145 | 19 | <zorba:fwd-decl ns="zorba">AtomicItemHandleHashSet</zorba:fwd-decl> | 20 | <zorba:fwd-decl ns="zorba">AtomicItemHandleHashSet</zorba:fwd-decl> |
1146 | 20 | </zorba:header> | 21 | </zorba:header> |
1147 | @@ -283,10 +284,10 @@ | |||
1148 | 283 | 284 | ||
1149 | 284 | <zorba:state> | 285 | <zorba:state> |
1150 | 285 | <zorba:member type="xs_integer" name="theCurrentPos" | 286 | <zorba:member type="xs_integer" name="theCurrentPos" |
1152 | 286 | defaultValue="xs_integer::zero()" brief="the current position in the sequence"/> | 287 | defaultValue="numeric_consts<xs_integer>::zero()" brief="the current position in the sequence"/> |
1153 | 287 | 288 | ||
1154 | 288 | <zorba:member type="xs_integer" name="thePosition" | 289 | <zorba:member type="xs_integer" name="thePosition" |
1156 | 289 | defaultValue="xs_integer::zero()" brief=""/> | 290 | defaultValue="numeric_consts<xs_integer>::zero()" brief=""/> |
1157 | 290 | 291 | ||
1158 | 291 | <zorba:member type="store::Item_t" name="theTargetItem" | 292 | <zorba:member type="store::Item_t" name="theTargetItem" |
1159 | 292 | defaultValue="NULL" brief=""/> | 293 | defaultValue="NULL" brief=""/> |
1160 | @@ -328,10 +329,10 @@ | |||
1161 | 328 | 329 | ||
1162 | 329 | <zorba:state> | 330 | <zorba:state> |
1163 | 330 | <zorba:member type="xs_integer" name="theCurrentPos" | 331 | <zorba:member type="xs_integer" name="theCurrentPos" |
1165 | 331 | defaultValue="xs_integer::zero()" brief="the current position in the sequence"/> | 332 | defaultValue="numeric_consts<xs_integer>::zero()" brief="the current position in the sequence"/> |
1166 | 332 | 333 | ||
1167 | 333 | <zorba:member type="xs_integer" name="thePosition" | 334 | <zorba:member type="xs_integer" name="thePosition" |
1169 | 334 | defaultValue="xs_integer::zero()" brief="the position to delete"/> | 335 | defaultValue="numeric_consts<xs_integer>::zero()" brief="the position to delete"/> |
1170 | 335 | 336 | ||
1171 | 336 | <zorba:member type="XQPCollator*" name="theCollator" | 337 | <zorba:member type="XQPCollator*" name="theCollator" |
1172 | 337 | defaultValue="0" brief="the collator"/> | 338 | defaultValue="0" brief="the collator"/> |
1173 | @@ -952,12 +953,12 @@ | |||
1174 | 952 | 953 | ||
1175 | 953 | <zorba:state> | 954 | <zorba:state> |
1176 | 954 | <zorba:member type="xs_integer" name="theCurInt" | 955 | <zorba:member type="xs_integer" name="theCurInt" |
1178 | 955 | defaultValue="xs_integer::zero()" brief="the current integer"/> | 956 | defaultValue="numeric_consts<xs_integer>::zero()" brief="the current integer"/> |
1179 | 956 | 957 | ||
1180 | 957 | <zorba:member type="xs_integer" name="theFirstVal" | 958 | <zorba:member type="xs_integer" name="theFirstVal" |
1182 | 958 | defaultValue="xs_integer::zero()" brief="first integer"/> | 959 | defaultValue="numeric_consts<xs_integer>::zero()" brief="first integer"/> |
1183 | 959 | 960 | ||
1185 | 960 | <zorba:member type="xs_integer" name="theLastVal" defaultValue="xs_integer::zero()" | 961 | <zorba:member type="xs_integer" name="theLastVal" defaultValue="numeric_consts<xs_integer>::zero()" |
1186 | 961 | brief="last integer"/> | 962 | brief="last integer"/> |
1187 | 962 | </zorba:state> | 963 | </zorba:state> |
1188 | 963 | 964 | ||
1189 | 964 | 965 | ||
1190 | === modified file 'src/runtime/store/maps_impl.cpp' | |||
1191 | --- src/runtime/store/maps_impl.cpp 2013-03-05 12:34:19 +0000 | |||
1192 | +++ src/runtime/store/maps_impl.cpp 2013-05-08 15:05:31 +0000 | |||
1193 | @@ -19,6 +19,7 @@ | |||
1194 | 19 | #include "diagnostics/util_macros.h" | 19 | #include "diagnostics/util_macros.h" |
1195 | 20 | #include "diagnostics/xquery_diagnostics.h" | 20 | #include "diagnostics/xquery_diagnostics.h" |
1196 | 21 | 21 | ||
1197 | 22 | #include "zorbatypes/integer.h" | ||
1198 | 22 | #include "zorbatypes/URI.h" | 23 | #include "zorbatypes/URI.h" |
1199 | 23 | 24 | ||
1200 | 24 | #include "system/globalenv.h" | 25 | #include "system/globalenv.h" |
1201 | 25 | 26 | ||
1202 | === modified file 'src/runtime/strings/strings_impl.cpp' | |||
1203 | --- src/runtime/strings/strings_impl.cpp 2013-05-04 20:20:05 +0000 | |||
1204 | +++ src/runtime/strings/strings_impl.cpp 2013-05-08 15:05:31 +0000 | |||
1205 | @@ -25,6 +25,7 @@ | |||
1206 | 25 | #include "diagnostics/xquery_diagnostics.h" | 25 | #include "diagnostics/xquery_diagnostics.h" |
1207 | 26 | #include "diagnostics/util_macros.h" | 26 | #include "diagnostics/util_macros.h" |
1208 | 27 | 27 | ||
1209 | 28 | #include "zorbatypes/integer.h" | ||
1210 | 28 | #include "zorbatypes/numconversions.h" | 29 | #include "zorbatypes/numconversions.h" |
1211 | 29 | 30 | ||
1212 | 30 | #include "system/globalenv.h" | 31 | #include "system/globalenv.h" |
1213 | @@ -734,8 +735,12 @@ | |||
1214 | 734 | } | 735 | } |
1215 | 735 | else | 736 | else |
1216 | 736 | { | 737 | { |
1219 | 737 | STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, xs_integer::zero()), | 738 | STACK_PUSH( |
1220 | 738 | state); | 739 | GENV_ITEMFACTORY->createInteger( |
1221 | 740 | result, numeric_consts<xs_integer>::zero() | ||
1222 | 741 | ), | ||
1223 | 742 | state | ||
1224 | 743 | ); | ||
1225 | 739 | } | 744 | } |
1226 | 740 | STACK_END(state); | 745 | STACK_END(state); |
1227 | 741 | } | 746 | } |
1228 | 742 | 747 | ||
1229 | === modified file 'src/store/api/collection.h' | |||
1230 | --- src/store/api/collection.h 2013-02-07 17:24:36 +0000 | |||
1231 | +++ src/store/api/collection.h 2013-05-08 15:05:31 +0000 | |||
1232 | @@ -59,7 +59,7 @@ | |||
1233 | 59 | * @return Iterator | 59 | * @return Iterator |
1234 | 60 | */ | 60 | */ |
1235 | 61 | virtual Iterator_t getIterator( | 61 | virtual Iterator_t getIterator( |
1237 | 62 | const xs_integer& aSkip = xs_integer::zero(), | 62 | const xs_integer& aSkip = numeric_consts<xs_integer>::zero(), |
1238 | 63 | const zstring& aStart = "") = 0; | 63 | const zstring& aStart = "") = 0; |
1239 | 64 | 64 | ||
1240 | 65 | /** | 65 | /** |
1241 | 66 | 66 | ||
1242 | === modified file 'src/store/api/iterator.h' | |||
1243 | --- src/store/api/iterator.h 2013-03-05 00:45:43 +0000 | |||
1244 | +++ src/store/api/iterator.h 2013-05-08 15:05:31 +0000 | |||
1245 | @@ -177,7 +177,7 @@ | |||
1246 | 177 | virtual ~IndexProbeIterator() { } | 177 | virtual ~IndexProbeIterator() { } |
1247 | 178 | 178 | ||
1248 | 179 | virtual void init(const IndexCondition_t& cond, | 179 | virtual void init(const IndexCondition_t& cond, |
1250 | 180 | const xs_integer& aSkip = xs_integer::zero()) = 0; | 180 | const xs_integer& aSkip = numeric_consts<xs_integer>::zero()) = 0; |
1251 | 181 | 181 | ||
1252 | 182 | virtual void open() = 0; | 182 | virtual void open() = 0; |
1253 | 183 | 183 | ||
1254 | 184 | 184 | ||
1255 | === modified file 'src/store/naive/atomic_items.cpp' | |||
1256 | --- src/store/naive/atomic_items.cpp 2013-04-16 21:12:12 +0000 | |||
1257 | +++ src/store/naive/atomic_items.cpp 2013-05-08 15:05:31 +0000 | |||
1258 | @@ -2691,7 +2691,7 @@ | |||
1259 | 2691 | 2691 | ||
1260 | 2692 | bool DecimalItem::getEBV() const | 2692 | bool DecimalItem::getEBV() const |
1261 | 2693 | { | 2693 | { |
1263 | 2694 | return ( theValue != xs_decimal::zero() ); | 2694 | return !!theValue.sign(); |
1264 | 2695 | } | 2695 | } |
1265 | 2696 | 2696 | ||
1266 | 2697 | 2697 | ||
1267 | 2698 | 2698 | ||
1268 | === modified file 'src/store/naive/atomic_items.h' | |||
1269 | --- src/store/naive/atomic_items.h 2013-04-08 08:45:18 +0000 | |||
1270 | +++ src/store/naive/atomic_items.h 2013-05-08 15:05:31 +0000 | |||
1271 | @@ -38,8 +38,11 @@ | |||
1272 | 38 | #include "naive_ft_token_iterator.h" | 38 | #include "naive_ft_token_iterator.h" |
1273 | 39 | #endif /* ZORBA_NO_FULL_TEXT */ | 39 | #endif /* ZORBA_NO_FULL_TEXT */ |
1274 | 40 | 40 | ||
1275 | 41 | #include "zorbatypes/datetime.h" | ||
1276 | 42 | #include "zorbatypes/decimal.h" | ||
1277 | 43 | #include "zorbatypes/floatimpl.h" | ||
1278 | 44 | #include "zorbatypes/integer.h" | ||
1279 | 41 | #include "zorbatypes/schema_types.h" | 45 | #include "zorbatypes/schema_types.h" |
1280 | 42 | #include "zorbatypes/datetime.h" | ||
1281 | 43 | 46 | ||
1282 | 44 | #include "diagnostics/xquery_diagnostics.h" | 47 | #include "diagnostics/xquery_diagnostics.h" |
1283 | 45 | #include "ordpath.h" | 48 | #include "ordpath.h" |
1284 | 46 | 49 | ||
1285 | === modified file 'src/store/naive/collection.h' | |||
1286 | --- src/store/naive/collection.h 2013-02-26 04:12:43 +0000 | |||
1287 | +++ src/store/naive/collection.h 2013-05-08 15:05:31 +0000 | |||
1288 | @@ -17,6 +17,7 @@ | |||
1289 | 17 | #define ZORBA_SIMPLESTORE_COLLECTION | 17 | #define ZORBA_SIMPLESTORE_COLLECTION |
1290 | 18 | 18 | ||
1291 | 19 | #include "store/api/collection.h" | 19 | #include "store/api/collection.h" |
1292 | 20 | #include "zorbatypes/integer.h" | ||
1293 | 20 | 21 | ||
1294 | 21 | #include "shared_types.h" | 22 | #include "shared_types.h" |
1295 | 22 | #include "tree_id.h" | 23 | #include "tree_id.h" |
1296 | 23 | 24 | ||
1297 | === modified file 'src/store/naive/collection_tree_info.h' | |||
1298 | --- src/store/naive/collection_tree_info.h 2013-02-06 18:52:32 +0000 | |||
1299 | +++ src/store/naive/collection_tree_info.h 2013-05-08 15:05:31 +0000 | |||
1300 | @@ -18,6 +18,7 @@ | |||
1301 | 18 | #define ZORBA_STORE_COLLECTION_TREE_INFO_H | 18 | #define ZORBA_STORE_COLLECTION_TREE_INFO_H |
1302 | 19 | 19 | ||
1303 | 20 | #include <zorba/config.h> | 20 | #include <zorba/config.h> |
1304 | 21 | #include "zorbatypes/integer.h" | ||
1305 | 21 | 22 | ||
1306 | 22 | namespace zorba | 23 | namespace zorba |
1307 | 23 | { | 24 | { |
1308 | 24 | 25 | ||
1309 | === modified file 'src/store/naive/pul_primitives.cpp' | |||
1310 | --- src/store/naive/pul_primitives.cpp 2013-02-26 04:12:43 +0000 | |||
1311 | +++ src/store/naive/pul_primitives.cpp 2013-05-08 15:05:31 +0000 | |||
1312 | @@ -1147,7 +1147,7 @@ | |||
1313 | 1147 | 1147 | ||
1314 | 1148 | assert(lColl); | 1148 | assert(lColl); |
1315 | 1149 | 1149 | ||
1317 | 1150 | xs_integer const zero( xs_integer::zero() ); | 1150 | xs_integer const zero( numeric_consts<xs_integer>::zero() ); |
1318 | 1151 | for (std::size_t i = 0; i < theNumApplied; ++i) | 1151 | for (std::size_t i = 0; i < theNumApplied; ++i) |
1319 | 1152 | { | 1152 | { |
1320 | 1153 | ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(zero)); | 1153 | ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(zero)); |
1321 | 1154 | 1154 | ||
1322 | === modified file 'src/store/naive/simple_collection.cpp' | |||
1323 | --- src/store/naive/simple_collection.cpp 2013-04-16 21:12:12 +0000 | |||
1324 | +++ src/store/naive/simple_collection.cpp 2013-05-08 15:05:31 +0000 | |||
1325 | @@ -93,7 +93,7 @@ | |||
1326 | 93 | const zstring& startRef) | 93 | const zstring& startRef) |
1327 | 94 | { | 94 | { |
1328 | 95 | store::Item_t startNode; | 95 | store::Item_t startNode; |
1330 | 96 | xs_integer startPos = xs_integer::zero(); | 96 | xs_integer startPos; |
1331 | 97 | 97 | ||
1332 | 98 | if (startRef.size() != 0 && | 98 | if (startRef.size() != 0 && |
1333 | 99 | (!GET_STORE().getNodeByReference(startNode, startRef) || | 99 | (!GET_STORE().getNodeByReference(startNode, startRef) || |
1334 | @@ -511,7 +511,7 @@ | |||
1335 | 511 | 511 | ||
1336 | 512 | if (num == 0 || pos >= theTrees.size()) | 512 | if (num == 0 || pos >= theTrees.size()) |
1337 | 513 | { | 513 | { |
1339 | 514 | return xs_integer::zero(); | 514 | return numeric_consts<xs_integer>::zero(); |
1340 | 515 | } | 515 | } |
1341 | 516 | else | 516 | else |
1342 | 517 | { | 517 | { |
1343 | 518 | 518 | ||
1344 | === modified file 'src/store/naive/simple_index_value.h' | |||
1345 | --- src/store/naive/simple_index_value.h 2013-02-07 17:24:36 +0000 | |||
1346 | +++ src/store/naive/simple_index_value.h 2013-05-08 15:05:31 +0000 | |||
1347 | @@ -17,6 +17,7 @@ | |||
1348 | 17 | #define ZORBA_SIMPLE_STORE_INDEX_HASH_VALUE | 17 | #define ZORBA_SIMPLE_STORE_INDEX_HASH_VALUE |
1349 | 18 | 18 | ||
1350 | 19 | #include "simple_index.h" | 19 | #include "simple_index.h" |
1351 | 20 | #include "zorbatypes/integer.h" | ||
1352 | 20 | #include <map> | 21 | #include <map> |
1353 | 21 | 22 | ||
1354 | 22 | namespace zorba | 23 | namespace zorba |
1355 | 23 | 24 | ||
1356 | === modified file 'src/store/naive/simple_lazy_temp_seq.cpp' | |||
1357 | --- src/store/naive/simple_lazy_temp_seq.cpp 2013-04-16 21:12:12 +0000 | |||
1358 | +++ src/store/naive/simple_lazy_temp_seq.cpp 2013-05-08 15:05:31 +0000 | |||
1359 | @@ -21,9 +21,9 @@ | |||
1360 | 21 | #include "diagnostics/dict.h" | 21 | #include "diagnostics/dict.h" |
1361 | 22 | #include "diagnostics/util_macros.h" | 22 | #include "diagnostics/util_macros.h" |
1362 | 23 | #include "diagnostics/xquery_exception.h" | 23 | #include "diagnostics/xquery_exception.h" |
1364 | 24 | 24 | #include "simple_lazy_temp_seq.h" | |
1365 | 25 | #include "store/api/item.h" | 25 | #include "store/api/item.h" |
1367 | 26 | #include "simple_lazy_temp_seq.h" | 26 | #include "zorbatypes/integer.h" |
1368 | 27 | 27 | ||
1369 | 28 | 28 | ||
1370 | 29 | namespace zorba | 29 | namespace zorba |
1371 | 30 | 30 | ||
1372 | === modified file 'src/store/naive/simple_pul.cpp' | |||
1373 | --- src/store/naive/simple_pul.cpp 2013-04-17 18:37:33 +0000 | |||
1374 | +++ src/store/naive/simple_pul.cpp 2013-05-08 15:05:31 +0000 | |||
1375 | @@ -1419,8 +1419,7 @@ | |||
1376 | 1419 | 1419 | ||
1377 | 1420 | xs_integer pos = position->getIntegerValue(); | 1420 | xs_integer pos = position->getIntegerValue(); |
1378 | 1421 | 1421 | ||
1381 | 1422 | if (pos <= xs_integer::zero() || | 1422 | if (pos.sign() <= 0 || arr->getArraySize() + 1 < pos) |
1380 | 1423 | arr->getArraySize() + 1 < pos) | ||
1382 | 1424 | { | 1423 | { |
1383 | 1425 | RAISE_ERROR(jerr::JNUP0016, loc, | 1424 | RAISE_ERROR(jerr::JNUP0016, loc, |
1384 | 1426 | ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue())); | 1425 | ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue())); |
1385 | @@ -1557,8 +1556,7 @@ | |||
1386 | 1557 | 1556 | ||
1387 | 1558 | xs_integer pos = position->getIntegerValue(); | 1557 | xs_integer pos = position->getIntegerValue(); |
1388 | 1559 | 1558 | ||
1391 | 1560 | if (pos <= xs_integer::zero() || | 1559 | if (pos.sign() <= 0 || arr->getArraySize() < pos) |
1390 | 1561 | arr->getArraySize() < pos) | ||
1392 | 1562 | { | 1560 | { |
1393 | 1563 | RAISE_ERROR(jerr::JNUP0016, loc, | 1561 | RAISE_ERROR(jerr::JNUP0016, loc, |
1394 | 1564 | ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue())); | 1562 | ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue())); |
1395 | @@ -1623,8 +1621,7 @@ | |||
1396 | 1623 | 1621 | ||
1397 | 1624 | xs_integer pos = position->getIntegerValue(); | 1622 | xs_integer pos = position->getIntegerValue(); |
1398 | 1625 | 1623 | ||
1401 | 1626 | if (pos <= xs_integer::zero() || | 1624 | if (pos.sign() <= 0 || arr->getArraySize() < pos) |
1400 | 1627 | arr->getArraySize() < pos) | ||
1402 | 1628 | { | 1625 | { |
1403 | 1629 | RAISE_ERROR(jerr::JNUP0016, loc, | 1626 | RAISE_ERROR(jerr::JNUP0016, loc, |
1404 | 1630 | ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue())); | 1627 | ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue())); |
1405 | 1631 | 1628 | ||
1406 | === modified file 'src/store/naive/simple_temp_seq.cpp' | |||
1407 | --- src/store/naive/simple_temp_seq.cpp 2013-04-17 18:37:33 +0000 | |||
1408 | +++ src/store/naive/simple_temp_seq.cpp 2013-05-08 15:05:31 +0000 | |||
1409 | @@ -24,6 +24,7 @@ | |||
1410 | 24 | #include "store/api/item.h" | 24 | #include "store/api/item.h" |
1411 | 25 | #include "simple_temp_seq.h" | 25 | #include "simple_temp_seq.h" |
1412 | 26 | #include "store/api/copymode.h" | 26 | #include "store/api/copymode.h" |
1413 | 27 | #include "zorbatypes/integer.h" | ||
1414 | 27 | 28 | ||
1415 | 28 | namespace zorba { namespace simplestore { | 29 | namespace zorba { namespace simplestore { |
1416 | 29 | 30 | ||
1417 | 30 | 31 | ||
1418 | === modified file 'src/system/globalenv.cpp' | |||
1419 | --- src/system/globalenv.cpp 2013-02-07 17:24:36 +0000 | |||
1420 | +++ src/system/globalenv.cpp 2013-05-08 15:05:31 +0000 | |||
1421 | @@ -42,6 +42,7 @@ | |||
1422 | 42 | 42 | ||
1423 | 43 | #include "types/schema/schema.h" | 43 | #include "types/schema/schema.h" |
1424 | 44 | 44 | ||
1425 | 45 | #include "zorbatypes/m_apm.h" | ||
1426 | 45 | #include "zorbautils/condition.h" | 46 | #include "zorbautils/condition.h" |
1427 | 46 | 47 | ||
1428 | 47 | #include "store/api/collection.h" | 48 | #include "store/api/collection.h" |
1429 | 48 | 49 | ||
1430 | === modified file 'src/types/casting.cpp' | |||
1431 | --- src/types/casting.cpp 2013-05-02 00:18:56 +0000 | |||
1432 | +++ src/types/casting.cpp 2013-05-08 15:05:31 +0000 | |||
1433 | @@ -17,10 +17,13 @@ | |||
1434 | 17 | 17 | ||
1435 | 18 | #include <vector> | 18 | #include <vector> |
1436 | 19 | 19 | ||
1438 | 20 | #include "zorbatypes/numconversions.h" | 20 | #include "zorbatypes/chartype.h" |
1439 | 21 | #include "zorbatypes/datetime.h" | 21 | #include "zorbatypes/datetime.h" |
1440 | 22 | #include "zorbatypes/decimal.h" | ||
1441 | 22 | #include "zorbatypes/duration.h" | 23 | #include "zorbatypes/duration.h" |
1443 | 23 | #include "zorbatypes/chartype.h" | 24 | #include "zorbatypes/floatimpl.h" |
1444 | 25 | #include "zorbatypes/integer.h" | ||
1445 | 26 | #include "zorbatypes/numconversions.h" | ||
1446 | 24 | #include "zorbatypes/URI.h" | 27 | #include "zorbatypes/URI.h" |
1447 | 25 | 28 | ||
1448 | 26 | #include "diagnostics/xquery_diagnostics.h" | 29 | #include "diagnostics/xquery_diagnostics.h" |
1449 | @@ -1433,36 +1436,36 @@ | |||
1450 | 1433 | T1_TO_T2(bool, flt) | 1436 | T1_TO_T2(bool, flt) |
1451 | 1434 | { | 1437 | { |
1452 | 1435 | if (aItem->getBooleanValue()) | 1438 | if (aItem->getBooleanValue()) |
1454 | 1436 | aFactory->createFloat(result, xs_float::one()); | 1439 | aFactory->createFloat(result, numeric_consts<xs_float>::one()); |
1455 | 1437 | else | 1440 | else |
1457 | 1438 | aFactory->createFloat(result, xs_float::zero()); | 1441 | aFactory->createFloat(result, numeric_consts<xs_float>::zero()); |
1458 | 1439 | } | 1442 | } |
1459 | 1440 | 1443 | ||
1460 | 1441 | 1444 | ||
1461 | 1442 | T1_TO_T2(bool, dbl) | 1445 | T1_TO_T2(bool, dbl) |
1462 | 1443 | { | 1446 | { |
1463 | 1444 | if (aItem->getBooleanValue()) | 1447 | if (aItem->getBooleanValue()) |
1465 | 1445 | aFactory->createDouble(result, xs_double::one()); | 1448 | aFactory->createDouble(result, numeric_consts<xs_double>::one()); |
1466 | 1446 | else | 1449 | else |
1468 | 1447 | aFactory->createDouble(result, xs_double::zero()); | 1450 | aFactory->createDouble(result, numeric_consts<xs_double>::zero()); |
1469 | 1448 | } | 1451 | } |
1470 | 1449 | 1452 | ||
1471 | 1450 | 1453 | ||
1472 | 1451 | T1_TO_T2(bool, dec) | 1454 | T1_TO_T2(bool, dec) |
1473 | 1452 | { | 1455 | { |
1474 | 1453 | if (aItem->getBooleanValue()) | 1456 | if (aItem->getBooleanValue()) |
1476 | 1454 | aFactory->createDecimal(result, xs_decimal::one()); | 1457 | aFactory->createDecimal(result, numeric_consts<xs_decimal>::one()); |
1477 | 1455 | else | 1458 | else |
1479 | 1456 | aFactory->createDecimal(result, xs_decimal::zero()); | 1459 | aFactory->createDecimal(result, numeric_consts<xs_decimal>::zero()); |
1480 | 1457 | } | 1460 | } |
1481 | 1458 | 1461 | ||
1482 | 1459 | 1462 | ||
1483 | 1460 | T1_TO_T2(bool, int) | 1463 | T1_TO_T2(bool, int) |
1484 | 1461 | { | 1464 | { |
1485 | 1462 | if (aItem->getBooleanValue()) | 1465 | if (aItem->getBooleanValue()) |
1487 | 1463 | aFactory->createInteger(result, xs_integer::one()); | 1466 | aFactory->createInteger(result, numeric_consts<xs_integer>::one()); |
1488 | 1464 | else | 1467 | else |
1490 | 1465 | aFactory->createInteger(result, xs_integer::zero()); | 1468 | aFactory->createInteger(result, numeric_consts<xs_integer>::zero()); |
1491 | 1466 | } | 1469 | } |
1492 | 1467 | 1470 | ||
1493 | 1468 | 1471 | ||
1494 | @@ -1666,17 +1669,24 @@ | |||
1495 | 1666 | 1669 | ||
1496 | 1667 | T1_TO_T2(dec, uint) | 1670 | T1_TO_T2(dec, uint) |
1497 | 1668 | { | 1671 | { |
1500 | 1669 | xs_nonNegativeInteger const n(aItem->getDecimalValue()); | 1672 | try |
1501 | 1670 | aFactory->createNonNegativeInteger(result, n); | 1673 | { |
1502 | 1674 | xs_nonNegativeInteger const n(aItem->getDecimalValue()); | ||
1503 | 1675 | aFactory->createNonNegativeInteger(result, n); | ||
1504 | 1676 | } | ||
1505 | 1677 | catch ( const std::exception& ) | ||
1506 | 1678 | { | ||
1507 | 1679 | throwFOCA0002Exception(aItem->getStringValue(), errInfo); | ||
1508 | 1680 | } | ||
1509 | 1671 | } | 1681 | } |
1510 | 1672 | 1682 | ||
1511 | 1673 | 1683 | ||
1512 | 1674 | T1_TO_T2(bool, uint) | 1684 | T1_TO_T2(bool, uint) |
1513 | 1675 | { | 1685 | { |
1518 | 1676 | if (aItem->getBooleanValue()) | 1686 | xs_nonNegativeInteger const &i = aItem->getBooleanValue() ? |
1519 | 1677 | aFactory->createNonNegativeInteger(result, xs_nonNegativeInteger::one()); | 1687 | numeric_consts<xs_nonNegativeInteger>::one() : |
1520 | 1678 | else | 1688 | numeric_consts<xs_nonNegativeInteger>::zero(); |
1521 | 1679 | aFactory->createNonNegativeInteger(result, xs_nonNegativeInteger::zero()); | 1689 | aFactory->createNonNegativeInteger(result, i ); |
1522 | 1680 | } | 1690 | } |
1523 | 1681 | 1691 | ||
1524 | 1682 | 1692 | ||
1525 | @@ -2024,12 +2034,16 @@ | |||
1526 | 2024 | } | 2034 | } |
1527 | 2025 | case store::XS_POSITIVE_INTEGER: | 2035 | case store::XS_POSITIVE_INTEGER: |
1528 | 2026 | { | 2036 | { |
1531 | 2027 | xs_positiveInteger const i = aItem->getUnsignedIntegerValue(); | 2037 | try |
1530 | 2028 | if (i.sign() > 0) | ||
1532 | 2029 | { | 2038 | { |
1534 | 2030 | factory->createPositiveInteger(result, i); | 2039 | xs_positiveInteger const n = aItem->getUnsignedIntegerValue(); |
1535 | 2040 | factory->createPositiveInteger(result, n); | ||
1536 | 2031 | return; | 2041 | return; |
1537 | 2032 | } | 2042 | } |
1538 | 2043 | catch ( std::exception const& ) | ||
1539 | 2044 | { | ||
1540 | 2045 | // ignore | ||
1541 | 2046 | } | ||
1542 | 2033 | break; | 2047 | break; |
1543 | 2034 | } | 2048 | } |
1544 | 2035 | default: | 2049 | default: |
1545 | 2036 | 2050 | ||
1546 | === modified file 'src/types/schema/XercesParseUtils.cpp' | |||
1547 | --- src/types/schema/XercesParseUtils.cpp 2013-03-05 12:34:19 +0000 | |||
1548 | +++ src/types/schema/XercesParseUtils.cpp 2013-05-08 15:05:31 +0000 | |||
1549 | @@ -28,15 +28,18 @@ | |||
1550 | 28 | #include "LoadSchemaErrorHandler.h" | 28 | #include "LoadSchemaErrorHandler.h" |
1551 | 29 | #include "PrintSchema.h" | 29 | #include "PrintSchema.h" |
1552 | 30 | 30 | ||
1553 | 31 | #include "diagnostics/xquery_diagnostics.h" | ||
1554 | 31 | #include "store/api/item.h" | 32 | #include "store/api/item.h" |
1555 | 32 | #include "store/api/item_factory.h" | 33 | #include "store/api/item_factory.h" |
1556 | 34 | #include "system/globalenv.h" | ||
1557 | 33 | #include "types/typeimpl.h" | 35 | #include "types/typeimpl.h" |
1561 | 34 | #include "diagnostics/xquery_diagnostics.h" | 36 | #include "util/utf8_util.h" |
1559 | 35 | #include <zorbatypes/numconversions.h> | ||
1560 | 36 | #include "system/globalenv.h" | ||
1562 | 37 | #include "zorbatypes/datetime.h" | 37 | #include "zorbatypes/datetime.h" |
1563 | 38 | #include "zorbatypes/decimal.h" | ||
1564 | 38 | #include "zorbatypes/duration.h" | 39 | #include "zorbatypes/duration.h" |
1566 | 39 | #include "util/utf8_util.h" | 40 | #include "zorbatypes/floatimpl.h" |
1567 | 41 | #include "zorbatypes/integer.h" | ||
1568 | 42 | #include "zorbatypes/numconversions.h" | ||
1569 | 40 | 43 | ||
1570 | 41 | using namespace std; | 44 | using namespace std; |
1571 | 42 | XERCES_CPP_NAMESPACE_USE; | 45 | XERCES_CPP_NAMESPACE_USE; |
1572 | 43 | 46 | ||
1573 | === modified file 'src/util/stl_util.h' | |||
1574 | --- src/util/stl_util.h 2013-04-17 15:21:56 +0000 | |||
1575 | +++ src/util/stl_util.h 2013-05-08 15:05:31 +0000 | |||
1576 | @@ -421,6 +421,13 @@ | |||
1577 | 421 | return true; | 421 | return true; |
1578 | 422 | } | 422 | } |
1579 | 423 | 423 | ||
1580 | 424 | inline std::enable_if<!ZORBA_TR1_NS::is_signed<char>::value | ||
1581 | 425 | && !ZORBA_TR1_NS::is_unsigned<char>::value, | ||
1582 | 426 | bool>::type | ||
1583 | 427 | ge0( char c ) { | ||
1584 | 428 | return c >= 0; | ||
1585 | 429 | } | ||
1586 | 430 | |||
1587 | 424 | template<typename NumericType> inline | 431 | template<typename NumericType> inline |
1588 | 425 | typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type | 432 | typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type |
1589 | 426 | lt0( NumericType n ) { | 433 | lt0( NumericType n ) { |
1590 | @@ -433,6 +440,13 @@ | |||
1591 | 433 | return false; | 440 | return false; |
1592 | 434 | } | 441 | } |
1593 | 435 | 442 | ||
1594 | 443 | inline std::enable_if<!ZORBA_TR1_NS::is_signed<char>::value | ||
1595 | 444 | && !ZORBA_TR1_NS::is_unsigned<char>::value, | ||
1596 | 445 | bool>::type | ||
1597 | 446 | lt0( char c ) { | ||
1598 | 447 | return c < 0; | ||
1599 | 448 | } | ||
1600 | 449 | |||
1601 | 436 | template<typename NumericType> inline | 450 | template<typename NumericType> inline |
1602 | 437 | typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type | 451 | typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type |
1603 | 438 | le0( NumericType n ) { | 452 | le0( NumericType n ) { |
1604 | @@ -445,6 +459,10 @@ | |||
1605 | 445 | return n == 0; | 459 | return n == 0; |
1606 | 446 | } | 460 | } |
1607 | 447 | 461 | ||
1608 | 462 | inline bool le0( char c ) { | ||
1609 | 463 | return c <= 0; | ||
1610 | 464 | } | ||
1611 | 465 | |||
1612 | 448 | /////////////////////////////////////////////////////////////////////////////// | 466 | /////////////////////////////////////////////////////////////////////////////// |
1613 | 449 | 467 | ||
1614 | 450 | // | 468 | // |
1615 | 451 | 469 | ||
1616 | === modified file 'src/zorbaserialization/serialize_basic_types.cpp' | |||
1617 | --- src/zorbaserialization/serialize_basic_types.cpp 2013-04-08 00:12:00 +0000 | |||
1618 | +++ src/zorbaserialization/serialize_basic_types.cpp 2013-05-08 15:05:31 +0000 | |||
1619 | @@ -22,6 +22,7 @@ | |||
1620 | 22 | #include "zorbaserialization/archiver.h" | 22 | #include "zorbaserialization/archiver.h" |
1621 | 23 | #include "zorbaserialization/base64impl.h" | 23 | #include "zorbaserialization/base64impl.h" |
1622 | 24 | 24 | ||
1623 | 25 | #include "zorbatypes/m_apm.h" | ||
1624 | 25 | #include "zorbatypes/floatimpl.h" | 26 | #include "zorbatypes/floatimpl.h" |
1625 | 26 | 27 | ||
1626 | 27 | #include "diagnostics/xquery_diagnostics.h" | 28 | #include "diagnostics/xquery_diagnostics.h" |
1627 | 28 | 29 | ||
1628 | === modified file 'src/zorbaserialization/serialize_zorba_types.cpp' | |||
1629 | --- src/zorbaserialization/serialize_zorba_types.cpp 2013-03-27 17:11:24 +0000 | |||
1630 | +++ src/zorbaserialization/serialize_zorba_types.cpp 2013-05-08 15:05:31 +0000 | |||
1631 | @@ -82,26 +82,21 @@ | |||
1632 | 82 | /******************************************************************************* | 82 | /******************************************************************************* |
1633 | 83 | 83 | ||
1634 | 84 | ********************************************************************************/ | 84 | ********************************************************************************/ |
1655 | 85 | #ifdef ZORBA_WITH_BIG_INTEGER | 85 | |
1656 | 86 | 86 | template<class T> | |
1657 | 87 | void operator&(serialization::Archiver& ar, IntegerImpl& obj) | 87 | void operator&(serialization::Archiver& ar, IntegerImpl<T>& obj) |
1658 | 88 | { | 88 | { |
1659 | 89 | ar & obj.value_; | 89 | ar & obj.value(); |
1660 | 90 | } | 90 | } |
1661 | 91 | 91 | ||
1662 | 92 | #else | 92 | #define INSTANTIATE_INTEGER(I) \ |
1663 | 93 | 93 | template void operator&<I::traits_type>(serialization::Archiver&, I&) | |
1664 | 94 | void operator&(serialization::Archiver& ar, IntegerImpl<long long>& obj) | 94 | |
1665 | 95 | { | 95 | INSTANTIATE_INTEGER( Integer ); |
1666 | 96 | ar & obj.value(); | 96 | INSTANTIATE_INTEGER( NegativeInteger ); |
1667 | 97 | } | 97 | INSTANTIATE_INTEGER( NonNegativeInteger ); |
1668 | 98 | 98 | INSTANTIATE_INTEGER( NonPositiveInteger ); | |
1669 | 99 | void operator&(serialization::Archiver& ar, IntegerImpl<unsigned long long>& obj) | 99 | INSTANTIATE_INTEGER( PositiveInteger ); |
1650 | 100 | { | ||
1651 | 101 | ar & obj.value(); | ||
1652 | 102 | } | ||
1653 | 103 | |||
1654 | 104 | #endif | ||
1670 | 105 | 100 | ||
1671 | 106 | 101 | ||
1672 | 107 | /******************************************************************************* | 102 | /******************************************************************************* |
1673 | 108 | 103 | ||
1674 | === modified file 'src/zorbaserialization/serialize_zorba_types.h' | |||
1675 | --- src/zorbaserialization/serialize_zorba_types.h 2013-02-07 17:24:36 +0000 | |||
1676 | +++ src/zorbaserialization/serialize_zorba_types.h 2013-05-08 15:05:31 +0000 | |||
1677 | @@ -23,6 +23,7 @@ | |||
1678 | 23 | #include "zorbatypes/rchandle.h" | 23 | #include "zorbatypes/rchandle.h" |
1679 | 24 | #include "zorbatypes/m_apm.h" | 24 | #include "zorbatypes/m_apm.h" |
1680 | 25 | #include "zorbatypes/floatimpl.h" | 25 | #include "zorbatypes/floatimpl.h" |
1681 | 26 | #include "zorbatypes/zorbatypes_decl.h" | ||
1682 | 26 | 27 | ||
1683 | 27 | #include "zorbautils/checked_vector.h" | 28 | #include "zorbautils/checked_vector.h" |
1684 | 28 | 29 | ||
1685 | @@ -37,24 +38,16 @@ | |||
1686 | 37 | 38 | ||
1687 | 38 | namespace zorba | 39 | namespace zorba |
1688 | 39 | { | 40 | { |
1689 | 40 | class Decimal; | ||
1690 | 41 | class Duration; | ||
1691 | 42 | class Timezone; | ||
1692 | 43 | class DateTime; | ||
1693 | 44 | class Base16; | 41 | class Base16; |
1694 | 45 | class Base64; | 42 | class Base64; |
1696 | 46 | class QueryLoc; | 43 | class Diagnostic; |
1697 | 44 | class function; | ||
1698 | 47 | class HashMapItemPointerCmp; | 45 | class HashMapItemPointerCmp; |
1699 | 48 | class HashMapZStringCmp; | 46 | class HashMapZStringCmp; |
1700 | 47 | class QueryLoc; | ||
1701 | 48 | class Timezone; | ||
1702 | 49 | class XQType; | 49 | class XQType; |
1703 | 50 | class function; | ||
1704 | 51 | class Diagnostic; | ||
1705 | 52 | class ZorbaException; | 50 | class ZorbaException; |
1706 | 53 | #ifdef ZORBA_WITH_BIG_INTEGER | ||
1707 | 54 | class IntegerImpl; | ||
1708 | 55 | #else | ||
1709 | 56 | template<typename IntType> class IntegerImpl; | ||
1710 | 57 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
1711 | 58 | 51 | ||
1712 | 59 | namespace serialization | 52 | namespace serialization |
1713 | 60 | { | 53 | { |
1714 | @@ -65,12 +58,8 @@ | |||
1715 | 65 | 58 | ||
1716 | 66 | void operator&(Archiver& ar, const XQType*& obj); | 59 | void operator&(Archiver& ar, const XQType*& obj); |
1717 | 67 | 60 | ||
1724 | 68 | #ifdef ZORBA_WITH_BIG_INTEGER | 61 | template<class C> |
1725 | 69 | void operator&(Archiver& ar, IntegerImpl& obj); | 62 | void operator&(Archiver& ar, IntegerImpl<C>& obj); |
1720 | 70 | #else | ||
1721 | 71 | void operator&(serialization::Archiver& ar, IntegerImpl<long long>& obj); | ||
1722 | 72 | void operator&(serialization::Archiver& ar, IntegerImpl<unsigned long long>& obj); | ||
1723 | 73 | #endif | ||
1726 | 74 | 63 | ||
1727 | 75 | void operator&(Archiver& ar, Decimal& obj); | 64 | void operator&(Archiver& ar, Decimal& obj); |
1728 | 76 | 65 | ||
1729 | 77 | 66 | ||
1730 | === modified file 'src/zorbatypes/CMakeLists.txt' | |||
1731 | --- src/zorbatypes/CMakeLists.txt 2013-02-07 17:24:36 +0000 | |||
1732 | +++ src/zorbatypes/CMakeLists.txt 2013-05-08 15:05:31 +0000 | |||
1733 | @@ -17,6 +17,7 @@ | |||
1734 | 17 | floatimpl.cpp | 17 | floatimpl.cpp |
1735 | 18 | integer.cpp | 18 | integer.cpp |
1736 | 19 | numconversions.cpp | 19 | numconversions.cpp |
1737 | 20 | numeric_types.cpp | ||
1738 | 20 | binary.cpp | 21 | binary.cpp |
1739 | 21 | URI.cpp | 22 | URI.cpp |
1740 | 22 | collation_manager.cpp | 23 | collation_manager.cpp |
1741 | 23 | 24 | ||
1742 | === modified file 'src/zorbatypes/datetime.h' | |||
1743 | --- src/zorbatypes/datetime.h 2013-04-23 06:09:42 +0000 | |||
1744 | +++ src/zorbatypes/datetime.h 2013-05-08 15:05:31 +0000 | |||
1745 | @@ -20,11 +20,10 @@ | |||
1746 | 20 | #include <iostream> | 20 | #include <iostream> |
1747 | 21 | 21 | ||
1748 | 22 | #include <zorba/config.h> | 22 | #include <zorba/config.h> |
1749 | 23 | #include "zorbatypes/timezone.h" | ||
1750 | 24 | #include "zorbatypes/duration.h" | ||
1751 | 25 | |||
1752 | 26 | #include "util/ascii_util.h" | 23 | #include "util/ascii_util.h" |
1753 | 27 | 24 | ||
1754 | 25 | #include "timezone.h" | ||
1755 | 26 | #include "duration.h" | ||
1756 | 28 | 27 | ||
1757 | 29 | namespace zorba | 28 | namespace zorba |
1758 | 30 | { | 29 | { |
1759 | @@ -301,7 +300,7 @@ | |||
1760 | 301 | 300 | ||
1761 | 302 | int getMinutes() const; | 301 | int getMinutes() const; |
1762 | 303 | 302 | ||
1764 | 304 | xs_decimal getSeconds() const; | 303 | Decimal getSeconds() const; |
1765 | 305 | 304 | ||
1766 | 306 | int getIntSeconds() const; | 305 | int getIntSeconds() const; |
1767 | 307 | 306 | ||
1768 | 308 | 307 | ||
1769 | === modified file 'src/zorbatypes/datetime/datetimetype.cpp' | |||
1770 | --- src/zorbatypes/datetime/datetimetype.cpp 2013-04-24 17:26:02 +0000 | |||
1771 | +++ src/zorbatypes/datetime/datetimetype.cpp 2013-05-08 15:05:31 +0000 | |||
1772 | @@ -29,14 +29,15 @@ | |||
1773 | 29 | #include <time.h> | 29 | #include <time.h> |
1774 | 30 | #endif | 30 | #endif |
1775 | 31 | 31 | ||
1776 | 32 | #include "zorbatypes/datetime.h" | ||
1777 | 33 | #include "zorbatypes/datetime/parse.h" | ||
1778 | 34 | #include "zorbatypes/decimal.h" | ||
1779 | 35 | #include "zorbatypes/duration.h" | ||
1780 | 36 | #include "zorbatypes/integer.h" | ||
1781 | 37 | #include "zorbatypes/timezone.h" | ||
1782 | 38 | #include "zorbatypes/zorbatypes_decl.h" | ||
1783 | 39 | #include "zorbatypes/zstring.h" | ||
1784 | 32 | #include "zorbautils/hashfun.h" | 40 | #include "zorbautils/hashfun.h" |
1785 | 33 | #include <zorbatypes/datetime.h> | ||
1786 | 34 | #include <zorbatypes/duration.h> | ||
1787 | 35 | #include <zorbatypes/timezone.h> | ||
1788 | 36 | #include <zorbatypes/zorbatypes_decl.h> | ||
1789 | 37 | #include <zorbatypes/zstring.h> | ||
1790 | 38 | |||
1791 | 39 | #include "zorbatypes/datetime/parse.h" | ||
1792 | 40 | 41 | ||
1793 | 41 | #include "util/ascii_util.h" | 42 | #include "util/ascii_util.h" |
1794 | 42 | #include "util/time_util.h" | 43 | #include "util/time_util.h" |
1795 | @@ -1325,7 +1326,7 @@ | |||
1796 | 1325 | // validate timezone value (-14 .. +14 H) | 1326 | // validate timezone value (-14 .. +14 H) |
1797 | 1326 | if (d->getYears() != 0 || d->getMonths() != 0 || | 1327 | if (d->getYears() != 0 || d->getMonths() != 0 || |
1798 | 1327 | d->getDays() != 0 || | 1328 | d->getDays() != 0 || |
1800 | 1328 | d->getSeconds() != Integer::zero() || | 1329 | d->getSeconds().sign() != 0 || |
1801 | 1329 | d->getHours()*3600 + d->getMinutes()*60 > 14*3600 || | 1330 | d->getHours()*3600 + d->getMinutes()*60 > 14*3600 || |
1802 | 1330 | d->getHours()*3600 + d->getMinutes()*60 < -14*3600) | 1331 | d->getHours()*3600 + d->getMinutes()*60 < -14*3600) |
1803 | 1331 | throw InvalidTimezoneException( d->getHours()*3600 + d->getMinutes()*60 ); | 1332 | throw InvalidTimezoneException( d->getHours()*3600 + d->getMinutes()*60 ); |
1804 | 1332 | 1333 | ||
1805 | === modified file 'src/zorbatypes/datetime/duration.cpp' | |||
1806 | --- src/zorbatypes/datetime/duration.cpp 2013-04-16 21:12:12 +0000 | |||
1807 | +++ src/zorbatypes/datetime/duration.cpp 2013-05-08 15:05:31 +0000 | |||
1808 | @@ -19,11 +19,14 @@ | |||
1809 | 19 | #include <memory> | 19 | #include <memory> |
1810 | 20 | #include <string> | 20 | #include <string> |
1811 | 21 | 21 | ||
1813 | 22 | #include "zorbautils/hashfun.h" | 22 | #include "zorbatypes/datetime.h" |
1814 | 23 | #include "zorbatypes/datetime/parse.h" | ||
1815 | 24 | #include "zorbatypes/decimal.h" | ||
1816 | 23 | #include "zorbatypes/duration.h" | 25 | #include "zorbatypes/duration.h" |
1818 | 24 | #include "zorbatypes/datetime/parse.h" | 26 | #include "zorbatypes/floatimpl.h" |
1819 | 27 | #include "zorbatypes/integer.h" | ||
1820 | 25 | #include "zorbatypes/numconversions.h" | 28 | #include "zorbatypes/numconversions.h" |
1822 | 26 | #include "zorbatypes/datetime.h" | 29 | #include "zorbautils/hashfun.h" |
1823 | 27 | 30 | ||
1824 | 28 | #include "diagnostics/xquery_diagnostics.h" | 31 | #include "diagnostics/xquery_diagnostics.h" |
1825 | 29 | 32 | ||
1826 | @@ -597,7 +600,8 @@ | |||
1827 | 597 | 600 | ||
1828 | 598 | xs_double Duration::getTotalSeconds() const | 601 | xs_double Duration::getTotalSeconds() const |
1829 | 599 | { | 602 | { |
1831 | 600 | return (is_negative ? xs_double::neg_one() : xs_double::one()) | 603 | return (is_negative ? |
1832 | 604 | numeric_consts<xs_double>::neg_one() : numeric_consts<xs_double>::one()) | ||
1833 | 601 | * ((((((((xs_double(data[YEAR_DATA]) * 12 | 605 | * ((((((((xs_double(data[YEAR_DATA]) * 12 |
1834 | 602 | + xs_double(data[MONTH_DATA])) * 30) | 606 | + xs_double(data[MONTH_DATA])) * 30) |
1835 | 603 | + xs_double(data[DAY_DATA])) * 24) | 607 | + xs_double(data[DAY_DATA])) * 24) |
1836 | 604 | 608 | ||
1837 | === modified file 'src/zorbatypes/datetime/timezone.cpp' | |||
1838 | --- src/zorbatypes/datetime/timezone.cpp 2013-03-13 16:19:33 +0000 | |||
1839 | +++ src/zorbatypes/datetime/timezone.cpp 2013-05-08 15:05:31 +0000 | |||
1840 | @@ -22,6 +22,7 @@ | |||
1841 | 22 | #include <zorbatypes/timezone.h> | 22 | #include <zorbatypes/timezone.h> |
1842 | 23 | 23 | ||
1843 | 24 | #include "zorbatypes/datetime/parse.h" | 24 | #include "zorbatypes/datetime/parse.h" |
1844 | 25 | #include "zorbatypes/decimal.h" | ||
1845 | 25 | 26 | ||
1846 | 26 | #include "zorbautils/hashfun.h" | 27 | #include "zorbautils/hashfun.h" |
1847 | 27 | 28 | ||
1848 | 28 | 29 | ||
1849 | === modified file 'src/zorbatypes/decimal.cpp' | |||
1850 | --- src/zorbatypes/decimal.cpp 2013-04-11 18:13:48 +0000 | |||
1851 | +++ src/zorbatypes/decimal.cpp 2013-05-08 15:05:31 +0000 | |||
1852 | @@ -23,19 +23,10 @@ | |||
1853 | 23 | #include "util/ascii_util.h" | 23 | #include "util/ascii_util.h" |
1854 | 24 | 24 | ||
1855 | 25 | #include "decimal.h" | 25 | #include "decimal.h" |
1856 | 26 | #include "floatimpl.h" | ||
1857 | 26 | #include "integer.h" | 27 | #include "integer.h" |
1858 | 27 | #include "numconversions.h" | 28 | #include "numconversions.h" |
1859 | 28 | 29 | ||
1860 | 29 | #ifdef ZORBA_WITH_BIG_INTEGER | ||
1861 | 30 | # define TEMPLATE_DECL(T) /* nothing */ | ||
1862 | 31 | # define INTEGER_IMPL(I) IntegerImpl | ||
1863 | 32 | #else | ||
1864 | 33 | # define TEMPLATE_DECL(T) template<typename T> /* spacer */ | ||
1865 | 34 | # define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */ | ||
1866 | 35 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
1867 | 36 | #define INTEGER_IMPL_LL INTEGER_IMPL(long long) | ||
1868 | 37 | #define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long) | ||
1869 | 38 | |||
1870 | 39 | namespace zorba { | 30 | namespace zorba { |
1871 | 40 | 31 | ||
1872 | 41 | /////////////////////////////////////////////////////////////////////////////// | 32 | /////////////////////////////////////////////////////////////////////////////// |
1873 | @@ -79,7 +70,6 @@ | |||
1874 | 79 | delete[] copy; | 70 | delete[] copy; |
1875 | 80 | } else | 71 | } else |
1876 | 81 | *result = first_non_ws; | 72 | *result = first_non_ws; |
1877 | 82 | |||
1878 | 83 | } | 73 | } |
1879 | 84 | 74 | ||
1880 | 85 | /** | 75 | /** |
1881 | @@ -178,7 +168,6 @@ | |||
1882 | 178 | } | 168 | } |
1883 | 179 | } | 169 | } |
1884 | 180 | 170 | ||
1885 | 181 | |||
1886 | 182 | ////////// constructors /////////////////////////////////////////////////////// | 171 | ////////// constructors /////////////////////////////////////////////////////// |
1887 | 183 | 172 | ||
1888 | 184 | Decimal::Decimal( long long n ) { | 173 | Decimal::Decimal( long long n ) { |
1889 | @@ -224,14 +213,16 @@ | |||
1890 | 224 | value_ = f.getNumber(); | 213 | value_ = f.getNumber(); |
1891 | 225 | } | 214 | } |
1892 | 226 | 215 | ||
1896 | 227 | TEMPLATE_DECL(I) | 216 | template<class T> |
1897 | 228 | Decimal::Decimal( INTEGER_IMPL(I) const &i ) : | 217 | Decimal::Decimal( IntegerImpl<T> const &i ) : value_( i.itod() ) { |
1895 | 229 | value_( i.itod() ) { | ||
1898 | 230 | } | 218 | } |
1903 | 231 | #ifndef ZORBA_WITH_BIG_INTEGER | 219 | |
1904 | 232 | template Decimal::Decimal( INTEGER_IMPL_LL const& ); | 220 | // instantiate Decimal-from-Integer constructors |
1905 | 233 | template Decimal::Decimal( INTEGER_IMPL_ULL const& ); | 221 | template Decimal::Decimal( Integer const& ); |
1906 | 234 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 222 | template Decimal::Decimal( NegativeInteger const& ); |
1907 | 223 | template Decimal::Decimal( NonNegativeInteger const& ); | ||
1908 | 224 | template Decimal::Decimal( NonPositiveInteger const& ); | ||
1909 | 225 | template Decimal::Decimal( PositiveInteger const& ); | ||
1910 | 235 | 226 | ||
1911 | 236 | ////////// assignment operators /////////////////////////////////////////////// | 227 | ////////// assignment operators /////////////////////////////////////////////// |
1912 | 237 | 228 | ||
1913 | @@ -247,15 +238,17 @@ | |||
1914 | 247 | return *this; | 238 | return *this; |
1915 | 248 | } | 239 | } |
1916 | 249 | 240 | ||
1919 | 250 | TEMPLATE_DECL(I) | 241 | template<class T> |
1920 | 251 | Decimal& Decimal::operator=( INTEGER_IMPL(I) const &i ) { | 242 | Decimal& Decimal::operator=( IntegerImpl<T> const &i ) { |
1921 | 252 | value_ = i.itod(); | 243 | value_ = i.itod(); |
1922 | 253 | return *this; | 244 | return *this; |
1923 | 254 | } | 245 | } |
1928 | 255 | #ifndef ZORBA_WITH_BIG_INTEGER | 246 | |
1929 | 256 | template Decimal& Decimal::operator=( INTEGER_IMPL_LL const& ); | 247 | template Decimal& Decimal::operator=( Integer const& ); |
1930 | 257 | template Decimal& Decimal::operator=( INTEGER_IMPL_ULL const& ); | 248 | template Decimal& Decimal::operator=( NegativeInteger const& ); |
1931 | 258 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 249 | template Decimal& Decimal::operator=( NonNegativeInteger const& ); |
1932 | 250 | template Decimal& Decimal::operator=( NonPositiveInteger const& ); | ||
1933 | 251 | template Decimal& Decimal::operator=( PositiveInteger const& ); | ||
1934 | 259 | 252 | ||
1935 | 260 | Decimal& Decimal::operator=( Double const &d ) { | 253 | Decimal& Decimal::operator=( Double const &d ) { |
1936 | 261 | if ( !d.isFinite() ) | 254 | if ( !d.isFinite() ) |
1937 | @@ -273,20 +266,19 @@ | |||
1938 | 273 | 266 | ||
1939 | 274 | ////////// arithmetic operators /////////////////////////////////////////////// | 267 | ////////// arithmetic operators /////////////////////////////////////////////// |
1940 | 275 | 268 | ||
1948 | 276 | #ifdef ZORBA_WITH_BIG_INTEGER | 269 | #define ZORBA_INSTANTIATE(OP,I) \ |
1949 | 277 | # define ZORBA_INSTANTIATE(OP) /* nothing */ | 270 | template Decimal operator OP( Decimal const&, I const& ) |
1943 | 278 | #else | ||
1944 | 279 | # define ZORBA_INSTANTIATE(OP) \ | ||
1945 | 280 | template Decimal operator OP( Decimal const&, INTEGER_IMPL_LL const& ); \ | ||
1946 | 281 | template Decimal operator OP( Decimal const&, INTEGER_IMPL_ULL const& ) | ||
1947 | 282 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
1950 | 283 | 271 | ||
1951 | 284 | #define ZORBA_DECIMAL_OP(OP) \ | 272 | #define ZORBA_DECIMAL_OP(OP) \ |
1954 | 285 | TEMPLATE_DECL(I) \ | 273 | template<class T> inline \ |
1955 | 286 | Decimal operator OP( Decimal const &d, INTEGER_IMPL(I) const &i ) { \ | 274 | Decimal operator OP( Decimal const &d, IntegerImpl<T> const &i ) { \ |
1956 | 287 | return d.value_ OP i.itod(); \ | 275 | return d.value_ OP i.itod(); \ |
1957 | 288 | } \ | 276 | } \ |
1959 | 289 | ZORBA_INSTANTIATE(OP) | 277 | ZORBA_INSTANTIATE(OP,Integer); \ |
1960 | 278 | ZORBA_INSTANTIATE(OP,NegativeInteger); \ | ||
1961 | 279 | ZORBA_INSTANTIATE(OP,NonNegativeInteger); \ | ||
1962 | 280 | ZORBA_INSTANTIATE(OP,NonPositiveInteger); \ | ||
1963 | 281 | ZORBA_INSTANTIATE(OP,PositiveInteger); | ||
1964 | 290 | 282 | ||
1965 | 291 | ZORBA_DECIMAL_OP(+); | 283 | ZORBA_DECIMAL_OP(+); |
1966 | 292 | ZORBA_DECIMAL_OP(-); | 284 | ZORBA_DECIMAL_OP(-); |
1967 | @@ -298,20 +290,19 @@ | |||
1968 | 298 | 290 | ||
1969 | 299 | ////////// relational operators /////////////////////////////////////////////// | 291 | ////////// relational operators /////////////////////////////////////////////// |
1970 | 300 | 292 | ||
1978 | 301 | #ifdef ZORBA_WITH_BIG_INTEGER | 293 | #define ZORBA_INSTANTIATE(OP,I) \ |
1979 | 302 | # define ZORBA_INSTANTIATE(OP) /* nothing */ | 294 | template bool operator OP( Decimal const&, I const& ) |
1973 | 303 | #else | ||
1974 | 304 | # define ZORBA_INSTANTIATE(OP) \ | ||
1975 | 305 | template bool operator OP( Decimal const&, INTEGER_IMPL_LL const& ); \ | ||
1976 | 306 | template bool operator OP( Decimal const&, INTEGER_IMPL_ULL const& ) | ||
1977 | 307 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
1980 | 308 | 295 | ||
1987 | 309 | #define ZORBA_DECIMAL_OP(OP) \ | 296 | #define ZORBA_DECIMAL_OP(OP) \ |
1988 | 310 | TEMPLATE_DECL(I) \ | 297 | template<class T> inline \ |
1989 | 311 | bool operator OP( Decimal const &d, INTEGER_IMPL(I) const &i ) { \ | 298 | bool operator OP( Decimal const &d, IntegerImpl<T> const &i ) { \ |
1990 | 312 | return d.value_ OP i.itod(); \ | 299 | return d.value_ OP i.itod(); \ |
1991 | 313 | } \ | 300 | } \ |
1992 | 314 | ZORBA_INSTANTIATE(OP) | 301 | ZORBA_INSTANTIATE( OP, Integer ); \ |
1993 | 302 | ZORBA_INSTANTIATE( OP, NegativeInteger ); \ | ||
1994 | 303 | ZORBA_INSTANTIATE( OP, NonNegativeInteger ); \ | ||
1995 | 304 | ZORBA_INSTANTIATE( OP, NonPositiveInteger ); \ | ||
1996 | 305 | ZORBA_INSTANTIATE( OP, PositiveInteger ); | ||
1997 | 315 | 306 | ||
1998 | 316 | ZORBA_DECIMAL_OP(==); | 307 | ZORBA_DECIMAL_OP(==); |
1999 | 317 | ZORBA_DECIMAL_OP(!=); | 308 | ZORBA_DECIMAL_OP(!=); |
2000 | @@ -325,17 +316,19 @@ | |||
2001 | 325 | ////////// math functions ///////////////////////////////////////////////////// | 316 | ////////// math functions ///////////////////////////////////////////////////// |
2002 | 326 | 317 | ||
2003 | 327 | Decimal Decimal::round() const { | 318 | Decimal Decimal::round() const { |
2005 | 328 | return round( INTEGER_IMPL_LL::zero() ); | 319 | return round( numeric_consts<xs_integer>::zero() ); |
2006 | 329 | } | 320 | } |
2007 | 330 | 321 | ||
2010 | 331 | TEMPLATE_DECL(I) | 322 | template<class T> |
2011 | 332 | Decimal Decimal::round( INTEGER_IMPL(I) const &precision ) const { | 323 | Decimal Decimal::round( IntegerImpl<T> const &precision ) const { |
2012 | 333 | return round2( value_, precision.itod() ); | 324 | return round2( value_, precision.itod() ); |
2013 | 334 | } | 325 | } |
2018 | 335 | #ifndef ZORBA_WITH_BIG_INTEGER | 326 | |
2019 | 336 | template Decimal Decimal::round( INTEGER_IMPL_LL const& ) const; | 327 | template Decimal Decimal::round( Integer const& ) const; |
2020 | 337 | template Decimal Decimal::round( INTEGER_IMPL_ULL const& ) const; | 328 | template Decimal Decimal::round( NegativeInteger const& ) const; |
2021 | 338 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 329 | template Decimal Decimal::round( NonNegativeInteger const& ) const; |
2022 | 330 | template Decimal Decimal::round( NonPositiveInteger const& ) const; | ||
2023 | 331 | template Decimal Decimal::round( PositiveInteger const& ) const; | ||
2024 | 339 | 332 | ||
2025 | 340 | Decimal::value_type Decimal::round2( value_type const &v, | 333 | Decimal::value_type Decimal::round2( value_type const &v, |
2026 | 341 | value_type const &precision ) { | 334 | value_type const &precision ) { |
2027 | @@ -352,14 +345,16 @@ | |||
2028 | 352 | return result; | 345 | return result; |
2029 | 353 | } | 346 | } |
2030 | 354 | 347 | ||
2033 | 355 | TEMPLATE_DECL(I) | 348 | template<class T> |
2034 | 356 | Decimal Decimal::roundHalfToEven( INTEGER_IMPL(I) const &precision ) const { | 349 | Decimal Decimal::roundHalfToEven( IntegerImpl<T> const &precision ) const { |
2035 | 357 | return roundHalfToEven2( value_, precision.itod() ); | 350 | return roundHalfToEven2( value_, precision.itod() ); |
2036 | 358 | } | 351 | } |
2041 | 359 | #ifndef ZORBA_WITH_BIG_INTEGER | 352 | |
2042 | 360 | template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_LL const& ) const; | 353 | template Decimal Decimal::roundHalfToEven( Integer const& ) const; |
2043 | 361 | template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_ULL const& ) const; | 354 | template Decimal Decimal::roundHalfToEven( NegativeInteger const& ) const; |
2044 | 362 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 355 | template Decimal Decimal::roundHalfToEven( NonNegativeInteger const& ) const; |
2045 | 356 | template Decimal Decimal::roundHalfToEven( NonPositiveInteger const& ) const; | ||
2046 | 357 | template Decimal Decimal::roundHalfToEven( PositiveInteger const& ) const; | ||
2047 | 363 | 358 | ||
2048 | 364 | Decimal::value_type Decimal::roundHalfToEven2( value_type const &v, | 359 | Decimal::value_type Decimal::roundHalfToEven2( value_type const &v, |
2049 | 365 | value_type const &precision ) { | 360 | value_type const &precision ) { |
2050 | @@ -425,21 +420,15 @@ | |||
2051 | 425 | return static_cast<uint32_t>( n ); | 420 | return static_cast<uint32_t>( n ); |
2052 | 426 | } | 421 | } |
2053 | 427 | 422 | ||
2064 | 428 | Decimal const& Decimal::one() { | 423 | zstring Decimal::toString( value_type const &value, bool minusZero, |
2065 | 429 | static Decimal d(1); | 424 | int precision ) { |
2056 | 430 | return d; | ||
2057 | 431 | } | ||
2058 | 432 | |||
2059 | 433 | zstring Decimal::toString( value_type const &value, int precision ) { | ||
2060 | 434 | return toString(value, false, precision); | ||
2061 | 435 | } | ||
2062 | 436 | |||
2063 | 437 | zstring Decimal::toString( value_type const &value, bool minusZero, int precision ) { | ||
2066 | 438 | char buf[ 1024 ]; | 425 | char buf[ 1024 ]; |
2067 | 439 | 426 | ||
2071 | 440 | if ( minusZero ) | 427 | if ( minusZero ) { |
2072 | 441 | { | 428 | if ( value.sign() == 0 ) |
2073 | 442 | buf[0] = '-'; | 429 | buf[0] = '-'; |
2074 | 430 | else | ||
2075 | 431 | minusZero = false; | ||
2076 | 443 | } | 432 | } |
2077 | 444 | 433 | ||
2078 | 445 | value.toFixPtString( buf + minusZero, precision ); | 434 | value.toFixPtString( buf + minusZero, precision ); |
2079 | @@ -464,11 +453,6 @@ | |||
2080 | 464 | return buf; | 453 | return buf; |
2081 | 465 | } | 454 | } |
2082 | 466 | 455 | ||
2083 | 467 | Decimal const& Decimal::zero() { | ||
2084 | 468 | static Decimal d(0); | ||
2085 | 469 | return d; | ||
2086 | 470 | } | ||
2087 | 471 | |||
2088 | 472 | /////////////////////////////////////////////////////////////////////////////// | 456 | /////////////////////////////////////////////////////////////////////////////// |
2089 | 473 | 457 | ||
2090 | 474 | } // namespace zorba | 458 | } // namespace zorba |
2091 | 475 | 459 | ||
2092 | === modified file 'src/zorbatypes/decimal.h' | |||
2093 | --- src/zorbatypes/decimal.h 2013-04-11 18:13:48 +0000 | |||
2094 | +++ src/zorbatypes/decimal.h 2013-05-08 15:05:31 +0000 | |||
2095 | @@ -28,14 +28,6 @@ | |||
2096 | 28 | #include "zorbatypes_decl.h" | 28 | #include "zorbatypes_decl.h" |
2097 | 29 | #include "zstring.h" | 29 | #include "zstring.h" |
2098 | 30 | 30 | ||
2099 | 31 | #ifdef ZORBA_WITH_BIG_INTEGER | ||
2100 | 32 | # define TEMPLATE_DECL(I) /* nothing */ | ||
2101 | 33 | # define INTEGER_IMPL(I) IntegerImpl | ||
2102 | 34 | #else | ||
2103 | 35 | # define TEMPLATE_DECL(I) template<typename I> /* spacer */ | ||
2104 | 36 | # define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */ | ||
2105 | 37 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
2106 | 38 | |||
2107 | 39 | namespace zorba { | 31 | namespace zorba { |
2108 | 40 | 32 | ||
2109 | 41 | class Decimal; | 33 | class Decimal; |
2110 | @@ -72,8 +64,8 @@ | |||
2111 | 72 | explicit Decimal( float n ); | 64 | explicit Decimal( float n ); |
2112 | 73 | explicit Decimal( double n ); | 65 | explicit Decimal( double n ); |
2113 | 74 | 66 | ||
2116 | 75 | TEMPLATE_DECL(I) | 67 | template<class T> |
2117 | 76 | explicit Decimal( INTEGER_IMPL(I) const &i ); | 68 | explicit Decimal( IntegerImpl<T> const &i ); |
2118 | 77 | 69 | ||
2119 | 78 | /** | 70 | /** |
2120 | 79 | * Constructs a %Decimal from a C string. | 71 | * Constructs a %Decimal from a C string. |
2121 | @@ -133,8 +125,8 @@ | |||
2122 | 133 | Decimal& operator=( Double const &d ); | 125 | Decimal& operator=( Double const &d ); |
2123 | 134 | Decimal& operator=( Float const &f ); | 126 | Decimal& operator=( Float const &f ); |
2124 | 135 | 127 | ||
2127 | 136 | TEMPLATE_DECL(I) | 128 | template<class T> |
2128 | 137 | Decimal& operator=( INTEGER_IMPL(I) const &i ); | 129 | Decimal& operator=( IntegerImpl<T> const &i ); |
2129 | 138 | 130 | ||
2130 | 139 | ////////// arithmetic operators ///////////////////////////////////////////// | 131 | ////////// arithmetic operators ///////////////////////////////////////////// |
2131 | 140 | 132 | ||
2132 | @@ -145,11 +137,11 @@ | |||
2133 | 145 | friend Decimal operator%( Decimal const&, Decimal const& ); | 137 | friend Decimal operator%( Decimal const&, Decimal const& ); |
2134 | 146 | 138 | ||
2135 | 147 | #define ZORBA_DECIMAL_OP(OP) \ | 139 | #define ZORBA_DECIMAL_OP(OP) \ |
2138 | 148 | TEMPLATE_DECL(I) \ | 140 | template<class T> \ |
2139 | 149 | friend Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \ | 141 | friend Decimal operator OP( Decimal const&, IntegerImpl<T> const& ); \ |
2140 | 150 | \ | 142 | \ |
2143 | 151 | TEMPLATE_DECL(I) \ | 143 | template<class T> \ |
2144 | 152 | friend Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& ) | 144 | friend Decimal operator OP( IntegerImpl<T> const&, Decimal const& ) |
2145 | 153 | 145 | ||
2146 | 154 | ZORBA_DECIMAL_OP(+); | 146 | ZORBA_DECIMAL_OP(+); |
2147 | 155 | ZORBA_DECIMAL_OP(-); | 147 | ZORBA_DECIMAL_OP(-); |
2148 | @@ -165,7 +157,7 @@ | |||
2149 | 165 | Decimal& operator%=( Decimal const& ); | 157 | Decimal& operator%=( Decimal const& ); |
2150 | 166 | 158 | ||
2151 | 167 | #define ZORBA_DECIMAL_OP(OP) \ | 159 | #define ZORBA_DECIMAL_OP(OP) \ |
2153 | 168 | TEMPLATE_DECL(I) Decimal& operator OP( INTEGER_IMPL(I) const& ) | 160 | template<class T> Decimal& operator OP( IntegerImpl<T> const& ) |
2154 | 169 | 161 | ||
2155 | 170 | ZORBA_DECIMAL_OP(+=); | 162 | ZORBA_DECIMAL_OP(+=); |
2156 | 171 | ZORBA_DECIMAL_OP(-=); | 163 | ZORBA_DECIMAL_OP(-=); |
2157 | @@ -178,12 +170,12 @@ | |||
2158 | 178 | 170 | ||
2159 | 179 | ////////// relational operators ///////////////////////////////////////////// | 171 | ////////// relational operators ///////////////////////////////////////////// |
2160 | 180 | 172 | ||
2167 | 181 | #define ZORBA_DECIMAL_OP(OP) \ | 173 | #define ZORBA_DECIMAL_OP(OP) \ |
2168 | 182 | friend bool operator OP( Decimal const&, Decimal const& ); \ | 174 | friend bool operator OP( Decimal const&, Decimal const& ); \ |
2169 | 183 | TEMPLATE_DECL(I) \ | 175 | template<class T> \ |
2170 | 184 | friend bool operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \ | 176 | friend bool operator OP( Decimal const&, IntegerImpl<T> const& ); \ |
2171 | 185 | TEMPLATE_DECL(I) \ | 177 | template<class T> \ |
2172 | 186 | friend bool operator OP( INTEGER_IMPL(I) const&, Decimal const& ) | 178 | friend bool operator OP( IntegerImpl<T> const&, Decimal const& ) |
2173 | 187 | 179 | ||
2174 | 188 | ZORBA_DECIMAL_OP(==); | 180 | ZORBA_DECIMAL_OP(==); |
2175 | 189 | ZORBA_DECIMAL_OP(!=); | 181 | ZORBA_DECIMAL_OP(!=); |
2176 | @@ -201,11 +193,11 @@ | |||
2177 | 201 | Decimal floor() const; | 193 | Decimal floor() const; |
2178 | 202 | Decimal round() const; | 194 | Decimal round() const; |
2179 | 203 | 195 | ||
2182 | 204 | TEMPLATE_DECL(I) | 196 | template<class T> |
2183 | 205 | Decimal round( INTEGER_IMPL(I) const &precision ) const; | 197 | Decimal round( IntegerImpl<T> const &precision ) const; |
2184 | 206 | 198 | ||
2187 | 207 | TEMPLATE_DECL(I) | 199 | template<class T> |
2188 | 208 | Decimal roundHalfToEven( INTEGER_IMPL(I) const &precision ) const; | 200 | Decimal roundHalfToEven( IntegerImpl<T> const &precision ) const; |
2189 | 209 | 201 | ||
2190 | 210 | Decimal sqrt() const; | 202 | Decimal sqrt() const; |
2191 | 211 | 203 | ||
2192 | @@ -223,9 +215,6 @@ | |||
2193 | 223 | 215 | ||
2194 | 224 | zstring toString( int precision = ZORBA_FLOAT_POINT_PRECISION ) const; | 216 | zstring toString( int precision = ZORBA_FLOAT_POINT_PRECISION ) const; |
2195 | 225 | 217 | ||
2196 | 226 | static Decimal const& one(); | ||
2197 | 227 | static Decimal const& zero(); | ||
2198 | 228 | |||
2199 | 229 | ///////////////////////////////////////////////////////////////////////////// | 218 | ///////////////////////////////////////////////////////////////////////////// |
2200 | 230 | 219 | ||
2201 | 231 | private: | 220 | private: |
2202 | @@ -254,13 +243,15 @@ | |||
2203 | 254 | static value_type roundHalfToEven2( value_type const &v, | 243 | static value_type roundHalfToEven2( value_type const &v, |
2204 | 255 | value_type const &precision ); | 244 | value_type const &precision ); |
2205 | 256 | 245 | ||
2208 | 257 | static zstring toString( value_type const&, | 246 | static zstring toString( value_type const &value, |
2209 | 258 | int precision = ZORBA_FLOAT_POINT_PRECISION ); | 247 | int precision = ZORBA_FLOAT_POINT_PRECISION ) { |
2210 | 248 | return toString( value, false, precision ); | ||
2211 | 249 | } | ||
2212 | 259 | 250 | ||
2213 | 260 | static zstring toString( value_type const&, bool, | 251 | static zstring toString( value_type const&, bool, |
2214 | 261 | int precision = ZORBA_FLOAT_POINT_PRECISION ); | 252 | int precision = ZORBA_FLOAT_POINT_PRECISION ); |
2215 | 262 | 253 | ||
2217 | 263 | TEMPLATE_DECL(I) friend class IntegerImpl; | 254 | template<class T> friend class IntegerImpl; |
2218 | 264 | template<typename F> friend class FloatImpl; | 255 | template<typename F> friend class FloatImpl; |
2219 | 265 | 256 | ||
2220 | 266 | friend xs_long to_xs_long( Decimal const& ); | 257 | friend xs_long to_xs_long( Decimal const& ); |
2221 | @@ -429,9 +420,6 @@ | |||
2222 | 429 | 420 | ||
2223 | 430 | } // namespace zorba | 421 | } // namespace zorba |
2224 | 431 | 422 | ||
2225 | 432 | #undef TEMPLATE_DECL | ||
2226 | 433 | #undef INTEGER_IMPL | ||
2227 | 434 | |||
2228 | 435 | #endif /* ZORBA_DECIMAL_H */ | 423 | #endif /* ZORBA_DECIMAL_H */ |
2229 | 436 | /* | 424 | /* |
2230 | 437 | * Local variables: | 425 | * Local variables: |
2231 | 438 | 426 | ||
2232 | === modified file 'src/zorbatypes/duration.h' | |||
2233 | --- src/zorbatypes/duration.h 2013-02-07 17:24:36 +0000 | |||
2234 | +++ src/zorbatypes/duration.h 2013-05-08 15:05:31 +0000 | |||
2235 | @@ -18,10 +18,10 @@ | |||
2236 | 18 | #define ZORBA_TYPES_DURATION_H | 18 | #define ZORBA_TYPES_DURATION_H |
2237 | 19 | 19 | ||
2238 | 20 | #include <zorba/config.h> | 20 | #include <zorba/config.h> |
2241 | 21 | #include "zorbatypes/zorbatypes_decl.h" | 21 | #include "zorbatypes_decl.h" |
2240 | 22 | #include "zorbatypes/schema_types.h" | ||
2242 | 23 | 22 | ||
2243 | 24 | #include "util/ascii_util.h" | 23 | #include "util/ascii_util.h" |
2244 | 24 | #include "zorbatypes/zstring.h" | ||
2245 | 25 | 25 | ||
2246 | 26 | namespace zorba | 26 | namespace zorba |
2247 | 27 | { | 27 | { |
2248 | @@ -175,9 +175,9 @@ | |||
2249 | 175 | 175 | ||
2250 | 176 | Duration* operator-(const Duration& d) const; | 176 | Duration* operator-(const Duration& d) const; |
2251 | 177 | 177 | ||
2253 | 178 | Duration* operator*(const xs_double& value) const; | 178 | Duration* operator*(const Double& value) const; |
2254 | 179 | 179 | ||
2256 | 180 | Duration* operator/(const xs_double& value) const; | 180 | Duration* operator/(const Double& value) const; |
2257 | 181 | 181 | ||
2258 | 182 | Decimal operator/(const Duration& d) const; | 182 | Decimal operator/(const Duration& d) const; |
2259 | 183 | 183 | ||
2260 | @@ -195,13 +195,13 @@ | |||
2261 | 195 | 195 | ||
2262 | 196 | virtual long getMinutes() const; | 196 | virtual long getMinutes() const; |
2263 | 197 | 197 | ||
2265 | 198 | virtual xs_decimal getSeconds() const; | 198 | virtual Decimal getSeconds() const; |
2266 | 199 | 199 | ||
2267 | 200 | virtual long getFractionalSeconds() const; | 200 | virtual long getFractionalSeconds() const; |
2268 | 201 | 201 | ||
2269 | 202 | virtual long getIntSeconds() const; | 202 | virtual long getIntSeconds() const; |
2270 | 203 | 203 | ||
2272 | 204 | xs_double getTotalSeconds() const; | 204 | Double getTotalSeconds() const; |
2273 | 205 | 205 | ||
2274 | 206 | long getTotalMilliseconds() const; | 206 | long getTotalMilliseconds() const; |
2275 | 207 | 207 | ||
2276 | 208 | 208 | ||
2277 | === modified file 'src/zorbatypes/floatimpl.cpp' | |||
2278 | --- src/zorbatypes/floatimpl.cpp 2013-04-02 21:31:04 +0000 | |||
2279 | +++ src/zorbatypes/floatimpl.cpp 2013-05-08 15:05:31 +0000 | |||
2280 | @@ -30,16 +30,6 @@ | |||
2281 | 30 | #include "zorbaserialization/serialize_zorba_types.h" | 30 | #include "zorbaserialization/serialize_zorba_types.h" |
2282 | 31 | #include "zorbaserialization/serialize_template_types.h" | 31 | #include "zorbaserialization/serialize_template_types.h" |
2283 | 32 | 32 | ||
2284 | 33 | #ifdef ZORBA_WITH_BIG_INTEGER | ||
2285 | 34 | # define TEMPLATE_DECL(T) /* nothing */ | ||
2286 | 35 | # define INTEGER_IMPL(I) IntegerImpl | ||
2287 | 36 | #else | ||
2288 | 37 | # define TEMPLATE_DECL(T) template<typename T> /* spacer */ | ||
2289 | 38 | # define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */ | ||
2290 | 39 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
2291 | 40 | #define INTEGER_IMPL_LL INTEGER_IMPL(long long) | ||
2292 | 41 | #define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long) | ||
2293 | 42 | |||
2294 | 43 | /////////////////////////////////////////////////////////////////////////////// | 33 | /////////////////////////////////////////////////////////////////////////////// |
2295 | 44 | 34 | ||
2296 | 45 | namespace zorba { | 35 | namespace zorba { |
2297 | @@ -72,8 +62,8 @@ | |||
2298 | 72 | } | 62 | } |
2299 | 73 | } | 63 | } |
2300 | 74 | 64 | ||
2303 | 75 | template<typename FloatType> | 65 | template<typename F> |
2304 | 76 | void FloatImpl<FloatType>::parse( char const *s ) { | 66 | void FloatImpl<F>::parse( char const *s ) { |
2305 | 77 | if ( !*s ) | 67 | if ( !*s ) |
2306 | 78 | throw std::invalid_argument( "empty string" ); | 68 | throw std::invalid_argument( "empty string" ); |
2307 | 79 | 69 | ||
2308 | @@ -151,80 +141,87 @@ | |||
2309 | 151 | 141 | ||
2310 | 152 | ////////// constructors /////////////////////////////////////////////////////// | 142 | ////////// constructors /////////////////////////////////////////////////////// |
2311 | 153 | 143 | ||
2314 | 154 | template<typename FloatType> | 144 | template<typename F> |
2315 | 155 | FloatImpl<FloatType>::FloatImpl( Decimal const &d ) { | 145 | FloatImpl<F>::FloatImpl( Decimal const &d ) { |
2316 | 156 | zstring const temp( d.toString() ); | 146 | zstring const temp( d.toString() ); |
2317 | 157 | parse( temp.c_str() ); | 147 | parse( temp.c_str() ); |
2318 | 158 | } | 148 | } |
2319 | 159 | 149 | ||
2323 | 160 | template<typename FloatType> | 150 | template<typename F> |
2324 | 161 | TEMPLATE_DECL(IntType) | 151 | template<class T> |
2325 | 162 | FloatImpl<FloatType>::FloatImpl( INTEGER_IMPL(IntType) const &i ) { | 152 | FloatImpl<F>::FloatImpl( IntegerImpl<T> const &i ) { |
2326 | 163 | zstring const temp( i.toString() ); | 153 | zstring const temp( i.toString() ); |
2327 | 164 | parse( temp.c_str() ); | 154 | parse( temp.c_str() ); |
2328 | 165 | } | 155 | } |
2329 | 166 | 156 | ||
2333 | 167 | #ifndef ZORBA_WITH_BIG_INTEGER | 157 | template FloatImpl<float>::FloatImpl( Integer const& ); |
2334 | 168 | template FloatImpl<float>::FloatImpl( INTEGER_IMPL_LL const& ); | 158 | template FloatImpl<float>::FloatImpl( NegativeInteger const& ); |
2335 | 169 | template FloatImpl<float>::FloatImpl( INTEGER_IMPL_ULL const& ); | 159 | template FloatImpl<float>::FloatImpl( NonNegativeInteger const& ); |
2336 | 160 | template FloatImpl<float>::FloatImpl( NonPositiveInteger const& ); | ||
2337 | 161 | template FloatImpl<float>::FloatImpl( PositiveInteger const& ); | ||
2338 | 170 | 162 | ||
2342 | 171 | template FloatImpl<double>::FloatImpl( INTEGER_IMPL_LL const& ); | 163 | template FloatImpl<double>::FloatImpl( Integer const& ); |
2343 | 172 | template FloatImpl<double>::FloatImpl( INTEGER_IMPL_ULL const& ); | 164 | template FloatImpl<double>::FloatImpl( NegativeInteger const& ); |
2344 | 173 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 165 | template FloatImpl<double>::FloatImpl( NonNegativeInteger const& ); |
2345 | 166 | template FloatImpl<double>::FloatImpl( NonPositiveInteger const& ); | ||
2346 | 167 | template FloatImpl<double>::FloatImpl( PositiveInteger const& ); | ||
2347 | 174 | 168 | ||
2348 | 175 | ////////// assignment operators /////////////////////////////////////////////// | 169 | ////////// assignment operators /////////////////////////////////////////////// |
2349 | 176 | 170 | ||
2352 | 177 | template<typename FloatType> | 171 | template<typename F> |
2353 | 178 | FloatImpl<FloatType>& FloatImpl<FloatType>::operator=( Decimal const &d ) { | 172 | FloatImpl<F>& FloatImpl<F>::operator=( Decimal const &d ) { |
2354 | 179 | zstring const temp( d.toString() ); | 173 | zstring const temp( d.toString() ); |
2355 | 180 | parse( temp.c_str() ); | 174 | parse( temp.c_str() ); |
2356 | 181 | return *this; | 175 | return *this; |
2357 | 182 | } | 176 | } |
2358 | 183 | 177 | ||
2363 | 184 | template<typename FloatType> | 178 | template<typename F> |
2364 | 185 | TEMPLATE_DECL(IntType) | 179 | template<class T> |
2365 | 186 | FloatImpl<FloatType>& | 180 | FloatImpl<F>& FloatImpl<F>::operator=( IntegerImpl<T> const &i ) { |
2362 | 187 | FloatImpl<FloatType>::operator=( INTEGER_IMPL(IntType) const &i ) { | ||
2366 | 188 | zstring const temp( i.toString() ); | 181 | zstring const temp( i.toString() ); |
2367 | 189 | parse( temp.c_str() ); | 182 | parse( temp.c_str() ); |
2368 | 190 | return *this; | 183 | return *this; |
2369 | 191 | } | 184 | } |
2370 | 192 | 185 | ||
2384 | 193 | #ifndef ZORBA_WITH_BIG_INTEGER | 186 | #define ZORBA_INSTANTIATE(F,I) \ |
2385 | 194 | template | 187 | template FloatImpl<F>& FloatImpl<F>::operator=( I const& ) |
2386 | 195 | FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_LL const& ); | 188 | |
2387 | 196 | 189 | ZORBA_INSTANTIATE(float,Integer); | |
2388 | 197 | template | 190 | ZORBA_INSTANTIATE(float,NegativeInteger); |
2389 | 198 | FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_ULL const& ); | 191 | ZORBA_INSTANTIATE(float,NonNegativeInteger); |
2390 | 199 | 192 | ZORBA_INSTANTIATE(float,NonPositiveInteger); | |
2391 | 200 | template | 193 | ZORBA_INSTANTIATE(float,PositiveInteger); |
2392 | 201 | FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_LL const& ); | 194 | |
2393 | 202 | 195 | ZORBA_INSTANTIATE(double,Integer); | |
2394 | 203 | template | 196 | ZORBA_INSTANTIATE(double,NegativeInteger); |
2395 | 204 | FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_ULL const& ); | 197 | ZORBA_INSTANTIATE(double,NonNegativeInteger); |
2396 | 205 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 198 | ZORBA_INSTANTIATE(double,NonPositiveInteger); |
2397 | 199 | ZORBA_INSTANTIATE(double,PositiveInteger); | ||
2398 | 200 | #undef ZORBA_INSTANTIATE | ||
2399 | 206 | 201 | ||
2400 | 207 | ////////// math functions ///////////////////////////////////////////////////// | 202 | ////////// math functions ///////////////////////////////////////////////////// |
2401 | 208 | 203 | ||
2405 | 209 | template<typename FloatType> | 204 | template<typename F> |
2406 | 210 | FloatImpl<FloatType> FloatImpl<FloatType>::acos() const { | 205 | FloatImpl<F> FloatImpl<F>::acos() const { |
2407 | 211 | if ( *this < neg_one() || *this > one() ) | 206 | if ( *this < numeric_consts<FloatImpl>::neg_one() || |
2408 | 207 | *this > numeric_consts<FloatImpl>::one() ) | ||
2409 | 212 | return nan(); | 208 | return nan(); |
2412 | 213 | return FloatImpl<FloatType>( | 209 | return FloatImpl<F>( |
2413 | 214 | isNegZero() ? -std::acos( value_ ): std::acos( value_ ) | 210 | isNegZero() ? -std::acos( value_ ) : std::acos( value_ ) |
2414 | 215 | ); | 211 | ); |
2415 | 216 | } | 212 | } |
2416 | 217 | 213 | ||
2420 | 218 | template<typename FloatType> | 214 | template<typename F> |
2421 | 219 | FloatImpl<FloatType> FloatImpl<FloatType>::asin() const { | 215 | FloatImpl<F> FloatImpl<F>::asin() const { |
2422 | 220 | if ( *this < neg_one() || *this > one() ) | 216 | if ( *this < numeric_consts<FloatImpl>::neg_one() || |
2423 | 217 | *this > numeric_consts<FloatImpl>::one() ) | ||
2424 | 221 | return nan(); | 218 | return nan(); |
2426 | 222 | return FloatImpl<FloatType>( std::asin( value_ ) ); | 219 | return FloatImpl<F>( std::asin( value_ ) ); |
2427 | 223 | } | 220 | } |
2428 | 224 | 221 | ||
2432 | 225 | template<typename FloatType> | 222 | template<typename F> |
2433 | 226 | void FloatImpl<FloatType>::frexp( FloatImpl<FloatType> &out_mantissa, | 223 | void FloatImpl<F>::frexp( FloatImpl<F> &out_mantissa, |
2434 | 227 | Integer &out_exponent ) const { | 224 | Integer &out_exponent ) const { |
2435 | 228 | int expint; | 225 | int expint; |
2436 | 229 | out_mantissa = FloatImpl( ::frexp( value_, &expint ) ); | 226 | out_mantissa = FloatImpl( ::frexp( value_, &expint ) ); |
2437 | 230 | out_exponent = Integer( expint ); | 227 | out_exponent = Integer( expint ); |
2438 | @@ -246,13 +243,13 @@ | |||
2439 | 246 | out_integer = int_part; | 243 | out_integer = int_part; |
2440 | 247 | } | 244 | } |
2441 | 248 | 245 | ||
2445 | 249 | template<typename FloatType> | 246 | template<typename F> |
2446 | 250 | FloatImpl<FloatType> FloatImpl<FloatType>::round() const { | 247 | FloatImpl<F> FloatImpl<F>::round() const { |
2447 | 251 | return round( Integer::zero() ); | 248 | return round( numeric_consts<xs_integer>::zero() ); |
2448 | 252 | } | 249 | } |
2449 | 253 | 250 | ||
2452 | 254 | template<typename FloatType> | 251 | template<typename F> |
2453 | 255 | FloatImpl<FloatType> FloatImpl<FloatType>::round( Integer const &precision ) const { | 252 | FloatImpl<F> FloatImpl<F>::round( Integer const &precision ) const { |
2454 | 256 | FloatImpl result; | 253 | FloatImpl result; |
2455 | 257 | if ( isFinite() && !isZero() ) { | 254 | if ( isFinite() && !isZero() ) { |
2456 | 258 | MAPM m( | 255 | MAPM m( |
2457 | @@ -274,8 +271,8 @@ | |||
2458 | 274 | return result; | 271 | return result; |
2459 | 275 | } | 272 | } |
2460 | 276 | 273 | ||
2463 | 277 | template<typename FloatType> FloatImpl<FloatType> | 274 | template<typename F> |
2464 | 278 | FloatImpl<FloatType>::roundHalfToEven( Integer const &precision) const { | 275 | FloatImpl<F> FloatImpl<F>::roundHalfToEven( Integer const &precision ) const { |
2465 | 279 | FloatImpl result; | 276 | FloatImpl result; |
2466 | 280 | if ( isFinite() && !isZero() ) { | 277 | if ( isFinite() && !isZero() ) { |
2467 | 281 | MAPM m( | 278 | MAPM m( |
2468 | @@ -318,48 +315,32 @@ | |||
2469 | 318 | return false; | 315 | return false; |
2470 | 319 | } | 316 | } |
2471 | 320 | 317 | ||
2514 | 321 | template<typename FloatType> | 318 | template<typename F> |
2515 | 322 | FloatImpl<FloatType> const& FloatImpl<FloatType>::nan() { | 319 | FloatImpl<F> const& FloatImpl<F>::nan() { |
2516 | 323 | static FloatImpl<FloatType> const value( std::sqrt( -1.0 ) ); | 320 | static FloatImpl<F> const value( std::sqrt( -1.0 ) ); |
2517 | 324 | return value; | 321 | return value; |
2518 | 325 | } | 322 | } |
2519 | 326 | 323 | ||
2520 | 327 | template<typename FloatType> | 324 | template<typename F> |
2521 | 328 | FloatImpl<FloatType> const& FloatImpl<FloatType>::neg_inf() { | 325 | FloatImpl<F> const& FloatImpl<F>::neg_inf() { |
2522 | 329 | static FloatImpl<FloatType> const value( | 326 | static FloatImpl<F> const value( -std::numeric_limits<F>::infinity() ); |
2523 | 330 | -std::numeric_limits<FloatType>::infinity() | 327 | return value; |
2524 | 331 | ); | 328 | } |
2525 | 332 | return value; | 329 | |
2526 | 333 | } | 330 | template<typename F> |
2527 | 334 | 331 | FloatImpl<F> const& FloatImpl<F>::neg_zero() { | |
2528 | 335 | template<typename FloatType> | 332 | static FloatImpl<F> const value( -0.0 ); |
2529 | 336 | FloatImpl<FloatType> const& FloatImpl<FloatType>::neg_one() { | 333 | return value; |
2530 | 337 | static FloatImpl<FloatType> const value( -1 ); | 334 | } |
2531 | 338 | return value; | 335 | |
2532 | 339 | } | 336 | template<typename F> |
2533 | 340 | 337 | FloatImpl<F> const& FloatImpl<F>::pos_inf() { | |
2534 | 341 | template<typename FloatType> | 338 | static FloatImpl<F> const value( std::numeric_limits<F>::infinity() ); |
2535 | 342 | FloatImpl<FloatType> const& FloatImpl<FloatType>::neg_zero() { | 339 | return value; |
2536 | 343 | static FloatImpl<FloatType> const value( -0.0 ); | 340 | } |
2537 | 344 | return value; | 341 | |
2538 | 345 | } | 342 | template<typename F> |
2539 | 346 | 343 | zstring FloatImpl<F>::toIntegerString() const { | |
2498 | 347 | template<typename FloatType> | ||
2499 | 348 | FloatImpl<FloatType> const& FloatImpl<FloatType>::one() { | ||
2500 | 349 | static FloatImpl<FloatType> const value( 1 ); | ||
2501 | 350 | return value; | ||
2502 | 351 | } | ||
2503 | 352 | |||
2504 | 353 | template<typename FloatType> | ||
2505 | 354 | FloatImpl<FloatType> const& FloatImpl<FloatType>::pos_inf() { | ||
2506 | 355 | static FloatImpl<FloatType> const value( | ||
2507 | 356 | std::numeric_limits<FloatType>::infinity() | ||
2508 | 357 | ); | ||
2509 | 358 | return value; | ||
2510 | 359 | } | ||
2511 | 360 | |||
2512 | 361 | template<typename FloatType> | ||
2513 | 362 | zstring FloatImpl<FloatType>::toIntegerString() const { | ||
2540 | 363 | if ( isNaN() ) | 344 | if ( isNaN() ) |
2541 | 364 | return nan_str(); | 345 | return nan_str(); |
2542 | 365 | if (isPosInf() ) | 346 | if (isPosInf() ) |
2543 | @@ -377,8 +358,8 @@ | |||
2544 | 377 | return buf; | 358 | return buf; |
2545 | 378 | } | 359 | } |
2546 | 379 | 360 | ||
2549 | 380 | template<typename FloatType> | 361 | template<typename F> |
2550 | 381 | zstring FloatImpl<FloatType>::toString( bool no_scientific_format ) const { | 362 | zstring FloatImpl<F>::toString( bool no_scientific_format ) const { |
2551 | 382 | if ( isNaN() ) | 363 | if ( isNaN() ) |
2552 | 383 | return nan_str(); | 364 | return nan_str(); |
2553 | 384 | if ( isPosInf() ) | 365 | if ( isPosInf() ) |
2554 | @@ -390,17 +371,17 @@ | |||
2555 | 390 | if ( isNegZero() ) | 371 | if ( isNegZero() ) |
2556 | 391 | return "-0"; | 372 | return "-0"; |
2557 | 392 | 373 | ||
2560 | 393 | FloatType const absVal = fabs( value_ ); | 374 | value_type const abs_val = fabs( value_ ); |
2561 | 394 | FloatType const lower = 0.000001f, upper = 1000000.0f; | 375 | value_type const lower = 0.000001f, upper = 1000000.0f; |
2562 | 395 | 376 | ||
2565 | 396 | if (no_scientific_format || (absVal < upper && absVal >= lower) || absVal == 0) | 377 | if ( no_scientific_format || (abs_val >= lower && abs_val < upper) || |
2566 | 397 | { | 378 | abs_val == 0 ) { |
2567 | 398 | #if 1 | 379 | #if 1 |
2568 | 399 | // This is the "spec" implementation, i.e., it is an exact application of | 380 | // This is the "spec" implementation, i.e., it is an exact application of |
2569 | 400 | // the spec in http://www.w3.org/TR/xpath-functions/#casting | 381 | // the spec in http://www.w3.org/TR/xpath-functions/#casting |
2570 | 401 | MAPM decimal_mapm( value_ ); | 382 | MAPM decimal_mapm( value_ ); |
2571 | 402 | decimal_mapm = decimal_mapm.round( precision_ ); | 383 | decimal_mapm = decimal_mapm.round( precision_ ); |
2573 | 403 | return Decimal::toString(decimal_mapm, isNegZero(), max_precision()); | 384 | return Decimal::toString( decimal_mapm, isNegZero(), max_precision() ); |
2574 | 404 | #else | 385 | #else |
2575 | 405 | std::stringstream stream; | 386 | std::stringstream stream; |
2576 | 406 | stream.precision(7); | 387 | stream.precision(7); |
2577 | @@ -471,12 +452,6 @@ | |||
2578 | 471 | } | 452 | } |
2579 | 472 | } | 453 | } |
2580 | 473 | 454 | ||
2581 | 474 | template<typename FloatType> | ||
2582 | 475 | FloatImpl<FloatType> const& FloatImpl<FloatType>::zero() { | ||
2583 | 476 | static FloatImpl<FloatType> const value( 0 ); | ||
2584 | 477 | return value; | ||
2585 | 478 | } | ||
2586 | 479 | |||
2587 | 480 | /////////////////////////////////////////////////////////////////////////////// | 455 | /////////////////////////////////////////////////////////////////////////////// |
2588 | 481 | 456 | ||
2589 | 482 | template class FloatImpl<double>; | 457 | template class FloatImpl<double>; |
2590 | 483 | 458 | ||
2591 | === modified file 'src/zorbatypes/floatimpl.h' | |||
2592 | --- src/zorbatypes/floatimpl.h 2013-04-09 01:29:36 +0000 | |||
2593 | +++ src/zorbatypes/floatimpl.h 2013-05-08 15:05:31 +0000 | |||
2594 | @@ -29,14 +29,6 @@ | |||
2595 | 29 | #include "schema_types.h" | 29 | #include "schema_types.h" |
2596 | 30 | #include "zorbatypes_decl.h" | 30 | #include "zorbatypes_decl.h" |
2597 | 31 | 31 | ||
2598 | 32 | #ifdef ZORBA_WITH_BIG_INTEGER | ||
2599 | 33 | # define TEMPLATE_DECL(I) /* nothing */ | ||
2600 | 34 | # define INTEGER_IMPL(I) IntegerImpl | ||
2601 | 35 | #else | ||
2602 | 36 | # define TEMPLATE_DECL(I) template<typename I> /* spacer */ | ||
2603 | 37 | # define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */ | ||
2604 | 38 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
2605 | 39 | |||
2606 | 40 | namespace zorba { | 32 | namespace zorba { |
2607 | 41 | 33 | ||
2608 | 42 | template<typename FloatType> | 34 | template<typename FloatType> |
2609 | @@ -71,8 +63,8 @@ | |||
2610 | 71 | explicit FloatImpl( double n ); | 63 | explicit FloatImpl( double n ); |
2611 | 72 | explicit FloatImpl( Decimal const &d ); | 64 | explicit FloatImpl( Decimal const &d ); |
2612 | 73 | 65 | ||
2615 | 74 | TEMPLATE_DECL(IntType) | 66 | template<class T> |
2616 | 75 | explicit FloatImpl( INTEGER_IMPL(IntType) const &i ); | 67 | explicit FloatImpl( IntegerImpl<T> const &i ); |
2617 | 76 | 68 | ||
2618 | 77 | /** | 69 | /** |
2619 | 78 | * Constructs a %FloatImpl from a C string. | 70 | * Constructs a %FloatImpl from a C string. |
2620 | @@ -126,8 +118,8 @@ | |||
2621 | 126 | FloatImpl& operator=( char const *s ); | 118 | FloatImpl& operator=( char const *s ); |
2622 | 127 | FloatImpl& operator=( Decimal const &d ); | 119 | FloatImpl& operator=( Decimal const &d ); |
2623 | 128 | 120 | ||
2626 | 129 | TEMPLATE_DECL(I) | 121 | template<class T> |
2627 | 130 | FloatImpl& operator=( INTEGER_IMPL(I) const &i ); | 122 | FloatImpl& operator=( IntegerImpl<T> const &i ); |
2628 | 131 | 123 | ||
2629 | 132 | ////////// arithmetic operators ///////////////////////////////////////////// | 124 | ////////// arithmetic operators ///////////////////////////////////////////// |
2630 | 133 | 125 | ||
2631 | @@ -269,11 +261,9 @@ | |||
2632 | 269 | bool isPosZero() const; | 261 | bool isPosZero() const; |
2633 | 270 | bool isNegZero() const; | 262 | bool isNegZero() const; |
2634 | 271 | bool isInteger() const; | 263 | bool isInteger() const; |
2635 | 264 | int sign() const; | ||
2636 | 272 | 265 | ||
2637 | 273 | static FloatImpl const& zero(); | ||
2638 | 274 | static FloatImpl const& neg_zero(); | 266 | static FloatImpl const& neg_zero(); |
2639 | 275 | static FloatImpl const& one(); | ||
2640 | 276 | static FloatImpl const& neg_one(); | ||
2641 | 277 | static FloatImpl const& nan(); | 267 | static FloatImpl const& nan(); |
2642 | 278 | static FloatImpl const& pos_inf(); | 268 | static FloatImpl const& pos_inf(); |
2643 | 279 | static FloatImpl const& neg_inf(); | 269 | static FloatImpl const& neg_inf(); |
2644 | @@ -283,7 +273,6 @@ | |||
2645 | 283 | } | 273 | } |
2646 | 284 | 274 | ||
2647 | 285 | zstring toIntegerString() const; | 275 | zstring toIntegerString() const; |
2648 | 286 | |||
2649 | 287 | zstring toString( bool no_scientific_mode = false ) const; | 276 | zstring toString( bool no_scientific_mode = false ) const; |
2650 | 288 | 277 | ||
2651 | 289 | ///////////////////////////////////////////////////////////////////////////// | 278 | ///////////////////////////////////////////////////////////////////////////// |
2652 | @@ -298,14 +287,12 @@ | |||
2653 | 298 | value_type value_; | 287 | value_type value_; |
2654 | 299 | precision_type precision_; | 288 | precision_type precision_; |
2655 | 300 | 289 | ||
2656 | 301 | FloatImpl( value_type v, precision_type p ); | ||
2657 | 302 | |||
2658 | 303 | static precision_type max_precision(); | 290 | static precision_type max_precision(); |
2659 | 304 | 291 | ||
2660 | 305 | void parse( char const* ); | 292 | void parse( char const* ); |
2661 | 306 | bool parse_etc( char const* ); | 293 | bool parse_etc( char const* ); |
2662 | 307 | 294 | ||
2664 | 308 | TEMPLATE_DECL(I) friend class IntegerImpl; | 295 | template<class T> friend class IntegerImpl; |
2665 | 309 | friend class Decimal; | 296 | friend class Decimal; |
2666 | 310 | 297 | ||
2667 | 311 | friend class FloatImpl<float>; | 298 | friend class FloatImpl<float>; |
2668 | @@ -412,24 +399,19 @@ | |||
2669 | 412 | parse( s ); | 399 | parse( s ); |
2670 | 413 | } | 400 | } |
2671 | 414 | 401 | ||
2673 | 415 | template<typename F> template<typename G> | 402 | template<typename F> |
2674 | 403 | template<typename G> | ||
2675 | 416 | inline FloatImpl<F>::FloatImpl( FloatImpl<G> const &f ) : | 404 | inline FloatImpl<F>::FloatImpl( FloatImpl<G> const &f ) : |
2676 | 417 | value_( static_cast<F>( f.value_ ) ), precision_( max_precision() ) | 405 | value_( static_cast<F>( f.value_ ) ), precision_( max_precision() ) |
2677 | 418 | { | 406 | { |
2678 | 419 | } | 407 | } |
2679 | 420 | 408 | ||
2680 | 421 | template<typename F> | ||
2681 | 422 | inline FloatImpl<F>::FloatImpl( value_type v, precision_type p ) : | ||
2682 | 423 | value_( v ), precision_( p ) | ||
2683 | 424 | { | ||
2684 | 425 | } | ||
2685 | 426 | |||
2686 | 427 | ////////// assignment operators /////////////////////////////////////////////// | 409 | ////////// assignment operators /////////////////////////////////////////////// |
2687 | 428 | 410 | ||
2689 | 429 | template<typename F> template<typename G> | 411 | template<typename F> |
2690 | 412 | template<typename G> | ||
2691 | 430 | inline FloatImpl<F>& FloatImpl<F>::operator=( FloatImpl<G> const &f ) { | 413 | inline FloatImpl<F>& FloatImpl<F>::operator=( FloatImpl<G> const &f ) { |
2692 | 431 | value_ = static_cast<F>( f.value_ ); | 414 | value_ = static_cast<F>( f.value_ ); |
2693 | 432 | precision_ = max_precision(); | ||
2694 | 433 | return *this; | 415 | return *this; |
2695 | 434 | } | 416 | } |
2696 | 435 | 417 | ||
2697 | @@ -437,7 +419,6 @@ | |||
2698 | 437 | template<typename F> \ | 419 | template<typename F> \ |
2699 | 438 | inline FloatImpl<F>& FloatImpl<F>::operator=( T n ) { \ | 420 | inline FloatImpl<F>& FloatImpl<F>::operator=( T n ) { \ |
2700 | 439 | value_ = static_cast<F>( n ); \ | 421 | value_ = static_cast<F>( n ); \ |
2701 | 440 | precision_ = max_precision(); \ | ||
2702 | 441 | return *this; \ | 422 | return *this; \ |
2703 | 442 | } | 423 | } |
2704 | 443 | 424 | ||
2705 | @@ -668,7 +649,8 @@ | |||
2706 | 668 | ZORBA_FLOAT_OP(/=) | 649 | ZORBA_FLOAT_OP(/=) |
2707 | 669 | #undef ZORBA_FLOAT_OP | 650 | #undef ZORBA_FLOAT_OP |
2708 | 670 | 651 | ||
2710 | 671 | template<typename F> template<typename G> | 652 | template<typename F> |
2711 | 653 | template<typename G> | ||
2712 | 672 | inline FloatImpl<F>& FloatImpl<F>::operator%=( FloatImpl<G> const &f ) { | 654 | inline FloatImpl<F>& FloatImpl<F>::operator%=( FloatImpl<G> const &f ) { |
2713 | 673 | value_ = std::fmod( value_, static_cast<F>( f.value_ ) ); | 655 | value_ = std::fmod( value_, static_cast<F>( f.value_ ) ); |
2714 | 674 | return *this; | 656 | return *this; |
2715 | @@ -676,7 +658,7 @@ | |||
2716 | 676 | 658 | ||
2717 | 677 | template<typename F> | 659 | template<typename F> |
2718 | 678 | inline FloatImpl<F> FloatImpl<F>::operator-() const { | 660 | inline FloatImpl<F> FloatImpl<F>::operator-() const { |
2720 | 679 | return FloatImpl<F>( -value_, precision_ ); | 661 | return FloatImpl<F>( -value_ ); |
2721 | 680 | } | 662 | } |
2722 | 681 | 663 | ||
2723 | 682 | #define ZORBA_FLOAT_OP(OP) \ | 664 | #define ZORBA_FLOAT_OP(OP) \ |
2724 | @@ -932,7 +914,8 @@ | |||
2725 | 932 | 914 | ||
2726 | 933 | ////////// miscellaneous ////////////////////////////////////////////////////// | 915 | ////////// miscellaneous ////////////////////////////////////////////////////// |
2727 | 934 | 916 | ||
2729 | 935 | template<typename F> template<typename G> | 917 | template<typename F> |
2730 | 918 | template<typename G> | ||
2731 | 936 | inline int FloatImpl<F>::compare( FloatImpl<G> const &f ) const { | 919 | inline int FloatImpl<F>::compare( FloatImpl<G> const &f ) const { |
2732 | 937 | return value_ < f.value_ ? -1 : value_ > f.value_ ? 1 : 0; | 920 | return value_ < f.value_ ? -1 : value_ > f.value_ ? 1 : 0; |
2733 | 938 | } | 921 | } |
2734 | @@ -987,12 +970,17 @@ | |||
2735 | 987 | return isFinite() && ::floor( value_ ) == value_; | 970 | return isFinite() && ::floor( value_ ) == value_; |
2736 | 988 | } | 971 | } |
2737 | 989 | 972 | ||
2739 | 990 | template <typename F> | 973 | template<typename F> |
2740 | 991 | inline bool FloatImpl<F>::isZero() const { | 974 | inline bool FloatImpl<F>::isZero() const { |
2741 | 992 | return value_ == 0; | 975 | return value_ == 0; |
2742 | 993 | } | 976 | } |
2743 | 994 | 977 | ||
2744 | 995 | template<typename F> | 978 | template<typename F> |
2745 | 979 | inline int FloatImpl<F>::sign() const { | ||
2746 | 980 | return value_ > 0 ? 1 : value_ < 0 ? -1 : 0; | ||
2747 | 981 | } | ||
2748 | 982 | |||
2749 | 983 | template<typename F> | ||
2750 | 996 | inline std::ostream& operator<<( std::ostream &os, FloatImpl<F> const &f ) { | 984 | inline std::ostream& operator<<( std::ostream &os, FloatImpl<F> const &f ) { |
2751 | 997 | return os << f.toString(); | 985 | return os << f.toString(); |
2752 | 998 | } | 986 | } |
2753 | @@ -1001,9 +989,6 @@ | |||
2754 | 1001 | 989 | ||
2755 | 1002 | } // namespace zorba | 990 | } // namespace zorba |
2756 | 1003 | 991 | ||
2757 | 1004 | #undef TEMPLATE_DECL | ||
2758 | 1005 | #undef INTEGER_IMPL | ||
2759 | 1006 | |||
2760 | 1007 | #endif // ZORBA_FLOATIMPL_H | 992 | #endif // ZORBA_FLOATIMPL_H |
2761 | 1008 | /* | 993 | /* |
2762 | 1009 | * Local variables: | 994 | * Local variables: |
2763 | 1010 | 995 | ||
2764 | === modified file 'src/zorbatypes/integer.cpp' | |||
2765 | --- src/zorbatypes/integer.cpp 2013-04-09 22:38:19 +0000 | |||
2766 | +++ src/zorbatypes/integer.cpp 2013-05-08 15:05:31 +0000 | |||
2767 | @@ -16,166 +16,185 @@ | |||
2768 | 16 | 16 | ||
2769 | 17 | #include "stdafx.h" | 17 | #include "stdafx.h" |
2770 | 18 | 18 | ||
2771 | 19 | // standard | ||
2772 | 19 | #include <cerrno> | 20 | #include <cerrno> |
2773 | 20 | #include <cstdlib> | 21 | #include <cstdlib> |
2774 | 22 | #include <sstream> | ||
2775 | 21 | 23 | ||
2776 | 24 | // Zorba | ||
2777 | 22 | #include <zorba/internal/unique_ptr.h> | 25 | #include <zorba/internal/unique_ptr.h> |
2778 | 23 | #include "util/cxx_util.h" | 26 | #include "util/cxx_util.h" |
2779 | 24 | #include "util/string_util.h" | 27 | #include "util/string_util.h" |
2780 | 25 | 28 | ||
2782 | 26 | #include "integer.h" | 29 | // local |
2783 | 27 | #include "decimal.h" | 30 | #include "decimal.h" |
2784 | 28 | #include "floatimpl.h" | 31 | #include "floatimpl.h" |
2785 | 32 | #include "integer.h" | ||
2786 | 29 | #include "numconversions.h" | 33 | #include "numconversions.h" |
2787 | 30 | 34 | ||
2788 | 31 | #ifdef ZORBA_WITH_BIG_INTEGER | ||
2789 | 32 | # define TEMPLATE_DECL(T) /* nothing */ | ||
2790 | 33 | # define INTEGER_IMPL(T) IntegerImpl | ||
2791 | 34 | #else | ||
2792 | 35 | # define TEMPLATE_DECL(T) template<typename T> /* spacer */ | ||
2793 | 36 | # define INTEGER_IMPL(T) IntegerImpl<T> /* spacer */ | ||
2794 | 37 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
2795 | 38 | #define INTEGER_IMPL_LL INTEGER_IMPL(long long) | ||
2796 | 39 | #define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long) | ||
2797 | 40 | |||
2798 | 41 | using namespace std; | 35 | using namespace std; |
2799 | 42 | 36 | ||
2800 | 43 | #ifndef ZORBA_WITH_BIG_INTEGER | ||
2801 | 44 | unsigned long long MaxUIntegerValue = ~0ull >> 1; | ||
2802 | 45 | |||
2803 | 46 | inline bool is_too_big( long long ) { | ||
2804 | 47 | return false; | ||
2805 | 48 | } | ||
2806 | 49 | |||
2807 | 50 | inline bool is_too_big( unsigned long long n ) { | ||
2808 | 51 | return n > MaxUIntegerValue; | ||
2809 | 52 | } | ||
2810 | 53 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
2811 | 54 | |||
2812 | 55 | namespace zorba { | 37 | namespace zorba { |
2813 | 56 | 38 | ||
2814 | 57 | /////////////////////////////////////////////////////////////////////////////// | 39 | /////////////////////////////////////////////////////////////////////////////// |
2815 | 58 | 40 | ||
2818 | 59 | TEMPLATE_DECL(I) | 41 | ostream& operator<<( ostream &o, MAPM const &m ) { |
2819 | 60 | void INTEGER_IMPL(I)::parse( char const *s ) { | 42 | unique_ptr<char[]> const buf( new char[ m.exponent() + 3 ] ); |
2820 | 43 | m.toIntegerString( buf.get() ); | ||
2821 | 44 | return o << buf.get(); | ||
2822 | 45 | } | ||
2823 | 46 | |||
2824 | 47 | void integer_traits::throw_error( string const &what, bool throw_range_error ) { | ||
2825 | 48 | if ( throw_range_error ) | ||
2826 | 49 | throw range_error( what ); | ||
2827 | 50 | throw invalid_argument( what ); | ||
2828 | 51 | } | ||
2829 | 52 | |||
2830 | 53 | void integer_traits::throw_error( MAPM const &n, char const *op, | ||
2831 | 54 | bool throw_range_error ) { | ||
2832 | 55 | ostringstream oss; | ||
2833 | 56 | oss << n; | ||
2834 | 57 | string const what( BUILD_STRING( oss.str(), ": not ", op, " 0" ) ); | ||
2835 | 58 | throw_error( what, throw_range_error ); | ||
2836 | 59 | } | ||
2837 | 60 | |||
2838 | 61 | /////////////////////////////////////////////////////////////////////////////// | ||
2839 | 62 | |||
2840 | 63 | template<class T> | ||
2841 | 64 | void IntegerImpl<T>::parse( char const *s, bool throw_range_error ) { | ||
2842 | 61 | #ifdef ZORBA_WITH_BIG_INTEGER | 65 | #ifdef ZORBA_WITH_BIG_INTEGER |
2843 | 62 | Decimal::parse( s, &value_, Decimal::parse_integer ); | 66 | Decimal::parse( s, &value_, Decimal::parse_integer ); |
2844 | 63 | #else | 67 | #else |
2851 | 64 | value_type const temp( ztd::aton<value_type>( s ) ); | 68 | try { |
2852 | 65 | if ( is_too_big( temp ) ) | 69 | value_ = ztd::aton<value_type>( s ); |
2853 | 66 | throw std::invalid_argument( | 70 | } |
2854 | 67 | BUILD_STRING( '"', temp, "\": unsigned integer too big" ) | 71 | catch ( std::range_error const &e ) { |
2855 | 68 | ); | 72 | if ( throw_range_error ) |
2856 | 69 | value_ = temp; | 73 | throw; |
2857 | 74 | throw invalid_argument( e.what() ); | ||
2858 | 75 | } | ||
2859 | 70 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 76 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
2860 | 77 | T::check_value( value_, throw_range_error ); | ||
2861 | 71 | } | 78 | } |
2862 | 72 | 79 | ||
2863 | 73 | ////////// constructors /////////////////////////////////////////////////////// | 80 | ////////// constructors /////////////////////////////////////////////////////// |
2864 | 74 | 81 | ||
2865 | 75 | #ifdef ZORBA_WITH_BIG_INTEGER | 82 | #ifdef ZORBA_WITH_BIG_INTEGER |
2867 | 76 | IntegerImpl::IntegerImpl( long long n ) { | 83 | template<class T> |
2868 | 84 | IntegerImpl<T>::IntegerImpl( long long n ) { | ||
2869 | 77 | ascii::itoa_buf_type buf; | 85 | ascii::itoa_buf_type buf; |
2870 | 78 | value_ = ascii::itoa( n, buf ); | 86 | value_ = ascii::itoa( n, buf ); |
2871 | 87 | T::check_value( value_, false ); | ||
2872 | 79 | } | 88 | } |
2873 | 80 | 89 | ||
2874 | 81 | #if ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG | 90 | #if ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG |
2877 | 82 | TEMPLATE_DECL(T) | 91 | template<class T> |
2878 | 83 | INTEGER_IMPL(T)::IntegerImpl( unsigned int n ) { | 92 | IntegerImpl<T>::IntegerImpl( unsigned int n ) { |
2879 | 84 | ascii::itoa_buf_type buf; | 93 | ascii::itoa_buf_type buf; |
2880 | 85 | value_ = ascii::itoa( n, buf ); | 94 | value_ = ascii::itoa( n, buf ); |
2881 | 95 | T::check_value( value_, false ); | ||
2882 | 86 | } | 96 | } |
2883 | 87 | #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */ | 97 | #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */ |
2884 | 88 | 98 | ||
2886 | 89 | IntegerImpl::IntegerImpl( unsigned long n ) { | 99 | template<class T> |
2887 | 100 | IntegerImpl<T>::IntegerImpl( unsigned long n ) { | ||
2888 | 90 | ascii::itoa_buf_type buf; | 101 | ascii::itoa_buf_type buf; |
2889 | 91 | value_ = ascii::itoa( n, buf ); | 102 | value_ = ascii::itoa( n, buf ); |
2890 | 103 | T::check_value( value_, false ); | ||
2891 | 92 | } | 104 | } |
2892 | 93 | 105 | ||
2894 | 94 | IntegerImpl::IntegerImpl( unsigned long long n ) { | 106 | template<class T> |
2895 | 107 | IntegerImpl<T>::IntegerImpl( unsigned long long n ) { | ||
2896 | 95 | ascii::itoa_buf_type buf; | 108 | ascii::itoa_buf_type buf; |
2897 | 96 | value_ = ascii::itoa( n, buf ); | 109 | value_ = ascii::itoa( n, buf ); |
2898 | 110 | T::check_value( value_, false ); | ||
2899 | 97 | } | 111 | } |
2900 | 98 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 112 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
2901 | 99 | 113 | ||
2905 | 100 | TEMPLATE_DECL(T) | 114 | template<class T> |
2906 | 101 | INTEGER_IMPL(T)::IntegerImpl( Decimal const &d ) { | 115 | IntegerImpl<T>::IntegerImpl( Decimal const &d ) { |
2907 | 102 | value_ = ftoi( d.value_ ); | 116 | value_ = T::check_value( ftoi( d.value_ ), false ); |
2908 | 103 | } | 117 | } |
2909 | 104 | 118 | ||
2912 | 105 | TEMPLATE_DECL(T) | 119 | template<class T> |
2913 | 106 | INTEGER_IMPL(T)::IntegerImpl( Double const &d ) { | 120 | IntegerImpl<T>::IntegerImpl( Double const &d ) { |
2914 | 107 | if ( !d.isFinite() ) | 121 | if ( !d.isFinite() ) |
2915 | 108 | throw std::invalid_argument( "not finite" ); | 122 | throw std::invalid_argument( "not finite" ); |
2917 | 109 | value_ = ftoi( d.getNumber() ); | 123 | value_ = T::check_value( ftoi( d.getNumber() ), false ); |
2918 | 110 | } | 124 | } |
2919 | 111 | 125 | ||
2922 | 112 | TEMPLATE_DECL(T) | 126 | template<class T> |
2923 | 113 | INTEGER_IMPL(T)::IntegerImpl( Float const &f ) { | 127 | IntegerImpl<T>::IntegerImpl( Float const &f ) { |
2924 | 114 | if ( !f.isFinite() ) | 128 | if ( !f.isFinite() ) |
2925 | 115 | throw std::invalid_argument( "not finite" ); | 129 | throw std::invalid_argument( "not finite" ); |
2927 | 116 | value_ = ftoi( f.getNumber() ); | 130 | value_ = T::check_value( ftoi( f.getNumber() ), false ); |
2928 | 117 | } | 131 | } |
2929 | 118 | 132 | ||
2930 | 119 | ////////// assignment operators /////////////////////////////////////////////// | 133 | ////////// assignment operators /////////////////////////////////////////////// |
2931 | 120 | 134 | ||
2932 | 121 | #ifdef ZORBA_WITH_BIG_INTEGER | 135 | #ifdef ZORBA_WITH_BIG_INTEGER |
2948 | 122 | IntegerImpl& IntegerImpl::operator=( long long n ) { | 136 | template<class T> |
2949 | 123 | ascii::itoa_buf_type buf; | 137 | IntegerImpl<T>& IntegerImpl<T>::operator=( long long n ) { |
2950 | 124 | value_ = ascii::itoa( n, buf ); | 138 | ascii::itoa_buf_type buf; |
2951 | 125 | return *this; | 139 | value_ = ascii::itoa( n, buf ); |
2952 | 126 | } | 140 | T::check_value( value_, true ); |
2953 | 127 | 141 | return *this; | |
2954 | 128 | IntegerImpl& IntegerImpl::operator=( unsigned long n ) { | 142 | } |
2955 | 129 | ascii::itoa_buf_type buf; | 143 | |
2956 | 130 | value_ = ascii::itoa( n, buf ); | 144 | template<class T> |
2957 | 131 | return *this; | 145 | IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long n ) { |
2958 | 132 | } | 146 | ascii::itoa_buf_type buf; |
2959 | 133 | 147 | value_ = ascii::itoa( n, buf ); | |
2960 | 134 | IntegerImpl& IntegerImpl::operator=( unsigned long long n ) { | 148 | T::check_value( value_, true ); |
2961 | 135 | ascii::itoa_buf_type buf; | 149 | return *this; |
2962 | 136 | value_ = ascii::itoa( n, buf ); | 150 | } |
2963 | 151 | |||
2964 | 152 | template<class T> | ||
2965 | 153 | IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long long n ) { | ||
2966 | 154 | ascii::itoa_buf_type buf; | ||
2967 | 155 | value_ = ascii::itoa( n, buf ); | ||
2968 | 156 | T::check_value( value_, true ); | ||
2969 | 137 | return *this; | 157 | return *this; |
2970 | 138 | } | 158 | } |
2971 | 139 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 159 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
2972 | 140 | 160 | ||
2976 | 141 | TEMPLATE_DECL(T) | 161 | template<class T> |
2977 | 142 | INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Decimal const &d ) { | 162 | IntegerImpl<T>& IntegerImpl<T>::operator=( Decimal const &d ) { |
2978 | 143 | value_ = ftoi( d.value_ ); | 163 | value_ = T::check_value( ftoi( d.value_ ), true ); |
2979 | 144 | return *this; | 164 | return *this; |
2980 | 145 | } | 165 | } |
2981 | 146 | 166 | ||
2984 | 147 | TEMPLATE_DECL(T) | 167 | template<class T> |
2985 | 148 | INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Double const &d ) { | 168 | IntegerImpl<T>& IntegerImpl<T>::operator=( Double const &d ) { |
2986 | 149 | if ( !d.isFinite() ) | 169 | if ( !d.isFinite() ) |
2987 | 150 | throw std::invalid_argument( "not finite" ); | 170 | throw std::invalid_argument( "not finite" ); |
2989 | 151 | value_ = ftoi( d.getNumber() ); | 171 | value_ = T::check_value( ftoi( d.getNumber() ), true ); |
2990 | 152 | return *this; | 172 | return *this; |
2991 | 153 | } | 173 | } |
2992 | 154 | 174 | ||
2995 | 155 | TEMPLATE_DECL(T) | 175 | template<class T> |
2996 | 156 | INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Float const &f ) { | 176 | IntegerImpl<T>& IntegerImpl<T>::operator=( Float const &f ) { |
2997 | 157 | if ( !f.isFinite() ) | 177 | if ( !f.isFinite() ) |
2998 | 158 | throw std::invalid_argument( "not finite" ); | 178 | throw std::invalid_argument( "not finite" ); |
3000 | 159 | value_ = ftoi( f.getNumber() ); | 179 | value_ = T::check_value( ftoi( f.getNumber() ), true ); |
3001 | 160 | return *this; | 180 | return *this; |
3002 | 161 | } | 181 | } |
3003 | 162 | 182 | ||
3004 | 163 | ////////// arithmetic operators /////////////////////////////////////////////// | 183 | ////////// arithmetic operators /////////////////////////////////////////////// |
3005 | 164 | 184 | ||
3013 | 165 | #ifdef ZORBA_WITH_BIG_INTEGER | 185 | #define ZORBA_INSTANTIATE(OP,I) \ |
3014 | 166 | # define ZORBA_INSTANTIATE(OP) /* nothing */ | 186 | template Decimal operator OP( I const&, Decimal const& ); |
3008 | 167 | #else | ||
3009 | 168 | # define ZORBA_INSTANTIATE(OP) \ | ||
3010 | 169 | template Decimal operator OP( INTEGER_IMPL_LL const&, Decimal const& ); \ | ||
3011 | 170 | template Decimal operator OP( INTEGER_IMPL_ULL const&, Decimal const& ); | ||
3012 | 171 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
3015 | 172 | 187 | ||
3016 | 173 | #define ZORBA_INTEGER_OP(OP) \ | 188 | #define ZORBA_INTEGER_OP(OP) \ |
3019 | 174 | TEMPLATE_DECL(T) \ | 189 | template<class T> \ |
3020 | 175 | Decimal operator OP( INTEGER_IMPL(T) const &i, Decimal const &d ) { \ | 190 | Decimal operator OP( IntegerImpl<T> const &i, Decimal const &d ) { \ |
3021 | 176 | return i.itod() OP d.value_; \ | 191 | return i.itod() OP d.value_; \ |
3022 | 177 | } \ | 192 | } \ |
3024 | 178 | ZORBA_INSTANTIATE(OP) | 193 | ZORBA_INSTANTIATE( OP, Integer ); \ |
3025 | 194 | ZORBA_INSTANTIATE( OP, NegativeInteger ); \ | ||
3026 | 195 | ZORBA_INSTANTIATE( OP, NonNegativeInteger ); \ | ||
3027 | 196 | ZORBA_INSTANTIATE( OP, NonPositiveInteger ); \ | ||
3028 | 197 | ZORBA_INSTANTIATE( OP, PositiveInteger ); | ||
3029 | 179 | 198 | ||
3030 | 180 | ZORBA_INTEGER_OP(+) | 199 | ZORBA_INTEGER_OP(+) |
3031 | 181 | ZORBA_INTEGER_OP(-) | 200 | ZORBA_INTEGER_OP(-) |
3032 | @@ -187,15 +206,26 @@ | |||
3033 | 187 | 206 | ||
3034 | 188 | #ifdef ZORBA_WITH_BIG_INTEGER | 207 | #ifdef ZORBA_WITH_BIG_INTEGER |
3035 | 189 | 208 | ||
3045 | 190 | #define ZORBA_INTEGER_OP(OP,T) \ | 209 | #define ZORBA_INSTANTIATE(OP,I,N) \ |
3046 | 191 | IntegerImpl operator OP( IntegerImpl const &i, T n ) { \ | 210 | template Integer operator OP( I const&, N ); \ |
3047 | 192 | ascii::itoa_buf_type buf; \ | 211 | template Integer operator OP( N, I const& ) |
3048 | 193 | return i.value_ OP IntegerImpl::value_type( ascii::itoa( n, buf ) ); \ | 212 | |
3049 | 194 | } \ | 213 | #define ZORBA_INTEGER_OP(OP,N) \ |
3050 | 195 | IntegerImpl operator OP( T n, IntegerImpl const &i ) { \ | 214 | template<class T> \ |
3051 | 196 | ascii::itoa_buf_type buf; \ | 215 | Integer operator OP( IntegerImpl<T> const &i, N n ) { \ |
3052 | 197 | return IntegerImpl::value_type( ascii::itoa( n, buf ) ) OP i.value_; \ | 216 | ascii::itoa_buf_type buf; \ |
3053 | 198 | } | 217 | return i.value_ OP MAPM( ascii::itoa( n, buf ) ); \ |
3054 | 218 | } \ | ||
3055 | 219 | template<class T> \ | ||
3056 | 220 | Integer operator OP( N n, IntegerImpl<T> const &i ) { \ | ||
3057 | 221 | ascii::itoa_buf_type buf; \ | ||
3058 | 222 | return MAPM( ascii::itoa( n, buf ) ) OP i.value_; \ | ||
3059 | 223 | } \ | ||
3060 | 224 | ZORBA_INSTANTIATE( OP, Integer, N ); \ | ||
3061 | 225 | ZORBA_INSTANTIATE( OP, NegativeInteger, N ); \ | ||
3062 | 226 | ZORBA_INSTANTIATE( OP, NonNegativeInteger, N ); \ | ||
3063 | 227 | ZORBA_INSTANTIATE( OP, NonPositiveInteger, N ); \ | ||
3064 | 228 | ZORBA_INSTANTIATE( OP, PositiveInteger, N ); | ||
3065 | 199 | 229 | ||
3066 | 200 | ZORBA_INTEGER_OP(+,long long) | 230 | ZORBA_INTEGER_OP(+,long long) |
3067 | 201 | ZORBA_INTEGER_OP(-,long long) | 231 | ZORBA_INTEGER_OP(-,long long) |
3068 | @@ -210,30 +240,44 @@ | |||
3069 | 210 | ZORBA_INTEGER_OP(*,unsigned long long) | 240 | ZORBA_INTEGER_OP(*,unsigned long long) |
3070 | 211 | ZORBA_INTEGER_OP(%,unsigned long long) | 241 | ZORBA_INTEGER_OP(%,unsigned long long) |
3071 | 212 | #undef ZORBA_INTEGER_OP | 242 | #undef ZORBA_INTEGER_OP |
3084 | 213 | 243 | #undef ZORBA_INSTANTIATE | |
3085 | 214 | #define ZORBA_INTEGER_OP(T) \ | 244 | |
3086 | 215 | IntegerImpl operator/( IntegerImpl const &i, T n ) { \ | 245 | #define ZORBA_INSTANTIATE(I,N) \ |
3087 | 216 | ascii::itoa_buf_type buf; \ | 246 | template Integer operator/( I const&, N ); \ |
3088 | 217 | IntegerImpl::value_type const temp( ascii::itoa( n, buf ) ); \ | 247 | template Integer operator/( N, I const& ) |
3089 | 218 | return IntegerImpl::ftoi( i.value_ / temp ); \ | 248 | |
3090 | 219 | } \ | 249 | #define ZORBA_INTEGER_OP(N) \ |
3091 | 220 | IntegerImpl operator/( T n, IntegerImpl const &i ) { \ | 250 | template<class T> \ |
3092 | 221 | ascii::itoa_buf_type buf; \ | 251 | Integer operator/( IntegerImpl<T> const &i, N n ) { \ |
3093 | 222 | IntegerImpl::value_type const temp( ascii::itoa( n, buf ) ); \ | 252 | ascii::itoa_buf_type buf; \ |
3094 | 223 | return IntegerImpl::ftoi( temp / i.value_ ); \ | 253 | MAPM const temp( ascii::itoa( n, buf ) ); \ |
3095 | 224 | } | 254 | return Integer::ftoi( i.value_ / temp ); \ |
3096 | 255 | } \ | ||
3097 | 256 | template<class T> \ | ||
3098 | 257 | Integer operator/( N n, IntegerImpl<T> const &i ) { \ | ||
3099 | 258 | ascii::itoa_buf_type buf; \ | ||
3100 | 259 | MAPM const temp( ascii::itoa( n, buf ) ); \ | ||
3101 | 260 | return Integer::ftoi( temp / i.value_ ); \ | ||
3102 | 261 | } \ | ||
3103 | 262 | ZORBA_INSTANTIATE( Integer, N ); \ | ||
3104 | 263 | ZORBA_INSTANTIATE( NegativeInteger, N ); \ | ||
3105 | 264 | ZORBA_INSTANTIATE( NonNegativeInteger, N ); \ | ||
3106 | 265 | ZORBA_INSTANTIATE( NonPositiveInteger, N ); \ | ||
3107 | 266 | ZORBA_INSTANTIATE( PositiveInteger, N ); | ||
3108 | 225 | 267 | ||
3109 | 226 | ZORBA_INTEGER_OP(long long) | 268 | ZORBA_INTEGER_OP(long long) |
3110 | 227 | ZORBA_INTEGER_OP(unsigned long) | 269 | ZORBA_INTEGER_OP(unsigned long) |
3111 | 228 | ZORBA_INTEGER_OP(unsigned long long) | 270 | ZORBA_INTEGER_OP(unsigned long long) |
3112 | 229 | #undef ZORBA_INTEGER_OP | 271 | #undef ZORBA_INTEGER_OP |
3113 | 272 | #undef ZORBA_INSTANTIATE | ||
3114 | 230 | 273 | ||
3121 | 231 | #define ZORBA_INTEGER_OP(OP,T) \ | 274 | #define ZORBA_INTEGER_OP(OP,N) \ |
3122 | 232 | IntegerImpl& IntegerImpl::operator OP( T n ) { \ | 275 | template<class T> \ |
3123 | 233 | ascii::itoa_buf_type buf; \ | 276 | IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \ |
3124 | 234 | value_type const temp( ascii::itoa( n, buf ) ); \ | 277 | ascii::itoa_buf_type buf; \ |
3125 | 235 | value_ OP temp; \ | 278 | value_type const temp( ascii::itoa( n, buf ) ); \ |
3126 | 236 | return *this; \ | 279 | T::check_value( value_ OP temp, true ); \ |
3127 | 280 | return *this; \ | ||
3128 | 237 | } | 281 | } |
3129 | 238 | 282 | ||
3130 | 239 | ZORBA_INTEGER_OP(+=,long long) | 283 | ZORBA_INTEGER_OP(+=,long long) |
3131 | @@ -250,12 +294,13 @@ | |||
3132 | 250 | ZORBA_INTEGER_OP(%=,unsigned long long) | 294 | ZORBA_INTEGER_OP(%=,unsigned long long) |
3133 | 251 | #undef ZORBA_INTEGER_OP | 295 | #undef ZORBA_INTEGER_OP |
3134 | 252 | 296 | ||
3141 | 253 | #define ZORBA_INTEGER_OP(T) \ | 297 | #define ZORBA_INTEGER_OP(N) \ |
3142 | 254 | IntegerImpl& IntegerImpl::operator/=( T n ) { \ | 298 | template<class T> \ |
3143 | 255 | ascii::itoa_buf_type buf; \ | 299 | IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \ |
3144 | 256 | value_type const temp( ascii::itoa( n, buf ) ); \ | 300 | ascii::itoa_buf_type buf; \ |
3145 | 257 | value_ = ftoi( value_ / temp ); \ | 301 | value_type const temp( ascii::itoa( n, buf ) ); \ |
3146 | 258 | return *this; \ | 302 | T::check_value( value_ = ftoi( value_ / temp ), true ); \ |
3147 | 303 | return *this; \ | ||
3148 | 259 | } | 304 | } |
3149 | 260 | 305 | ||
3150 | 261 | ZORBA_INTEGER_OP(long long) | 306 | ZORBA_INTEGER_OP(long long) |
3151 | @@ -266,36 +311,63 @@ | |||
3152 | 266 | 311 | ||
3153 | 267 | ////////// relational operators /////////////////////////////////////////////// | 312 | ////////// relational operators /////////////////////////////////////////////// |
3154 | 268 | 313 | ||
3157 | 269 | TEMPLATE_DECL(T) | 314 | #define ZORBA_INSTANTIATE(OP,I) \ |
3158 | 270 | bool operator==( INTEGER_IMPL(T) const &i, Decimal const &d ) { | 315 | template bool operator OP( I const&, Decimal const& ) |
3159 | 316 | |||
3160 | 317 | template<class T> | ||
3161 | 318 | bool operator==( IntegerImpl<T> const &i, Decimal const &d ) { | ||
3162 | 271 | return d.is_xs_integer() && i.itod() == d.value_; | 319 | return d.is_xs_integer() && i.itod() == d.value_; |
3163 | 272 | } | 320 | } |
3164 | 273 | 321 | ||
3170 | 274 | #define ZORBA_INTEGER_OP(OP) \ | 322 | ZORBA_INSTANTIATE( ==, Integer ); |
3171 | 275 | TEMPLATE_DECL(T) \ | 323 | ZORBA_INSTANTIATE( ==, NegativeInteger ); |
3172 | 276 | bool operator OP( INTEGER_IMPL(T) const &i, Decimal const &d ) { \ | 324 | ZORBA_INSTANTIATE( ==, NonNegativeInteger ); |
3173 | 277 | return i.itod() OP d.value_; \ | 325 | ZORBA_INSTANTIATE( ==, NonPositiveInteger ); |
3174 | 278 | } | 326 | ZORBA_INSTANTIATE( ==, PositiveInteger ); |
3175 | 327 | |||
3176 | 328 | #define ZORBA_INTEGER_OP(OP) \ | ||
3177 | 329 | template<class T> \ | ||
3178 | 330 | bool operator OP( IntegerImpl<T> const &i, Decimal const &d ) { \ | ||
3179 | 331 | return i.itod() OP d.value_; \ | ||
3180 | 332 | } \ | ||
3181 | 333 | ZORBA_INSTANTIATE( OP, Integer ); \ | ||
3182 | 334 | ZORBA_INSTANTIATE( OP, NegativeInteger ); \ | ||
3183 | 335 | ZORBA_INSTANTIATE( OP, NonNegativeInteger ); \ | ||
3184 | 336 | ZORBA_INSTANTIATE( OP, NonPositiveInteger ); \ | ||
3185 | 337 | ZORBA_INSTANTIATE( OP, PositiveInteger ); | ||
3186 | 279 | 338 | ||
3187 | 280 | ZORBA_INTEGER_OP(!=) | 339 | ZORBA_INTEGER_OP(!=) |
3188 | 281 | ZORBA_INTEGER_OP(< ) | 340 | ZORBA_INTEGER_OP(< ) |
3189 | 282 | ZORBA_INTEGER_OP(<=) | 341 | ZORBA_INTEGER_OP(<=) |
3190 | 283 | ZORBA_INTEGER_OP(> ) | 342 | ZORBA_INTEGER_OP(> ) |
3191 | 284 | ZORBA_INTEGER_OP(>=) | 343 | ZORBA_INTEGER_OP(>=) |
3192 | 344 | #undef ZORBA_INSTANTIATE | ||
3193 | 285 | #undef ZORBA_INTEGER_OP | 345 | #undef ZORBA_INTEGER_OP |
3194 | 286 | 346 | ||
3195 | 287 | #ifdef ZORBA_WITH_BIG_INTEGER | 347 | #ifdef ZORBA_WITH_BIG_INTEGER |
3196 | 288 | 348 | ||
3207 | 289 | #define ZORBA_INTEGER_OP(OP,T) \ | 349 | #define ZORBA_INSTANTIATE(OP,I,N) \ |
3208 | 290 | bool operator OP( IntegerImpl const &i, T n ) { \ | 350 | template bool operator OP( I const&, N ); \ |
3209 | 291 | ascii::itoa_buf_type buf; \ | 351 | template bool operator OP( N, I const& ) |
3210 | 292 | return i.value_ OP IntegerImpl::value_type( ascii::itoa( n, buf ) ); \ | 352 | |
3211 | 293 | } \ | 353 | #define ZORBA_INTEGER_OP(OP,N) \ |
3212 | 294 | \ | 354 | template<class T> \ |
3213 | 295 | bool operator OP( T n, IntegerImpl const &i ) { \ | 355 | bool operator OP( IntegerImpl<T> const &i, N n ) { \ |
3214 | 296 | ascii::itoa_buf_type buf; \ | 356 | ascii::itoa_buf_type buf; \ |
3215 | 297 | return IntegerImpl::value_type( ascii::itoa( n, buf ) ) OP i.value_; \ | 357 | return i.value_ OP MAPM( ascii::itoa( n, buf ) ); \ |
3216 | 298 | } | 358 | } \ |
3217 | 359 | \ | ||
3218 | 360 | template<class T> \ | ||
3219 | 361 | bool operator OP( N n, IntegerImpl<T> const &i ) { \ | ||
3220 | 362 | ascii::itoa_buf_type buf; \ | ||
3221 | 363 | return MAPM( ascii::itoa( n, buf ) ) OP i.value_; \ | ||
3222 | 364 | } \ | ||
3223 | 365 | \ | ||
3224 | 366 | ZORBA_INSTANTIATE( OP, Integer, N ); \ | ||
3225 | 367 | ZORBA_INSTANTIATE( OP, NegativeInteger, N ); \ | ||
3226 | 368 | ZORBA_INSTANTIATE( OP, NonNegativeInteger, N ); \ | ||
3227 | 369 | ZORBA_INSTANTIATE( OP, NonPositiveInteger, N ); \ | ||
3228 | 370 | ZORBA_INSTANTIATE( OP, PositiveInteger, N ); | ||
3229 | 299 | 371 | ||
3230 | 300 | ZORBA_INTEGER_OP(==,long long) | 372 | ZORBA_INTEGER_OP(==,long long) |
3231 | 301 | ZORBA_INTEGER_OP(!=,long long) | 373 | ZORBA_INTEGER_OP(!=,long long) |
3232 | @@ -315,27 +387,14 @@ | |||
3233 | 315 | ZORBA_INTEGER_OP(<=,unsigned long long) | 387 | ZORBA_INTEGER_OP(<=,unsigned long long) |
3234 | 316 | ZORBA_INTEGER_OP(> ,unsigned long long) | 388 | ZORBA_INTEGER_OP(> ,unsigned long long) |
3235 | 317 | ZORBA_INTEGER_OP(>=,unsigned long long) | 389 | ZORBA_INTEGER_OP(>=,unsigned long long) |
3236 | 318 | |||
3237 | 319 | #else /* ZORBA_WITH_BIG_INTEGER */ | ||
3238 | 320 | |||
3239 | 321 | #define ZORBA_INSTANTIATE(OP) \ | ||
3240 | 322 | template bool operator OP( INTEGER_IMPL_LL const&, Decimal const& ); \ | ||
3241 | 323 | template bool operator OP( INTEGER_IMPL_ULL const&, Decimal const& ) | ||
3242 | 324 | |||
3243 | 325 | ZORBA_INSTANTIATE(==); | ||
3244 | 326 | ZORBA_INSTANTIATE(!=); | ||
3245 | 327 | ZORBA_INSTANTIATE(< ); | ||
3246 | 328 | ZORBA_INSTANTIATE(<=); | ||
3247 | 329 | ZORBA_INSTANTIATE(> ); | ||
3248 | 330 | ZORBA_INSTANTIATE(>=); | ||
3249 | 331 | #undef ZORBA_INSTANTIATE | 390 | #undef ZORBA_INSTANTIATE |
3250 | 332 | 391 | ||
3251 | 333 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 392 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3252 | 334 | 393 | ||
3253 | 335 | ////////// math functions ///////////////////////////////////////////////////// | 394 | ////////// math functions ///////////////////////////////////////////////////// |
3254 | 336 | 395 | ||
3257 | 337 | TEMPLATE_DECL(T) | 396 | template<class T> |
3258 | 338 | Double INTEGER_IMPL(T)::pow( INTEGER_IMPL(T) const &power ) const { | 397 | Double IntegerImpl<T>::pow( IntegerImpl<T> const &power ) const { |
3259 | 339 | #ifdef ZORBA_WITH_BIG_INTEGER | 398 | #ifdef ZORBA_WITH_BIG_INTEGER |
3260 | 340 | value_type const result( value_.pow( power.value_, 15 ) ); | 399 | value_type const result( value_.pow( power.value_, 15 ) ); |
3261 | 341 | char buf[300]; | 400 | char buf[300]; |
3262 | @@ -349,30 +408,30 @@ | |||
3263 | 349 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 408 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3264 | 350 | } | 409 | } |
3265 | 351 | 410 | ||
3268 | 352 | TEMPLATE_DECL(T) | 411 | template<class T> |
3269 | 353 | INTEGER_IMPL(T) INTEGER_IMPL(T)::round( IntegerImpl const &precision ) const { | 412 | IntegerImpl<T> IntegerImpl<T>::round( IntegerImpl<T> const &precision ) const { |
3270 | 354 | return IntegerImpl( Decimal::round2( itod(), precision.itod() ) ); | 413 | return IntegerImpl( Decimal::round2( itod(), precision.itod() ) ); |
3271 | 355 | } | 414 | } |
3272 | 356 | 415 | ||
3276 | 357 | TEMPLATE_DECL(T) | 416 | template<class T> |
3277 | 358 | INTEGER_IMPL(T) | 417 | IntegerImpl<T> |
3278 | 359 | INTEGER_IMPL(T)::roundHalfToEven( IntegerImpl const &precision ) const { | 418 | IntegerImpl<T>::roundHalfToEven( IntegerImpl const &precision ) const { |
3279 | 360 | return IntegerImpl( Decimal::roundHalfToEven2( itod(), precision.itod() ) ); | 419 | return IntegerImpl( Decimal::roundHalfToEven2( itod(), precision.itod() ) ); |
3280 | 361 | } | 420 | } |
3281 | 362 | 421 | ||
3282 | 363 | ////////// miscellaneous ////////////////////////////////////////////////////// | 422 | ////////// miscellaneous ////////////////////////////////////////////////////// |
3283 | 364 | 423 | ||
3284 | 365 | #ifndef ZORBA_WITH_BIG_INTEGER | 424 | #ifndef ZORBA_WITH_BIG_INTEGER |
3287 | 366 | TEMPLATE_DECL(T) | 425 | template<class T> |
3288 | 367 | typename INTEGER_IMPL(T)::value_type INTEGER_IMPL(T)::ftoi( MAPM const &d ) { | 426 | typename IntegerImpl<T>::value_type IntegerImpl<T>::ftoi( MAPM const &d ) { |
3289 | 368 | MAPM const temp( d.sign() >= 0 ? d.floor() : d.ceil() ); | 427 | MAPM const temp( d.sign() >= 0 ? d.floor() : d.ceil() ); |
3290 | 369 | unique_ptr<char[]> const buf( new char[ temp.exponent() + 3 ] ); | 428 | unique_ptr<char[]> const buf( new char[ temp.exponent() + 3 ] ); |
3291 | 370 | temp.toIntegerString( buf.get() ); | 429 | temp.toIntegerString( buf.get() ); |
3292 | 371 | return ztd::aton<value_type>( buf.get() ); | 430 | return ztd::aton<value_type>( buf.get() ); |
3293 | 372 | } | 431 | } |
3294 | 373 | 432 | ||
3297 | 374 | TEMPLATE_DECL(T) | 433 | template<class T> |
3298 | 375 | MAPM INTEGER_IMPL(T)::itod() const { | 434 | MAPM IntegerImpl<T>::itod() const { |
3299 | 376 | if ( is_cxx_long() ) | 435 | if ( is_cxx_long() ) |
3300 | 377 | return static_cast<long>( value_ ); | 436 | return static_cast<long>( value_ ); |
3301 | 378 | ascii::itoa_buf_type buf; | 437 | ascii::itoa_buf_type buf; |
3302 | @@ -381,77 +440,79 @@ | |||
3303 | 381 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 440 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3304 | 382 | 441 | ||
3305 | 383 | #ifdef ZORBA_WITH_BIG_INTEGER | 442 | #ifdef ZORBA_WITH_BIG_INTEGER |
3307 | 384 | size_t IntegerImpl::alloc_size() const { | 443 | |
3308 | 444 | static MAPM xs_byte_min( "-128" ); | ||
3309 | 445 | static MAPM xs_byte_max( "127" ); | ||
3310 | 446 | static MAPM xs_short_min( "-32768" ); | ||
3311 | 447 | static MAPM xs_short_max( "32767" ); | ||
3312 | 448 | static MAPM xs_unsignedByte_max( "256" ); | ||
3313 | 449 | static MAPM xs_unsignedInt_max( "4294967295" ); | ||
3314 | 450 | static MAPM xs_unsignedLong_max( "18446744073709551615" ); | ||
3315 | 451 | static MAPM xs_unsignedShort_max( "65536" ); | ||
3316 | 452 | |||
3317 | 453 | template<class T> | ||
3318 | 454 | size_t IntegerImpl<T>::alloc_size() const { | ||
3319 | 385 | return value_.significant_digits(); | 455 | return value_.significant_digits(); |
3320 | 386 | } | 456 | } |
3321 | 387 | 457 | ||
3323 | 388 | uint32_t IntegerImpl::hash() const { | 458 | template<class T> |
3324 | 459 | uint32_t IntegerImpl<T>::hash() const { | ||
3325 | 389 | return Decimal::hash( value_ ); | 460 | return Decimal::hash( value_ ); |
3326 | 390 | } | 461 | } |
3327 | 391 | 462 | ||
3331 | 392 | bool IntegerImpl::is_xs_byte() const { | 463 | template<class T> |
3332 | 393 | static MAPM xs_byte_min( "-128" ); | 464 | bool IntegerImpl<T>::is_xs_byte() const { |
3330 | 394 | static MAPM xs_byte_max( "127" ); | ||
3333 | 395 | return value_ >= xs_byte_min && value_ <= xs_byte_max; | 465 | return value_ >= xs_byte_min && value_ <= xs_byte_max; |
3334 | 396 | } | 466 | } |
3335 | 397 | 467 | ||
3339 | 398 | bool IntegerImpl::is_xs_short() const { | 468 | template<class T> |
3340 | 399 | static MAPM xs_short_min( "-32768" ); | 469 | bool IntegerImpl<T>::is_xs_short() const { |
3338 | 400 | static MAPM xs_short_max( "32767" ); | ||
3341 | 401 | return value_ >= xs_short_min && value_ <= xs_short_max; | 470 | return value_ >= xs_short_min && value_ <= xs_short_max; |
3342 | 402 | } | 471 | } |
3343 | 403 | 472 | ||
3346 | 404 | bool IntegerImpl::is_xs_unsignedByte() const { | 473 | template<class T> |
3347 | 405 | static MAPM xs_unsignedByte_max( "256" ); | 474 | bool IntegerImpl<T>::is_xs_unsignedByte() const { |
3348 | 406 | return value_.sign() >= 0 && value_ <= xs_unsignedByte_max; | 475 | return value_.sign() >= 0 && value_ <= xs_unsignedByte_max; |
3349 | 407 | } | 476 | } |
3350 | 408 | 477 | ||
3353 | 409 | bool IntegerImpl::is_xs_unsignedInt() const { | 478 | template<class T> |
3354 | 410 | static MAPM xs_unsignedInt_max( "4294967295" ); | 479 | bool IntegerImpl<T>::is_xs_unsignedInt() const { |
3355 | 411 | return value_.sign() >= 0 && value_ <= xs_unsignedInt_max; | 480 | return value_.sign() >= 0 && value_ <= xs_unsignedInt_max; |
3356 | 412 | } | 481 | } |
3357 | 413 | 482 | ||
3360 | 414 | bool IntegerImpl::is_xs_unsignedLong() const { | 483 | template<class T> |
3361 | 415 | static MAPM xs_unsignedLong_max( "18446744073709551615" ); | 484 | bool IntegerImpl<T>::is_xs_unsignedLong() const { |
3362 | 416 | return value_.sign() >= 0 && value_ <= xs_unsignedLong_max; | 485 | return value_.sign() >= 0 && value_ <= xs_unsignedLong_max; |
3363 | 417 | } | 486 | } |
3364 | 418 | 487 | ||
3367 | 419 | bool IntegerImpl::is_xs_unsignedShort() const { | 488 | template<class T> |
3368 | 420 | static MAPM xs_unsignedShort_max( "65536" ); | 489 | bool IntegerImpl<T>::is_xs_unsignedShort() const { |
3369 | 421 | return value_.sign() >= 0 && value_ <= xs_unsignedShort_max; | 490 | return value_.sign() >= 0 && value_ <= xs_unsignedShort_max; |
3370 | 422 | } | 491 | } |
3371 | 423 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 492 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3372 | 424 | 493 | ||
3381 | 425 | TEMPLATE_DECL(T) | 494 | template<class T> |
3382 | 426 | INTEGER_IMPL(T) const& INTEGER_IMPL(T)::one() { | 495 | zstring IntegerImpl<T>::toString() const { |
3375 | 427 | static INTEGER_IMPL(T) const i(1); | ||
3376 | 428 | return i; | ||
3377 | 429 | } | ||
3378 | 430 | |||
3379 | 431 | TEMPLATE_DECL(T) | ||
3380 | 432 | zstring INTEGER_IMPL(T)::toString() const { | ||
3383 | 433 | #ifdef ZORBA_WITH_BIG_INTEGER | 496 | #ifdef ZORBA_WITH_BIG_INTEGER |
3387 | 434 | unique_ptr<char[]> const buf( new char[ value_.exponent() + 3 ] ); | 497 | ostringstream oss; |
3388 | 435 | value_.toIntegerString( buf.get() ); | 498 | oss << value_; |
3389 | 436 | return buf.get(); | 499 | return oss.str(); |
3390 | 437 | #else | 500 | #else |
3391 | 438 | ascii::itoa_buf_type buf; | 501 | ascii::itoa_buf_type buf; |
3392 | 439 | return ascii::itoa( value_, buf ); | 502 | return ascii::itoa( value_, buf ); |
3393 | 440 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 503 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3394 | 441 | } | 504 | } |
3395 | 442 | 505 | ||
3408 | 443 | TEMPLATE_DECL(T) | 506 | /////////////////////////////////////////////////////////////////////////////// |
3409 | 444 | INTEGER_IMPL(T) const& INTEGER_IMPL(T)::zero() { | 507 | |
3410 | 445 | static INTEGER_IMPL(T) const i(0); | 508 | // instantiate integer types |
3411 | 446 | return i; | 509 | template class IntegerImpl<integer_traits>; |
3412 | 447 | } | 510 | template class IntegerImpl<negative_traits>; |
3413 | 448 | 511 | template class IntegerImpl<nonNegative_traits>; | |
3414 | 449 | /////////////////////////////////////////////////////////////////////////////// | 512 | template class IntegerImpl<nonPositive_traits>; |
3415 | 450 | 513 | template class IntegerImpl<positive_traits>; | |
3416 | 451 | #ifndef ZORBA_WITH_BIG_INTEGER | 514 | |
3417 | 452 | template class IntegerImpl<long long>; | 515 | /////////////////////////////////////////////////////////////////////////////// |
3406 | 453 | template class IntegerImpl<unsigned long long>; | ||
3407 | 454 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
3418 | 455 | 516 | ||
3419 | 456 | } // namespace zorba | 517 | } // namespace zorba |
3420 | 457 | /* vim:set et sw=2 ts=2: */ | 518 | /* vim:set et sw=2 ts=2: */ |
3421 | 458 | 519 | ||
3422 | === modified file 'src/zorbatypes/integer.h' | |||
3423 | --- src/zorbatypes/integer.h 2013-02-26 04:12:43 +0000 | |||
3424 | +++ src/zorbatypes/integer.h 2013-05-08 15:05:31 +0000 | |||
3425 | @@ -18,60 +18,142 @@ | |||
3426 | 18 | #ifndef ZORBA_INTEGER_H | 18 | #ifndef ZORBA_INTEGER_H |
3427 | 19 | #define ZORBA_INTEGER_H | 19 | #define ZORBA_INTEGER_H |
3428 | 20 | 20 | ||
3429 | 21 | // standard | ||
3430 | 21 | #include <cmath> | 22 | #include <cmath> |
3431 | 22 | #include <limits> | 23 | #include <limits> |
3432 | 24 | #include <string> | ||
3433 | 23 | 25 | ||
3434 | 26 | // Zorba | ||
3435 | 24 | #include <zorba/config.h> | 27 | #include <zorba/config.h> |
3436 | 25 | |||
3437 | 26 | #include "common/common.h" | 28 | #include "common/common.h" |
3438 | 27 | #include "util/stl_util.h" | 29 | #include "util/stl_util.h" |
3439 | 30 | #include "util/string_util.h" | ||
3440 | 28 | 31 | ||
3441 | 32 | // local | ||
3442 | 29 | #include "m_apm.h" | 33 | #include "m_apm.h" |
3443 | 34 | #include "numeric_types.h" | ||
3444 | 30 | #include "schema_types_base.h" | 35 | #include "schema_types_base.h" |
3445 | 31 | #include "zorbatypes_decl.h" | 36 | #include "zorbatypes_decl.h" |
3446 | 32 | #include "zstring.h" | 37 | #include "zstring.h" |
3447 | 33 | 38 | ||
3448 | 34 | #ifdef ZORBA_WITH_BIG_INTEGER | ||
3449 | 35 | # define TEMPLATE_DECL(I) /* nothing */ | ||
3450 | 36 | # define INTEGER_IMPL(I) IntegerImpl | ||
3451 | 37 | # define TEMPLATE_TYPENAME /* nothing */ | ||
3452 | 38 | #else | ||
3453 | 39 | # define TEMPLATE_DECL(I) template<typename I> /* spacer */ | ||
3454 | 40 | # define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */ | ||
3455 | 41 | # define TEMPLATE_TYPENAME typename | ||
3456 | 42 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
3457 | 43 | #define INTEGER_IMPL_LL INTEGER_IMPL(long long) | ||
3458 | 44 | #define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long) | ||
3459 | 45 | |||
3460 | 46 | namespace zorba { | 39 | namespace zorba { |
3461 | 47 | 40 | ||
3463 | 48 | TEMPLATE_DECL(I) | 41 | template<class TraitsType> |
3464 | 49 | class IntegerImpl; | 42 | class IntegerImpl; |
3465 | 50 | 43 | ||
3468 | 51 | namespace serialization | 44 | namespace serialization { |
3467 | 52 | { | ||
3469 | 53 | class Archiver; | 45 | class Archiver; |
3471 | 54 | TEMPLATE_DECL(I) void operator&( Archiver&, INTEGER_IMPL(I)& ); | 46 | |
3472 | 47 | template<class T> | ||
3473 | 48 | void operator&( Archiver&, IntegerImpl<T>& ); | ||
3474 | 55 | } | 49 | } |
3475 | 56 | 50 | ||
3476 | 57 | /////////////////////////////////////////////////////////////////////////////// | 51 | /////////////////////////////////////////////////////////////////////////////// |
3477 | 58 | 52 | ||
3481 | 59 | TEMPLATE_DECL(IntType) | 53 | std::ostream& operator<<( std::ostream&, MAPM const& ); |
3482 | 60 | class IntegerImpl | 54 | |
3483 | 61 | { | 55 | struct integer_traits { |
3484 | 56 | static int const default_value = 0; | ||
3485 | 57 | |||
3486 | 58 | template<typename ValueType> | ||
3487 | 59 | static ValueType check_value( ValueType n, bool ) { | ||
3488 | 60 | return n; | ||
3489 | 61 | } | ||
3490 | 62 | |||
3491 | 63 | static MAPM const& check_value( MAPM const &n, bool ) { | ||
3492 | 64 | return n; | ||
3493 | 65 | } | ||
3494 | 66 | |||
3495 | 67 | protected: | ||
3496 | 68 | static void throw_error( std::string const&, bool ); | ||
3497 | 69 | |||
3498 | 70 | template<typename ValueType> | ||
3499 | 71 | static void throw_error( ValueType n, char const *op, | ||
3500 | 72 | bool throw_range_error ) { | ||
3501 | 73 | std::string const what( BUILD_STRING( n, ": not ", op, " 0" ) ); | ||
3502 | 74 | throw_error( what, throw_range_error ); | ||
3503 | 75 | } | ||
3504 | 76 | |||
3505 | 77 | static void throw_error( MAPM const &n, char const *op, | ||
3506 | 78 | bool throw_range_error ); | ||
3507 | 79 | }; | ||
3508 | 80 | |||
3509 | 81 | struct nonPositive_traits : integer_traits { | ||
3510 | 82 | template<typename ValueType> | ||
3511 | 83 | static ValueType check_value( ValueType n, bool throw_range_error ) { | ||
3512 | 84 | if ( !ztd::le0( n ) ) | ||
3513 | 85 | throw_error( n, "<=", throw_range_error ); | ||
3514 | 86 | return n; | ||
3515 | 87 | } | ||
3516 | 88 | static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { | ||
3517 | 89 | if ( !(n.sign() <= 0) ) | ||
3518 | 90 | throw_error( n, "<=", throw_range_error ); | ||
3519 | 91 | return n; | ||
3520 | 92 | } | ||
3521 | 93 | }; | ||
3522 | 94 | |||
3523 | 95 | struct negative_traits : nonPositive_traits { | ||
3524 | 96 | static int const default_value = -1; | ||
3525 | 97 | |||
3526 | 98 | template<typename ValueType> | ||
3527 | 99 | static ValueType check_value( ValueType n, bool throw_range_error ) { | ||
3528 | 100 | if ( !ztd::lt0( n ) ) | ||
3529 | 101 | throw_error( n, "<", throw_range_error ); | ||
3530 | 102 | return n; | ||
3531 | 103 | } | ||
3532 | 104 | static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { | ||
3533 | 105 | if ( !(n.sign() < 0) ) | ||
3534 | 106 | throw_error( n, "<", throw_range_error ); | ||
3535 | 107 | return n; | ||
3536 | 108 | } | ||
3537 | 109 | }; | ||
3538 | 110 | |||
3539 | 111 | struct nonNegative_traits : integer_traits { | ||
3540 | 112 | template<typename ValueType> | ||
3541 | 113 | static ValueType check_value( ValueType n, bool throw_range_error ) { | ||
3542 | 114 | if ( !ztd::ge0( n ) ) | ||
3543 | 115 | throw_error( n, ">=", throw_range_error ); | ||
3544 | 116 | return n; | ||
3545 | 117 | } | ||
3546 | 118 | static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { | ||
3547 | 119 | if ( !(n.sign() >= 0) ) | ||
3548 | 120 | throw_error( n, ">=", throw_range_error ); | ||
3549 | 121 | return n; | ||
3550 | 122 | } | ||
3551 | 123 | }; | ||
3552 | 124 | |||
3553 | 125 | struct positive_traits : nonNegative_traits { | ||
3554 | 126 | static int const default_value = 1; | ||
3555 | 127 | |||
3556 | 128 | template<typename ValueType> | ||
3557 | 129 | static ValueType check_value( ValueType n, bool throw_range_error ) { | ||
3558 | 130 | if ( !ztd::gt0( n ) ) | ||
3559 | 131 | throw_error( n, ">", throw_range_error ); | ||
3560 | 132 | return n; | ||
3561 | 133 | } | ||
3562 | 134 | static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { | ||
3563 | 135 | if ( !(n.sign() > 0) ) | ||
3564 | 136 | throw_error( n, ">", throw_range_error ); | ||
3565 | 137 | return n; | ||
3566 | 138 | } | ||
3567 | 139 | }; | ||
3568 | 140 | |||
3569 | 141 | template<class TraitsType> | ||
3570 | 142 | class IntegerImpl { | ||
3571 | 62 | public: | 143 | public: |
3572 | 63 | #ifdef ZORBA_WITH_BIG_INTEGER | 144 | #ifdef ZORBA_WITH_BIG_INTEGER |
3573 | 64 | typedef MAPM value_type; | 145 | typedef MAPM value_type; |
3574 | 65 | #else | 146 | #else |
3576 | 66 | typedef IntType value_type; | 147 | typedef long long value_type; |
3577 | 67 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 148 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3578 | 149 | typedef TraitsType traits_type; | ||
3579 | 68 | 150 | ||
3580 | 69 | ////////// constructors ///////////////////////////////////////////////////// | 151 | ////////// constructors ///////////////////////////////////////////////////// |
3581 | 70 | 152 | ||
3582 | 71 | explicit IntegerImpl( char c ); | 153 | explicit IntegerImpl( char c ); |
3583 | 72 | explicit IntegerImpl( signed char c ); | 154 | explicit IntegerImpl( signed char c ); |
3584 | 73 | explicit IntegerImpl( short n ); | 155 | explicit IntegerImpl( short n ); |
3586 | 74 | explicit IntegerImpl( int n = 0 ); | 156 | explicit IntegerImpl( int n = traits_type::default_value ); |
3587 | 75 | explicit IntegerImpl( long n ); | 157 | explicit IntegerImpl( long n ); |
3588 | 76 | explicit IntegerImpl( long long n ); | 158 | explicit IntegerImpl( long long n ); |
3589 | 77 | explicit IntegerImpl( unsigned char c ); | 159 | explicit IntegerImpl( unsigned char c ); |
3590 | @@ -112,27 +194,27 @@ | |||
3591 | 112 | explicit IntegerImpl( Float const &f ); | 194 | explicit IntegerImpl( Float const &f ); |
3592 | 113 | 195 | ||
3593 | 114 | /** | 196 | /** |
3596 | 115 | * Constructs from another %IntegerImpl even if its \c IntType is different. | 197 | * Constructs from another %IntegerImpl even if its \c TraitsType is |
3597 | 116 | * (This subsumes the conventional copy constructor.) | 198 | * different. (This subsumes the conventional copy constructor.) |
3598 | 117 | * | 199 | * |
3600 | 118 | * @tparam IntType2 the integer type of \a i. | 200 | * @tparam TraitsType2 The traits type of \a i. |
3601 | 119 | * @param i The %IntegerImpl to copy from. | 201 | * @param i The %IntegerImpl to copy from. |
3602 | 120 | */ | 202 | */ |
3605 | 121 | TEMPLATE_DECL(IntType2) | 203 | template<class TraitsType2> |
3606 | 122 | IntegerImpl( INTEGER_IMPL(IntType2) const &i ); | 204 | IntegerImpl( IntegerImpl<TraitsType2> const &i ); |
3607 | 123 | 205 | ||
3608 | 124 | ////////// assignment operators ///////////////////////////////////////////// | 206 | ////////// assignment operators ///////////////////////////////////////////// |
3609 | 125 | 207 | ||
3610 | 126 | /** | 208 | /** |
3612 | 127 | * Assign from an %IntegerImpl even if its \c IntType is different. | 209 | * Assign from an %IntegerImpl even if its \c TraitsType is different. |
3613 | 128 | * (This subsumes the conventional assignment operator.) | 210 | * (This subsumes the conventional assignment operator.) |
3614 | 129 | * | 211 | * |
3616 | 130 | * @tparam IntType2 the integer type of \a i. | 212 | * @tparam TraitsType2 The traits type of \a i. |
3617 | 131 | * @param i The %IntegerImpl to assign from. | 213 | * @param i The %IntegerImpl to assign from. |
3618 | 132 | * @return Returns \c *this. | 214 | * @return Returns \c *this. |
3619 | 133 | */ | 215 | */ |
3622 | 134 | TEMPLATE_DECL(IntType2) | 216 | template<class TraitsType2> |
3623 | 135 | IntegerImpl& operator=( INTEGER_IMPL(IntType2) const &i ); | 217 | IntegerImpl& operator=( IntegerImpl<TraitsType2> const &i ); |
3624 | 136 | 218 | ||
3625 | 137 | IntegerImpl& operator=( char c ); | 219 | IntegerImpl& operator=( char c ); |
3626 | 138 | IntegerImpl& operator=( signed char c ); | 220 | IntegerImpl& operator=( signed char c ); |
3627 | @@ -155,16 +237,15 @@ | |||
3628 | 155 | 237 | ||
3629 | 156 | ////////// arithmetic operators ///////////////////////////////////////////// | 238 | ////////// arithmetic operators ///////////////////////////////////////////// |
3630 | 157 | 239 | ||
3641 | 158 | #define ZORBA_INTEGER_OP(OP) \ | 240 | #define ZORBA_INTEGER_OP(OP) \ |
3642 | 159 | TEMPLATE_DECL(I) friend \ | 241 | template<class T,class U> friend \ |
3643 | 160 | INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const&, \ | 242 | Integer operator OP( IntegerImpl<T> const&, IntegerImpl<U> const& ); \ |
3644 | 161 | INTEGER_IMPL(I) const& ); \ | 243 | \ |
3645 | 162 | \ | 244 | template<class T> friend \ |
3646 | 163 | TEMPLATE_DECL(I) friend \ | 245 | Decimal operator OP( IntegerImpl<T> const&, Decimal const& ); \ |
3647 | 164 | Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \ | 246 | \ |
3648 | 165 | \ | 247 | template<class T> friend \ |
3649 | 166 | TEMPLATE_DECL(I) friend \ | 248 | Decimal operator OP( Decimal const&, IntegerImpl<T> const& ) |
3640 | 167 | Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& ) | ||
3650 | 168 | 249 | ||
3651 | 169 | ZORBA_INTEGER_OP(+); | 250 | ZORBA_INTEGER_OP(+); |
3652 | 170 | ZORBA_INTEGER_OP(-); | 251 | ZORBA_INTEGER_OP(-); |
3653 | @@ -173,12 +254,12 @@ | |||
3654 | 173 | ZORBA_INTEGER_OP(%); | 254 | ZORBA_INTEGER_OP(%); |
3655 | 174 | #undef ZORBA_INTEGER_OP | 255 | #undef ZORBA_INTEGER_OP |
3656 | 175 | 256 | ||
3663 | 176 | #define ZORBA_INTEGER_OP(OP,T) \ | 257 | #define ZORBA_INTEGER_OP(OP,N) \ |
3664 | 177 | TEMPLATE_DECL(I) friend \ | 258 | template<class T> friend \ |
3665 | 178 | INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const&, T ); \ | 259 | Integer operator OP( IntegerImpl<T> const&, N ); \ |
3666 | 179 | \ | 260 | \ |
3667 | 180 | TEMPLATE_DECL(I) friend \ | 261 | template<class T> friend \ |
3668 | 181 | INTEGER_IMPL(I) operator OP( T, INTEGER_IMPL(I) const& ) | 262 | Integer operator OP( N, IntegerImpl<T> const& ) |
3669 | 182 | 263 | ||
3670 | 183 | ZORBA_INTEGER_OP(+,char); | 264 | ZORBA_INTEGER_OP(+,char); |
3671 | 184 | ZORBA_INTEGER_OP(-,char); | 265 | ZORBA_INTEGER_OP(-,char); |
3672 | @@ -247,19 +328,14 @@ | |||
3673 | 247 | ZORBA_INTEGER_OP(%,double); | 328 | ZORBA_INTEGER_OP(%,double); |
3674 | 248 | #undef ZORBA_INTEGER_OP | 329 | #undef ZORBA_INTEGER_OP |
3675 | 249 | 330 | ||
3678 | 250 | #define ZORBA_INTEGER_OP(OP,TYPE) \ | 331 | #define ZORBA_INTEGER_OP(OP,T) \ |
3679 | 251 | IntegerImpl& operator OP( TYPE ) | 332 | IntegerImpl& operator OP( T ) |
3680 | 252 | 333 | ||
3681 | 253 | ZORBA_INTEGER_OP(+=,IntegerImpl const&); | 334 | ZORBA_INTEGER_OP(+=,IntegerImpl const&); |
3682 | 254 | ZORBA_INTEGER_OP(-=,IntegerImpl const&); | 335 | ZORBA_INTEGER_OP(-=,IntegerImpl const&); |
3683 | 255 | ZORBA_INTEGER_OP(*=,IntegerImpl const&); | 336 | ZORBA_INTEGER_OP(*=,IntegerImpl const&); |
3684 | 256 | ZORBA_INTEGER_OP(/=,IntegerImpl const&); | 337 | ZORBA_INTEGER_OP(/=,IntegerImpl const&); |
3685 | 257 | ZORBA_INTEGER_OP(%=,IntegerImpl const&); | 338 | ZORBA_INTEGER_OP(%=,IntegerImpl const&); |
3686 | 258 | #undef ZORBA_INTEGER_OP | ||
3687 | 259 | |||
3688 | 260 | #define ZORBA_INTEGER_OP(OP,T) \ | ||
3689 | 261 | IntegerImpl& operator OP( T ) | ||
3690 | 262 | |||
3691 | 263 | ZORBA_INTEGER_OP(+=,char); | 339 | ZORBA_INTEGER_OP(+=,char); |
3692 | 264 | ZORBA_INTEGER_OP(-=,char); | 340 | ZORBA_INTEGER_OP(-=,char); |
3693 | 265 | ZORBA_INTEGER_OP(*=,char); | 341 | ZORBA_INTEGER_OP(*=,char); |
3694 | @@ -327,7 +403,7 @@ | |||
3695 | 327 | ZORBA_INTEGER_OP(%=,double); | 403 | ZORBA_INTEGER_OP(%=,double); |
3696 | 328 | #undef ZORBA_INTEGER_OP | 404 | #undef ZORBA_INTEGER_OP |
3697 | 329 | 405 | ||
3699 | 330 | IntegerImpl operator-() const; | 406 | Integer operator-() const; |
3700 | 331 | 407 | ||
3701 | 332 | IntegerImpl& operator++(); | 408 | IntegerImpl& operator++(); |
3702 | 333 | IntegerImpl operator++(int); | 409 | IntegerImpl operator++(int); |
3703 | @@ -336,107 +412,107 @@ | |||
3704 | 336 | 412 | ||
3705 | 337 | ////////// relational operators ///////////////////////////////////////////// | 413 | ////////// relational operators ///////////////////////////////////////////// |
3706 | 338 | 414 | ||
3808 | 339 | #define ZORBA_INTEGER_OP(OP) \ | 415 | #define ZORBA_REL_OP(OP) \ |
3809 | 340 | TEMPLATE_DECL(I) friend \ | 416 | template<class T,class U> friend \ |
3810 | 341 | bool operator OP( INTEGER_IMPL(I) const&, INTEGER_IMPL(I) const& ); \ | 417 | bool operator OP( IntegerImpl<T> const&, IntegerImpl<U> const& ); \ |
3811 | 342 | \ | 418 | \ |
3812 | 343 | TEMPLATE_DECL(I) friend \ | 419 | template<class T> friend \ |
3813 | 344 | bool operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \ | 420 | bool operator OP( IntegerImpl<T> const&, Decimal const& ); \ |
3814 | 345 | \ | 421 | \ |
3815 | 346 | TEMPLATE_DECL(I) friend \ | 422 | template<class T> friend \ |
3816 | 347 | bool operator OP( Decimal const&, INTEGER_IMPL(I) const& ) | 423 | bool operator OP( Decimal const&, IntegerImpl<T> const& ) |
3817 | 348 | 424 | ||
3818 | 349 | ZORBA_INTEGER_OP(==); | 425 | ZORBA_REL_OP(==); |
3819 | 350 | ZORBA_INTEGER_OP(!=); | 426 | ZORBA_REL_OP(!=); |
3820 | 351 | ZORBA_INTEGER_OP(< ); | 427 | ZORBA_REL_OP(< ); |
3821 | 352 | ZORBA_INTEGER_OP(<=); | 428 | ZORBA_REL_OP(<=); |
3822 | 353 | ZORBA_INTEGER_OP(> ); | 429 | ZORBA_REL_OP(> ); |
3823 | 354 | ZORBA_INTEGER_OP(>=); | 430 | ZORBA_REL_OP(>=); |
3824 | 355 | #undef ZORBA_INTEGER_OP | 431 | #undef ZORBA_REL_OP |
3825 | 356 | 432 | ||
3826 | 357 | #define ZORBA_INTEGER_OP(OP,T) \ | 433 | #define ZORBA_REL_OP(OP,N) \ |
3827 | 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 ); \ |
3828 | 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& ) |
3829 | 360 | 436 | ||
3830 | 361 | ZORBA_INTEGER_OP(==,char); | 437 | ZORBA_REL_OP(==,char); |
3831 | 362 | ZORBA_INTEGER_OP(!=,char); | 438 | ZORBA_REL_OP(!=,char); |
3832 | 363 | ZORBA_INTEGER_OP(< ,char); | 439 | ZORBA_REL_OP(< ,char); |
3833 | 364 | ZORBA_INTEGER_OP(<=,char); | 440 | ZORBA_REL_OP(<=,char); |
3834 | 365 | ZORBA_INTEGER_OP(> ,char); | 441 | ZORBA_REL_OP(> ,char); |
3835 | 366 | ZORBA_INTEGER_OP(>=,char); | 442 | ZORBA_REL_OP(>=,char); |
3836 | 367 | ZORBA_INTEGER_OP(==,signed char); | 443 | ZORBA_REL_OP(==,signed char); |
3837 | 368 | ZORBA_INTEGER_OP(!=,signed char); | 444 | ZORBA_REL_OP(!=,signed char); |
3838 | 369 | ZORBA_INTEGER_OP(< ,signed char); | 445 | ZORBA_REL_OP(< ,signed char); |
3839 | 370 | ZORBA_INTEGER_OP(<=,signed char); | 446 | ZORBA_REL_OP(<=,signed char); |
3840 | 371 | ZORBA_INTEGER_OP(> ,signed char); | 447 | ZORBA_REL_OP(> ,signed char); |
3841 | 372 | ZORBA_INTEGER_OP(>=,signed char); | 448 | ZORBA_REL_OP(>=,signed char); |
3842 | 373 | ZORBA_INTEGER_OP(==,short); | 449 | ZORBA_REL_OP(==,short); |
3843 | 374 | ZORBA_INTEGER_OP(!=,short); | 450 | ZORBA_REL_OP(!=,short); |
3844 | 375 | ZORBA_INTEGER_OP(< ,short); | 451 | ZORBA_REL_OP(< ,short); |
3845 | 376 | ZORBA_INTEGER_OP(<=,short); | 452 | ZORBA_REL_OP(<=,short); |
3846 | 377 | ZORBA_INTEGER_OP(> ,short); | 453 | ZORBA_REL_OP(> ,short); |
3847 | 378 | ZORBA_INTEGER_OP(>=,short); | 454 | ZORBA_REL_OP(>=,short); |
3848 | 379 | ZORBA_INTEGER_OP(==,int); | 455 | ZORBA_REL_OP(==,int); |
3849 | 380 | ZORBA_INTEGER_OP(!=,int); | 456 | ZORBA_REL_OP(!=,int); |
3850 | 381 | ZORBA_INTEGER_OP(< ,int); | 457 | ZORBA_REL_OP(< ,int); |
3851 | 382 | ZORBA_INTEGER_OP(<=,int); | 458 | ZORBA_REL_OP(<=,int); |
3852 | 383 | ZORBA_INTEGER_OP(> ,int); | 459 | ZORBA_REL_OP(> ,int); |
3853 | 384 | ZORBA_INTEGER_OP(>=,int); | 460 | ZORBA_REL_OP(>=,int); |
3854 | 385 | ZORBA_INTEGER_OP(==,long); | 461 | ZORBA_REL_OP(==,long); |
3855 | 386 | ZORBA_INTEGER_OP(!=,long); | 462 | ZORBA_REL_OP(!=,long); |
3856 | 387 | ZORBA_INTEGER_OP(< ,long); | 463 | ZORBA_REL_OP(< ,long); |
3857 | 388 | ZORBA_INTEGER_OP(<=,long); | 464 | ZORBA_REL_OP(<=,long); |
3858 | 389 | ZORBA_INTEGER_OP(> ,long); | 465 | ZORBA_REL_OP(> ,long); |
3859 | 390 | ZORBA_INTEGER_OP(>=,long); | 466 | ZORBA_REL_OP(>=,long); |
3860 | 391 | ZORBA_INTEGER_OP(==,long long); | 467 | ZORBA_REL_OP(==,long long); |
3861 | 392 | ZORBA_INTEGER_OP(!=,long long); | 468 | ZORBA_REL_OP(!=,long long); |
3862 | 393 | ZORBA_INTEGER_OP(< ,long long); | 469 | ZORBA_REL_OP(< ,long long); |
3863 | 394 | ZORBA_INTEGER_OP(<=,long long); | 470 | ZORBA_REL_OP(<=,long long); |
3864 | 395 | ZORBA_INTEGER_OP(> ,long long); | 471 | ZORBA_REL_OP(> ,long long); |
3865 | 396 | ZORBA_INTEGER_OP(>=,long long); | 472 | ZORBA_REL_OP(>=,long long); |
3866 | 397 | ZORBA_INTEGER_OP(==,unsigned char); | 473 | ZORBA_REL_OP(==,unsigned char); |
3867 | 398 | ZORBA_INTEGER_OP(!=,unsigned char); | 474 | ZORBA_REL_OP(!=,unsigned char); |
3868 | 399 | ZORBA_INTEGER_OP(< ,unsigned char); | 475 | ZORBA_REL_OP(< ,unsigned char); |
3869 | 400 | ZORBA_INTEGER_OP(<=,unsigned char); | 476 | ZORBA_REL_OP(<=,unsigned char); |
3870 | 401 | ZORBA_INTEGER_OP(> ,unsigned char); | 477 | ZORBA_REL_OP(> ,unsigned char); |
3871 | 402 | ZORBA_INTEGER_OP(>=,unsigned char); | 478 | ZORBA_REL_OP(>=,unsigned char); |
3872 | 403 | ZORBA_INTEGER_OP(==,unsigned short); | 479 | ZORBA_REL_OP(==,unsigned short); |
3873 | 404 | ZORBA_INTEGER_OP(!=,unsigned short); | 480 | ZORBA_REL_OP(!=,unsigned short); |
3874 | 405 | ZORBA_INTEGER_OP(< ,unsigned short); | 481 | ZORBA_REL_OP(< ,unsigned short); |
3875 | 406 | ZORBA_INTEGER_OP(<=,unsigned short); | 482 | ZORBA_REL_OP(<=,unsigned short); |
3876 | 407 | ZORBA_INTEGER_OP(> ,unsigned short); | 483 | ZORBA_REL_OP(> ,unsigned short); |
3877 | 408 | ZORBA_INTEGER_OP(>=,unsigned short); | 484 | ZORBA_REL_OP(>=,unsigned short); |
3878 | 409 | ZORBA_INTEGER_OP(==,unsigned int); | 485 | ZORBA_REL_OP(==,unsigned int); |
3879 | 410 | ZORBA_INTEGER_OP(!=,unsigned int); | 486 | ZORBA_REL_OP(!=,unsigned int); |
3880 | 411 | ZORBA_INTEGER_OP(< ,unsigned int); | 487 | ZORBA_REL_OP(< ,unsigned int); |
3881 | 412 | ZORBA_INTEGER_OP(<=,unsigned int); | 488 | ZORBA_REL_OP(<=,unsigned int); |
3882 | 413 | ZORBA_INTEGER_OP(> ,unsigned int); | 489 | ZORBA_REL_OP(> ,unsigned int); |
3883 | 414 | ZORBA_INTEGER_OP(>=,unsigned int); | 490 | ZORBA_REL_OP(>=,unsigned int); |
3884 | 415 | ZORBA_INTEGER_OP(==,unsigned long); | 491 | ZORBA_REL_OP(==,unsigned long); |
3885 | 416 | ZORBA_INTEGER_OP(!=,unsigned long); | 492 | ZORBA_REL_OP(!=,unsigned long); |
3886 | 417 | ZORBA_INTEGER_OP(< ,unsigned long); | 493 | ZORBA_REL_OP(< ,unsigned long); |
3887 | 418 | ZORBA_INTEGER_OP(<=,unsigned long); | 494 | ZORBA_REL_OP(<=,unsigned long); |
3888 | 419 | ZORBA_INTEGER_OP(> ,unsigned long); | 495 | ZORBA_REL_OP(> ,unsigned long); |
3889 | 420 | ZORBA_INTEGER_OP(>=,unsigned long); | 496 | ZORBA_REL_OP(>=,unsigned long); |
3890 | 421 | ZORBA_INTEGER_OP(==,unsigned long long); | 497 | ZORBA_REL_OP(==,unsigned long long); |
3891 | 422 | ZORBA_INTEGER_OP(!=,unsigned long long); | 498 | ZORBA_REL_OP(!=,unsigned long long); |
3892 | 423 | ZORBA_INTEGER_OP(< ,unsigned long long); | 499 | ZORBA_REL_OP(< ,unsigned long long); |
3893 | 424 | ZORBA_INTEGER_OP(<=,unsigned long long); | 500 | ZORBA_REL_OP(<=,unsigned long long); |
3894 | 425 | ZORBA_INTEGER_OP(> ,unsigned long long); | 501 | ZORBA_REL_OP(> ,unsigned long long); |
3895 | 426 | ZORBA_INTEGER_OP(>=,unsigned long long); | 502 | ZORBA_REL_OP(>=,unsigned long long); |
3896 | 427 | ZORBA_INTEGER_OP(==,float); | 503 | ZORBA_REL_OP(==,float); |
3897 | 428 | ZORBA_INTEGER_OP(!=,float); | 504 | ZORBA_REL_OP(!=,float); |
3898 | 429 | ZORBA_INTEGER_OP(< ,float); | 505 | ZORBA_REL_OP(< ,float); |
3899 | 430 | ZORBA_INTEGER_OP(<=,float); | 506 | ZORBA_REL_OP(<=,float); |
3900 | 431 | ZORBA_INTEGER_OP(> ,float); | 507 | ZORBA_REL_OP(> ,float); |
3901 | 432 | ZORBA_INTEGER_OP(>=,float); | 508 | ZORBA_REL_OP(>=,float); |
3902 | 433 | ZORBA_INTEGER_OP(==,double); | 509 | ZORBA_REL_OP(==,double); |
3903 | 434 | ZORBA_INTEGER_OP(!=,double); | 510 | ZORBA_REL_OP(!=,double); |
3904 | 435 | ZORBA_INTEGER_OP(< ,double); | 511 | ZORBA_REL_OP(< ,double); |
3905 | 436 | ZORBA_INTEGER_OP(<=,double); | 512 | ZORBA_REL_OP(<=,double); |
3906 | 437 | ZORBA_INTEGER_OP(> ,double); | 513 | ZORBA_REL_OP(> ,double); |
3907 | 438 | ZORBA_INTEGER_OP(>=,double); | 514 | ZORBA_REL_OP(>=,double); |
3908 | 439 | #undef ZORBA_INTEGER_OP | 515 | #undef ZORBA_REL_OP |
3909 | 440 | 516 | ||
3910 | 441 | ////////// math functions /////////////////////////////////////////////////// | 517 | ////////// math functions /////////////////////////////////////////////////// |
3911 | 442 | 518 | ||
3912 | @@ -464,8 +540,6 @@ | |||
3913 | 464 | zstring toString() const; | 540 | zstring toString() const; |
3914 | 465 | value_type& value(); | 541 | value_type& value(); |
3915 | 466 | value_type const& value() const; | 542 | value_type const& value() const; |
3916 | 467 | static IntegerImpl const& one(); | ||
3917 | 468 | static IntegerImpl const& zero(); | ||
3918 | 469 | 543 | ||
3919 | 470 | ///////////////////////////////////////////////////////////////////////////// | 544 | ///////////////////////////////////////////////////////////////////////////// |
3920 | 471 | 545 | ||
3921 | @@ -473,20 +547,18 @@ | |||
3922 | 473 | #ifdef ZORBA_WITH_BIG_INTEGER | 547 | #ifdef ZORBA_WITH_BIG_INTEGER |
3923 | 474 | typedef long int_cast_type; | 548 | typedef long int_cast_type; |
3924 | 475 | #else | 549 | #else |
3926 | 476 | typedef IntType int_cast_type; | 550 | typedef value_type int_cast_type; |
3927 | 477 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 551 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3928 | 478 | 552 | ||
3929 | 479 | value_type value_; | 553 | value_type value_; |
3930 | 480 | 554 | ||
3931 | 481 | #ifdef ZORBA_WITH_BIG_INTEGER | ||
3932 | 482 | IntegerImpl( value_type const &v ) : value_( v ) { } | ||
3933 | 483 | #endif /* ZORBA_WITH_BIG_INTEGER */ | ||
3934 | 484 | |||
3935 | 485 | static value_type ftoi( double d ) { | 555 | static value_type ftoi( double d ) { |
3936 | 486 | return value_type( d >= 0 ? floor( d ) : ceil( d ) ); | 556 | return value_type( d >= 0 ? floor( d ) : ceil( d ) ); |
3937 | 487 | } | 557 | } |
3938 | 488 | 558 | ||
3939 | 489 | #ifdef ZORBA_WITH_BIG_INTEGER | 559 | #ifdef ZORBA_WITH_BIG_INTEGER |
3940 | 560 | IntegerImpl( value_type const &v ) : value_( v ) { } | ||
3941 | 561 | |||
3942 | 490 | static value_type ftoi( MAPM const &d ) { | 562 | static value_type ftoi( MAPM const &d ) { |
3943 | 491 | return d.sign() >= 0 ? d.floor() : d.ceil(); | 563 | return d.sign() >= 0 ? d.floor() : d.ceil(); |
3944 | 492 | } | 564 | } |
3945 | @@ -499,7 +571,6 @@ | |||
3946 | 499 | static value_type make_value_type( T n ) { | 571 | static value_type make_value_type( T n ) { |
3947 | 500 | return value_type( static_cast<int_cast_type>( n ) ); | 572 | return value_type( static_cast<int_cast_type>( n ) ); |
3948 | 501 | } | 573 | } |
3949 | 502 | |||
3950 | 503 | #else /* ZORBA_WITH_BIG_INTEGER */ | 574 | #else /* ZORBA_WITH_BIG_INTEGER */ |
3951 | 504 | 575 | ||
3952 | 505 | static value_type ftoi( value_type v ) { | 576 | static value_type ftoi( value_type v ) { |
3953 | @@ -516,148 +587,149 @@ | |||
3954 | 516 | } | 587 | } |
3955 | 517 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 588 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3956 | 518 | 589 | ||
3958 | 519 | void parse( char const *s ); | 590 | void parse( char const *s, bool throw_range_error ); |
3959 | 520 | 591 | ||
3960 | 521 | friend class Decimal; | 592 | friend class Decimal; |
3976 | 522 | template<typename T> friend class FloatImpl; | 593 | template<typename F> friend class FloatImpl; |
3977 | 523 | 594 | template<class T> friend class IntegerImpl; | |
3978 | 524 | #ifndef ZORBA_WITH_BIG_INTEGER | 595 | |
3979 | 525 | template<typename T> friend class IntegerImpl; | 596 | friend xs_int to_xs_int( Integer const& ); |
3980 | 526 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 597 | friend xs_long to_xs_long( Integer const& ); |
3981 | 527 | 598 | friend xs_unsignedByte to_xs_unsignedByte( Integer const& ); | |
3982 | 528 | friend xs_int to_xs_int( INTEGER_IMPL_LL const& ); | 599 | friend xs_unsignedShort to_xs_unsignedShort( Integer const& ); |
3983 | 529 | friend xs_long to_xs_long( INTEGER_IMPL_LL const& ); | 600 | friend xs_unsignedInt to_xs_unsignedInt( Integer const& ); |
3984 | 530 | friend xs_unsignedByte to_xs_unsignedByte( INTEGER_IMPL_LL const& ); | 601 | friend xs_unsignedLong to_xs_unsignedLong( Integer const& ); |
3985 | 531 | friend xs_unsignedShort to_xs_unsignedShort( INTEGER_IMPL_LL const& ); | 602 | |
3986 | 532 | friend xs_unsignedInt to_xs_unsignedInt( INTEGER_IMPL_LL const& ); | 603 | template<class T> friend |
3987 | 533 | friend xs_unsignedLong to_xs_unsignedLong( INTEGER_IMPL_LL const& ); | 604 | void serialization::operator&( serialization::Archiver&, IntegerImpl<T>& ); |
3973 | 534 | |||
3974 | 535 | TEMPLATE_DECL(I) friend | ||
3975 | 536 | void serialization::operator&( serialization::Archiver&, INTEGER_IMPL(I)& ); | ||
3988 | 537 | }; | 605 | }; |
3989 | 538 | 606 | ||
3992 | 539 | typedef INTEGER_IMPL_LL Integer; | 607 | typedef IntegerImpl<integer_traits> Integer; |
3993 | 540 | typedef INTEGER_IMPL_ULL UInteger; | 608 | typedef IntegerImpl<negative_traits> NegativeInteger; |
3994 | 609 | typedef IntegerImpl<nonNegative_traits> NonNegativeInteger; | ||
3995 | 610 | typedef IntegerImpl<nonPositive_traits> NonPositiveInteger; | ||
3996 | 611 | typedef IntegerImpl<positive_traits> PositiveInteger; | ||
3997 | 541 | 612 | ||
3998 | 542 | ////////// constructors /////////////////////////////////////////////////////// | 613 | ////////// constructors /////////////////////////////////////////////////////// |
3999 | 543 | 614 | ||
4027 | 544 | TEMPLATE_DECL(I) | 615 | template<class T> |
4028 | 545 | inline INTEGER_IMPL(I)::IntegerImpl( char c ) : | 616 | inline IntegerImpl<T>::IntegerImpl( char c ) : |
4029 | 546 | value_( static_cast<long>( c ) ) | 617 | value_( static_cast<long>( T::check_value( c, false ) ) ) |
4030 | 547 | { | 618 | { |
4031 | 548 | } | 619 | } |
4032 | 549 | 620 | ||
4033 | 550 | TEMPLATE_DECL(I) | 621 | template<class T> |
4034 | 551 | inline INTEGER_IMPL(I)::IntegerImpl( signed char c ) : | 622 | inline IntegerImpl<T>::IntegerImpl( signed char c ) : |
4035 | 552 | value_( static_cast<long>( c ) ) | 623 | value_( static_cast<long>( T::check_value( c, false ) ) ) |
4036 | 553 | { | 624 | { |
4037 | 554 | } | 625 | } |
4038 | 555 | 626 | ||
4039 | 556 | TEMPLATE_DECL(I) | 627 | template<class T> |
4040 | 557 | inline INTEGER_IMPL(I)::IntegerImpl( short n ) : | 628 | inline IntegerImpl<T>::IntegerImpl( short n ) : |
4041 | 558 | value_( static_cast<long>( n ) ) | 629 | value_( static_cast<long>( T::check_value( n, false ) ) ) |
4042 | 559 | { | 630 | { |
4043 | 560 | } | 631 | } |
4044 | 561 | 632 | ||
4045 | 562 | TEMPLATE_DECL(I) | 633 | template<class T> |
4046 | 563 | inline INTEGER_IMPL(I)::IntegerImpl( int n ) : | 634 | inline IntegerImpl<T>::IntegerImpl( int n ) : |
4047 | 564 | value_( static_cast<long>( n ) ) | 635 | value_( static_cast<long>( T::check_value( n, false ) ) ) |
4048 | 565 | { | 636 | { |
4049 | 566 | } | 637 | } |
4050 | 567 | 638 | ||
4051 | 568 | TEMPLATE_DECL(I) | 639 | template<class T> |
4052 | 569 | inline INTEGER_IMPL(I)::IntegerImpl( long n ) : | 640 | inline IntegerImpl<T>::IntegerImpl( long n ) : |
4053 | 570 | value_( n ) | 641 | value_( T::check_value( n, false ) ) |
4054 | 571 | { | 642 | { |
4055 | 572 | } | 643 | } |
4056 | 573 | 644 | ||
4057 | 574 | #ifndef ZORBA_WITH_BIG_INTEGER | 645 | #ifndef ZORBA_WITH_BIG_INTEGER |
4061 | 575 | TEMPLATE_DECL(I) | 646 | template<class T> |
4062 | 576 | inline INTEGER_IMPL(I)::IntegerImpl( long long n ) : | 647 | inline IntegerImpl<T>::IntegerImpl( long long n ) : |
4063 | 577 | value_( n ) | 648 | value_( T::check_value( n, false ) ) |
4064 | 578 | { | 649 | { |
4065 | 579 | } | 650 | } |
4066 | 580 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 651 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4067 | 581 | 652 | ||
4071 | 582 | TEMPLATE_DECL(I) | 653 | template<class T> |
4072 | 583 | inline INTEGER_IMPL(I)::IntegerImpl( unsigned char c ) : | 654 | inline IntegerImpl<T>::IntegerImpl( unsigned char c ) : |
4073 | 584 | value_( static_cast<long>( (unsigned long)c ) ) | 655 | value_( static_cast<long>( (unsigned long)T::check_value( c, false ) ) ) |
4074 | 585 | { | 656 | { |
4075 | 586 | } | 657 | } |
4076 | 587 | 658 | ||
4080 | 588 | TEMPLATE_DECL(I) | 659 | template<class T> |
4081 | 589 | inline INTEGER_IMPL(I)::IntegerImpl( unsigned short n ) : | 660 | inline IntegerImpl<T>::IntegerImpl( unsigned short n ) : |
4082 | 590 | value_( static_cast<long>( (unsigned long)n ) ) | 661 | value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) ) |
4083 | 591 | { | 662 | { |
4084 | 592 | } | 663 | } |
4085 | 593 | 664 | ||
4086 | 594 | #ifdef ZORBA_WITH_BIG_INTEGER | 665 | #ifdef ZORBA_WITH_BIG_INTEGER |
4087 | 595 | #if ZORBA_SIZEOF_INT != ZORBA_SIZEOF_LONG | 666 | #if ZORBA_SIZEOF_INT != ZORBA_SIZEOF_LONG |
4091 | 596 | TEMPLATE_DECL(T) | 667 | template<class T> |
4092 | 597 | inline INTEGER_IMPL(T)::IntegerImpl( unsigned int n ) : | 668 | inline IntegerImpl<T>::IntegerImpl( unsigned int n ) : |
4093 | 598 | value_( static_cast<long>( (unsigned long)n ) ) | 669 | value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) ) |
4094 | 599 | { | 670 | { |
4095 | 600 | } | 671 | } |
4096 | 601 | #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */ | 672 | #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */ |
4097 | 602 | #else /* ZORBA_WITH_BIG_INTEGER */ | 673 | #else /* ZORBA_WITH_BIG_INTEGER */ |
4146 | 603 | TEMPLATE_DECL(I) | 674 | |
4147 | 604 | inline INTEGER_IMPL(I)::IntegerImpl( unsigned int n ) : | 675 | template<class T> |
4148 | 605 | value_( static_cast<value_type>( n ) ) | 676 | inline IntegerImpl<T>::IntegerImpl( unsigned int n ) : |
4149 | 606 | { | 677 | value_( static_cast<value_type>( T::check_value( n, false ) ) ) |
4150 | 607 | } | 678 | { |
4151 | 608 | 679 | } | |
4152 | 609 | TEMPLATE_DECL(I) | 680 | |
4153 | 610 | inline INTEGER_IMPL(I)::IntegerImpl( unsigned long n ) : | 681 | template<class T> |
4154 | 611 | value_( static_cast<value_type>( n ) ) | 682 | inline IntegerImpl<T>::IntegerImpl( unsigned long n ) : |
4155 | 612 | { | 683 | value_( static_cast<value_type>( T::check_value( n, false ) ) ) |
4156 | 613 | } | 684 | { |
4157 | 614 | 685 | } | |
4158 | 615 | TEMPLATE_DECL(I) | 686 | |
4159 | 616 | inline INTEGER_IMPL(I)::IntegerImpl( unsigned long long n ) : | 687 | template<class T> |
4160 | 617 | value_( static_cast<value_type>( n ) ) | 688 | inline IntegerImpl<T>::IntegerImpl( unsigned long long n ) : |
4161 | 618 | { | 689 | value_( static_cast<value_type>( T::check_value( n, false ) ) ) |
4162 | 619 | } | 690 | { |
4163 | 620 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 691 | } |
4164 | 621 | 692 | #endif /* ZORBA_WITH_BIG_INTEGER */ | |
4165 | 622 | TEMPLATE_DECL(I) | 693 | |
4166 | 623 | inline INTEGER_IMPL(I)::IntegerImpl( float n ) : | 694 | template<class T> |
4167 | 624 | #ifdef ZORBA_WITH_BIG_INTEGER | 695 | inline IntegerImpl<T>::IntegerImpl( float n ) : |
4168 | 625 | value_( static_cast<double>( n ) ) | 696 | #ifdef ZORBA_WITH_BIG_INTEGER |
4169 | 626 | #else | 697 | value_( static_cast<double>( T::check_value( n, false ) ) ) |
4170 | 627 | value_( static_cast<value_type>( n ) ) | 698 | #else |
4171 | 628 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 699 | value_( static_cast<value_type>( T::check_value( n, false ) ) ) |
4172 | 629 | { | 700 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4173 | 630 | } | 701 | { |
4174 | 631 | 702 | } | |
4175 | 632 | TEMPLATE_DECL(I) | 703 | |
4176 | 633 | inline INTEGER_IMPL(I)::IntegerImpl( double n ) : | 704 | template<class T> |
4177 | 634 | #ifdef ZORBA_WITH_BIG_INTEGER | 705 | inline IntegerImpl<T>::IntegerImpl( double n ) : |
4178 | 635 | value_( n ) | 706 | #ifdef ZORBA_WITH_BIG_INTEGER |
4179 | 636 | #else | 707 | value_( T::check_value( n, false ) ) |
4180 | 637 | value_( static_cast<value_type>( n ) ) | 708 | #else |
4181 | 638 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 709 | value_( static_cast<value_type>( T::check_value( n, false ) ) ) |
4182 | 639 | { | 710 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4183 | 640 | } | 711 | { |
4184 | 641 | 712 | } | |
4185 | 642 | TEMPLATE_DECL(I) | 713 | |
4186 | 643 | inline INTEGER_IMPL(I)::IntegerImpl( char const *s ) { | 714 | template<class T> |
4187 | 644 | parse( s ); | 715 | inline IntegerImpl<T>::IntegerImpl( char const *s ) { |
4188 | 645 | } | 716 | parse( s, false ); |
4189 | 646 | 717 | } | |
4190 | 647 | TEMPLATE_DECL(I) | 718 | |
4191 | 648 | TEMPLATE_DECL(J) | 719 | template<class T> |
4192 | 649 | inline INTEGER_IMPL(I)::IntegerImpl( INTEGER_IMPL(J) const &i ) : | 720 | template<class U> |
4193 | 650 | value_( i.value_ ) | 721 | inline IntegerImpl<T>::IntegerImpl( IntegerImpl<U> const &i ) : |
4194 | 722 | value_( T::check_value( i.value_, false ) ) | ||
4195 | 651 | { | 723 | { |
4196 | 652 | } | 724 | } |
4197 | 653 | 725 | ||
4198 | 654 | ////////// assignment operators /////////////////////////////////////////////// | 726 | ////////// assignment operators /////////////////////////////////////////////// |
4199 | 655 | 727 | ||
4205 | 656 | #define ZORBA_ASSIGN_OP(T) \ | 728 | #define ZORBA_ASSIGN_OP(N) \ |
4206 | 657 | TEMPLATE_DECL(I) inline \ | 729 | template<class T> inline \ |
4207 | 658 | INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( T n ) { \ | 730 | IntegerImpl<T>& IntegerImpl<T>::operator=( N n ) { \ |
4208 | 659 | value_ = static_cast<int_cast_type>( n ); \ | 731 | value_ = static_cast<int_cast_type>( T::check_value( n, false ) ); \ |
4209 | 660 | return *this; \ | 732 | return *this; \ |
4210 | 661 | } | 733 | } |
4211 | 662 | 734 | ||
4212 | 663 | ZORBA_ASSIGN_OP(char) | 735 | ZORBA_ASSIGN_OP(char) |
4213 | @@ -677,25 +749,25 @@ | |||
4214 | 677 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 749 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4215 | 678 | #undef ZORBA_ASSIGN_OP | 750 | #undef ZORBA_ASSIGN_OP |
4216 | 679 | 751 | ||
4220 | 680 | TEMPLATE_DECL(I) | 752 | template<class T> |
4221 | 681 | inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( char const *s ) { | 753 | inline IntegerImpl<T>& IntegerImpl<T>::operator=( char const *s ) { |
4222 | 682 | parse( s ); | 754 | parse( s, false ); |
4223 | 683 | return *this; | 755 | return *this; |
4224 | 684 | } | 756 | } |
4225 | 685 | 757 | ||
4229 | 686 | TEMPLATE_DECL(I) TEMPLATE_DECL(J) | 758 | template<class T> |
4230 | 687 | inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( INTEGER_IMPL(J) const &i ) { | 759 | template<class U> |
4231 | 688 | value_ = i.value_; | 760 | inline IntegerImpl<T>& IntegerImpl<T>::operator=( IntegerImpl<U> const &i ) { |
4232 | 761 | T::check_value( value_ = i.value_, false ); | ||
4233 | 689 | return *this; | 762 | return *this; |
4234 | 690 | } | 763 | } |
4235 | 691 | 764 | ||
4236 | 692 | ////////// arithmetic operators /////////////////////////////////////////////// | 765 | ////////// arithmetic operators /////////////////////////////////////////////// |
4237 | 693 | 766 | ||
4243 | 694 | #define ZORBA_INTEGER_OP(OP) \ | 767 | #define ZORBA_INTEGER_OP(OP) \ |
4244 | 695 | TEMPLATE_DECL(I) inline \ | 768 | template<class T,class U> inline \ |
4245 | 696 | INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const &i, \ | 769 | Integer operator OP( IntegerImpl<T> const &i, IntegerImpl<U> const &j ) { \ |
4246 | 697 | INTEGER_IMPL(I) const &j ) { \ | 770 | return Integer( i.value_ OP j.value_ ); \ |
4242 | 698 | return INTEGER_IMPL(I)( i.value_ OP j.value_ ); \ | ||
4247 | 699 | } | 771 | } |
4248 | 700 | 772 | ||
4249 | 701 | ZORBA_INTEGER_OP(+) | 773 | ZORBA_INTEGER_OP(+) |
4250 | @@ -704,21 +776,20 @@ | |||
4251 | 704 | ZORBA_INTEGER_OP(%) | 776 | ZORBA_INTEGER_OP(%) |
4252 | 705 | #undef ZORBA_INTEGER_OP | 777 | #undef ZORBA_INTEGER_OP |
4253 | 706 | 778 | ||
4258 | 707 | TEMPLATE_DECL(I) inline | 779 | template<class T,class U> |
4259 | 708 | INTEGER_IMPL(I) operator/( INTEGER_IMPL(I) const &i, | 780 | inline Integer operator/( IntegerImpl<T> const &i, IntegerImpl<U> const &j ) { |
4260 | 709 | INTEGER_IMPL(I) const &j ) { | 781 | return Integer( Integer::ftoi( i.value_ / j.value_ ) ); |
4257 | 710 | return INTEGER_IMPL(I)( INTEGER_IMPL(I)::ftoi( i.value_ / j.value_ ) ); | ||
4261 | 711 | } | 782 | } |
4262 | 712 | 783 | ||
4267 | 713 | #define ZORBA_INTEGER_OP(OP,T) \ | 784 | #define ZORBA_INTEGER_OP(OP,N) \ |
4268 | 714 | TEMPLATE_DECL(I) inline \ | 785 | template<class T> inline \ |
4269 | 715 | INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const &i, T n ) { \ | 786 | Integer operator OP( IntegerImpl<T> const &i, N n ) { \ |
4270 | 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 ) ); \ |
4271 | 717 | } \ | 788 | } \ |
4272 | 718 | \ | 789 | \ |
4276 | 719 | TEMPLATE_DECL(I) inline \ | 790 | template<class T> inline \ |
4277 | 720 | INTEGER_IMPL(I) operator OP( T n, INTEGER_IMPL(I) const &i ) { \ | 791 | Integer operator OP( N n, IntegerImpl<T> const &i ) { \ |
4278 | 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_ ); \ |
4279 | 722 | } | 793 | } |
4280 | 723 | 794 | ||
4281 | 724 | ZORBA_INTEGER_OP(+,char) | 795 | ZORBA_INTEGER_OP(+,char) |
4282 | @@ -777,15 +848,15 @@ | |||
4283 | 777 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 848 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4284 | 778 | #undef ZORBA_INTEGER_OP | 849 | #undef ZORBA_INTEGER_OP |
4285 | 779 | 850 | ||
4295 | 780 | #define ZORBA_INTEGER_OP(T) \ | 851 | #define ZORBA_INTEGER_OP(N) \ |
4296 | 781 | TEMPLATE_DECL(I) inline \ | 852 | template<class T> inline \ |
4297 | 782 | INTEGER_IMPL(I) operator/( INTEGER_IMPL(I) const &i, T n ) { \ | 853 | Integer operator/( IntegerImpl<T> const &i, N n ) { \ |
4298 | 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 ) ) ); \ |
4299 | 784 | } \ | 855 | } \ |
4300 | 785 | \ | 856 | \ |
4301 | 786 | TEMPLATE_DECL(I) inline \ | 857 | template<class T> inline \ |
4302 | 787 | INTEGER_IMPL(I) operator/( T n, INTEGER_IMPL(I) const &i ) { \ | 858 | Integer operator/( N n, IntegerImpl<T> const &i ) { \ |
4303 | 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_ ) ); \ |
4304 | 789 | } | 860 | } |
4305 | 790 | 861 | ||
4306 | 791 | ZORBA_INTEGER_OP(signed char) | 862 | ZORBA_INTEGER_OP(signed char) |
4307 | @@ -805,11 +876,11 @@ | |||
4308 | 805 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 876 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4309 | 806 | #undef ZORBA_INTEGER_OP | 877 | #undef ZORBA_INTEGER_OP |
4310 | 807 | 878 | ||
4316 | 808 | #define ZORBA_INTEGER_OP(OP) \ | 879 | #define ZORBA_INTEGER_OP(OP) \ |
4317 | 809 | TEMPLATE_DECL(I) inline \ | 880 | template<class T> inline \ |
4318 | 810 | INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator OP( IntegerImpl const &i ) { \ | 881 | IntegerImpl<T>& IntegerImpl<T>::operator OP( IntegerImpl<T> const &i ) { \ |
4319 | 811 | value_ OP i.value_; \ | 882 | T::check_value( value_ OP i.value_, true ); \ |
4320 | 812 | return *this; \ | 883 | return *this; \ |
4321 | 813 | } | 884 | } |
4322 | 814 | 885 | ||
4323 | 815 | ZORBA_INTEGER_OP(+=) | 886 | ZORBA_INTEGER_OP(+=) |
4324 | @@ -818,17 +889,17 @@ | |||
4325 | 818 | ZORBA_INTEGER_OP(%=) | 889 | ZORBA_INTEGER_OP(%=) |
4326 | 819 | #undef ZORBA_INTEGER_OP | 890 | #undef ZORBA_INTEGER_OP |
4327 | 820 | 891 | ||
4331 | 821 | TEMPLATE_DECL(I) | 892 | template<class T> |
4332 | 822 | inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator/=( IntegerImpl const &i ) { | 893 | inline IntegerImpl<T>& IntegerImpl<T>::operator/=( IntegerImpl<T> const &i ) { |
4333 | 823 | value_ = ftoi( value_ / i.value_ ); | 894 | value_ = T::check_value( ftoi( value_ / i.value_ ), true ); |
4334 | 824 | return *this; | 895 | return *this; |
4335 | 825 | } | 896 | } |
4336 | 826 | 897 | ||
4342 | 827 | #define ZORBA_INTEGER_OP(OP,T) \ | 898 | #define ZORBA_INTEGER_OP(OP,N) \ |
4343 | 828 | TEMPLATE_DECL(I) inline \ | 899 | template<class T> inline \ |
4344 | 829 | INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator OP( T n ) { \ | 900 | IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \ |
4345 | 830 | value_ OP make_value_type( n ); \ | 901 | T::check_value( value_ OP make_value_type( n ), true ); \ |
4346 | 831 | return *this; \ | 902 | return *this; \ |
4347 | 832 | } | 903 | } |
4348 | 833 | 904 | ||
4349 | 834 | ZORBA_INTEGER_OP(+=,char) | 905 | ZORBA_INTEGER_OP(+=,char) |
4350 | @@ -887,11 +958,11 @@ | |||
4351 | 887 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 958 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4352 | 888 | #undef ZORBA_INTEGER_OP | 959 | #undef ZORBA_INTEGER_OP |
4353 | 889 | 960 | ||
4359 | 890 | #define ZORBA_INTEGER_OP(T) \ | 961 | #define ZORBA_INTEGER_OP(N) \ |
4360 | 891 | TEMPLATE_DECL(I) inline \ | 962 | template<class T> inline \ |
4361 | 892 | INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator/=( T n ) { \ | 963 | IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \ |
4362 | 893 | value_ = ftoi( value_ / make_value_type( n ) ); \ | 964 | value_ = T::check_value( ftoi( value_ / make_value_type( n ) ), true ); \ |
4363 | 894 | return *this; \ | 965 | return *this; \ |
4364 | 895 | } | 966 | } |
4365 | 896 | 967 | ||
4366 | 897 | ZORBA_INTEGER_OP(char) | 968 | ZORBA_INTEGER_OP(char) |
4367 | @@ -911,243 +982,247 @@ | |||
4368 | 911 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 982 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4369 | 912 | #undef ZORBA_INTEGER_OP | 983 | #undef ZORBA_INTEGER_OP |
4370 | 913 | 984 | ||
4374 | 914 | TEMPLATE_DECL(I) | 985 | template<class T> |
4375 | 915 | inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator-() const { | 986 | inline Integer IntegerImpl<T>::operator-() const { |
4376 | 916 | return INTEGER_IMPL(I)( -value_ ); | 987 | return Integer( -value_ ); |
4377 | 917 | } | 988 | } |
4378 | 918 | 989 | ||
4382 | 919 | TEMPLATE_DECL(I) | 990 | template<class T> |
4383 | 920 | inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator++() { | 991 | inline IntegerImpl<T>& IntegerImpl<T>::operator++() { |
4384 | 921 | ++value_; | 992 | T::check_value( ++value_, true ); |
4385 | 922 | return *this; | 993 | return *this; |
4386 | 923 | } | 994 | } |
4387 | 924 | 995 | ||
4392 | 925 | TEMPLATE_DECL(I) | 996 | template<class T> |
4393 | 926 | inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator++(int) { | 997 | inline IntegerImpl<T> IntegerImpl<T>::operator++(int) { |
4394 | 927 | INTEGER_IMPL(I) const result( *this ); | 998 | IntegerImpl<T> const result( *this ); |
4395 | 928 | ++value_; | 999 | T::check_value( ++value_, true ); |
4396 | 929 | return result; | 1000 | return result; |
4397 | 930 | } | 1001 | } |
4398 | 931 | 1002 | ||
4402 | 932 | TEMPLATE_DECL(I) | 1003 | template<class T> |
4403 | 933 | inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator--() { | 1004 | inline IntegerImpl<T>& IntegerImpl<T>::operator--() { |
4404 | 934 | --value_; | 1005 | T::check_value( --value_, true ); |
4405 | 935 | return *this; | 1006 | return *this; |
4406 | 936 | } | 1007 | } |
4407 | 937 | 1008 | ||
4412 | 938 | TEMPLATE_DECL(I) | 1009 | template<class T> |
4413 | 939 | inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator--(int) { | 1010 | inline IntegerImpl<T> IntegerImpl<T>::operator--(int) { |
4414 | 940 | INTEGER_IMPL(I) const result( *this ); | 1011 | IntegerImpl<T> const result( *this ); |
4415 | 941 | --value_; | 1012 | T::check_value( --value_, true ); |
4416 | 942 | return result; | 1013 | return result; |
4417 | 943 | } | 1014 | } |
4418 | 944 | 1015 | ||
4419 | 945 | ////////// relational operators /////////////////////////////////////////////// | 1016 | ////////// relational operators /////////////////////////////////////////////// |
4420 | 946 | 1017 | ||
4425 | 947 | #define ZORBA_INTEGER_OP(OP) \ | 1018 | #define ZORBA_REL_OP(OP) \ |
4426 | 948 | TEMPLATE_DECL(I) inline \ | 1019 | template<class T,class U> inline \ |
4427 | 949 | bool operator OP( INTEGER_IMPL(I) const &i, INTEGER_IMPL(I) const &j ) { \ | 1020 | bool operator OP( IntegerImpl<T> const &i, IntegerImpl<U> const &j ) { \ |
4428 | 950 | return i.value_ OP j.value_; \ | 1021 | return i.value_ OP j.value_; \ |
4429 | 951 | } | 1022 | } |
4430 | 952 | 1023 | ||
4438 | 953 | ZORBA_INTEGER_OP(==) | 1024 | ZORBA_REL_OP(==) |
4439 | 954 | ZORBA_INTEGER_OP(!=) | 1025 | ZORBA_REL_OP(!=) |
4440 | 955 | ZORBA_INTEGER_OP(< ) | 1026 | ZORBA_REL_OP(< ) |
4441 | 956 | ZORBA_INTEGER_OP(<=) | 1027 | ZORBA_REL_OP(<=) |
4442 | 957 | ZORBA_INTEGER_OP(> ) | 1028 | ZORBA_REL_OP(> ) |
4443 | 958 | ZORBA_INTEGER_OP(>=) | 1029 | ZORBA_REL_OP(>=) |
4444 | 959 | #undef ZORBA_INTEGER_OP | 1030 | #undef ZORBA_REL_OP |
4445 | 960 | 1031 | ||
4450 | 961 | #define ZORBA_INTEGER_OP(OP,T) \ | 1032 | #define ZORBA_REL_OP(OP,N) \ |
4451 | 962 | TEMPLATE_DECL(I) inline \ | 1033 | template<class T> inline \ |
4452 | 963 | bool operator OP( INTEGER_IMPL(I) const &i, T n ) { \ | 1034 | bool operator OP( IntegerImpl<T> const &i, N n ) { \ |
4453 | 964 | return i.value_ OP INTEGER_IMPL(I)::make_value_type( n ); \ | 1035 | return i.value_ OP IntegerImpl<T>::make_value_type( n ); \ |
4454 | 965 | } \ | 1036 | } \ |
4455 | 966 | \ | 1037 | \ |
4459 | 967 | TEMPLATE_DECL(I) inline \ | 1038 | template<class T> inline \ |
4460 | 968 | bool operator OP( T n, INTEGER_IMPL(I) const &i ) { \ | 1039 | bool operator OP( N n, IntegerImpl<T> const &i ) { \ |
4461 | 969 | return INTEGER_IMPL(I)::make_value_type( n ) OP i.value_; \ | 1040 | return IntegerImpl<T>::make_value_type( n ) OP i.value_; \ |
4462 | 970 | } | 1041 | } |
4463 | 971 | 1042 | ||
4524 | 972 | ZORBA_INTEGER_OP(==,char) | 1043 | ZORBA_REL_OP(==,char) |
4525 | 973 | ZORBA_INTEGER_OP(!=,char) | 1044 | ZORBA_REL_OP(!=,char) |
4526 | 974 | ZORBA_INTEGER_OP(< ,char) | 1045 | ZORBA_REL_OP(< ,char) |
4527 | 975 | ZORBA_INTEGER_OP(<=,char) | 1046 | ZORBA_REL_OP(<=,char) |
4528 | 976 | ZORBA_INTEGER_OP(> ,char) | 1047 | ZORBA_REL_OP(> ,char) |
4529 | 977 | ZORBA_INTEGER_OP(>=,char) | 1048 | ZORBA_REL_OP(>=,char) |
4530 | 978 | ZORBA_INTEGER_OP(==,signed char) | 1049 | ZORBA_REL_OP(==,signed char) |
4531 | 979 | ZORBA_INTEGER_OP(!=,signed char) | 1050 | ZORBA_REL_OP(!=,signed char) |
4532 | 980 | ZORBA_INTEGER_OP(< ,signed char) | 1051 | ZORBA_REL_OP(< ,signed char) |
4533 | 981 | ZORBA_INTEGER_OP(<=,signed char) | 1052 | ZORBA_REL_OP(<=,signed char) |
4534 | 982 | ZORBA_INTEGER_OP(> ,signed char) | 1053 | ZORBA_REL_OP(> ,signed char) |
4535 | 983 | ZORBA_INTEGER_OP(>=,signed char) | 1054 | ZORBA_REL_OP(>=,signed char) |
4536 | 984 | ZORBA_INTEGER_OP(==,short) | 1055 | ZORBA_REL_OP(==,short) |
4537 | 985 | ZORBA_INTEGER_OP(!=,short) | 1056 | ZORBA_REL_OP(!=,short) |
4538 | 986 | ZORBA_INTEGER_OP(< ,short) | 1057 | ZORBA_REL_OP(< ,short) |
4539 | 987 | ZORBA_INTEGER_OP(<=,short) | 1058 | ZORBA_REL_OP(<=,short) |
4540 | 988 | ZORBA_INTEGER_OP(> ,short) | 1059 | ZORBA_REL_OP(> ,short) |
4541 | 989 | ZORBA_INTEGER_OP(>=,short) | 1060 | ZORBA_REL_OP(>=,short) |
4542 | 990 | ZORBA_INTEGER_OP(==,int) | 1061 | ZORBA_REL_OP(==,int) |
4543 | 991 | ZORBA_INTEGER_OP(!=,int) | 1062 | ZORBA_REL_OP(!=,int) |
4544 | 992 | ZORBA_INTEGER_OP(< ,int) | 1063 | ZORBA_REL_OP(< ,int) |
4545 | 993 | ZORBA_INTEGER_OP(<=,int) | 1064 | ZORBA_REL_OP(<=,int) |
4546 | 994 | ZORBA_INTEGER_OP(> ,int) | 1065 | ZORBA_REL_OP(> ,int) |
4547 | 995 | ZORBA_INTEGER_OP(>=,int) | 1066 | ZORBA_REL_OP(>=,int) |
4548 | 996 | ZORBA_INTEGER_OP(==,long) | 1067 | ZORBA_REL_OP(==,long) |
4549 | 997 | ZORBA_INTEGER_OP(!=,long) | 1068 | ZORBA_REL_OP(!=,long) |
4550 | 998 | ZORBA_INTEGER_OP(< ,long) | 1069 | ZORBA_REL_OP(< ,long) |
4551 | 999 | ZORBA_INTEGER_OP(<=,long) | 1070 | ZORBA_REL_OP(<=,long) |
4552 | 1000 | ZORBA_INTEGER_OP(> ,long) | 1071 | ZORBA_REL_OP(> ,long) |
4553 | 1001 | ZORBA_INTEGER_OP(>=,long) | 1072 | ZORBA_REL_OP(>=,long) |
4554 | 1002 | ZORBA_INTEGER_OP(==,unsigned char) | 1073 | ZORBA_REL_OP(==,unsigned char) |
4555 | 1003 | ZORBA_INTEGER_OP(!=,unsigned char) | 1074 | ZORBA_REL_OP(!=,unsigned char) |
4556 | 1004 | ZORBA_INTEGER_OP(< ,unsigned char) | 1075 | ZORBA_REL_OP(< ,unsigned char) |
4557 | 1005 | ZORBA_INTEGER_OP(<=,unsigned char) | 1076 | ZORBA_REL_OP(<=,unsigned char) |
4558 | 1006 | ZORBA_INTEGER_OP(> ,unsigned char) | 1077 | ZORBA_REL_OP(> ,unsigned char) |
4559 | 1007 | ZORBA_INTEGER_OP(>=,unsigned char) | 1078 | ZORBA_REL_OP(>=,unsigned char) |
4560 | 1008 | ZORBA_INTEGER_OP(==,unsigned short) | 1079 | ZORBA_REL_OP(==,unsigned short) |
4561 | 1009 | ZORBA_INTEGER_OP(!=,unsigned short) | 1080 | ZORBA_REL_OP(!=,unsigned short) |
4562 | 1010 | ZORBA_INTEGER_OP(< ,unsigned short) | 1081 | ZORBA_REL_OP(< ,unsigned short) |
4563 | 1011 | ZORBA_INTEGER_OP(<=,unsigned short) | 1082 | ZORBA_REL_OP(<=,unsigned short) |
4564 | 1012 | ZORBA_INTEGER_OP(> ,unsigned short) | 1083 | ZORBA_REL_OP(> ,unsigned short) |
4565 | 1013 | ZORBA_INTEGER_OP(>=,unsigned short) | 1084 | ZORBA_REL_OP(>=,unsigned short) |
4566 | 1014 | ZORBA_INTEGER_OP(==,unsigned int) | 1085 | ZORBA_REL_OP(==,unsigned int) |
4567 | 1015 | ZORBA_INTEGER_OP(!=,unsigned int) | 1086 | ZORBA_REL_OP(!=,unsigned int) |
4568 | 1016 | ZORBA_INTEGER_OP(< ,unsigned int) | 1087 | ZORBA_REL_OP(< ,unsigned int) |
4569 | 1017 | ZORBA_INTEGER_OP(<=,unsigned int) | 1088 | ZORBA_REL_OP(<=,unsigned int) |
4570 | 1018 | ZORBA_INTEGER_OP(> ,unsigned int) | 1089 | ZORBA_REL_OP(> ,unsigned int) |
4571 | 1019 | ZORBA_INTEGER_OP(>=,unsigned int) | 1090 | ZORBA_REL_OP(>=,unsigned int) |
4572 | 1020 | ZORBA_INTEGER_OP(==,float) | 1091 | ZORBA_REL_OP(==,float) |
4573 | 1021 | ZORBA_INTEGER_OP(!=,float) | 1092 | ZORBA_REL_OP(!=,float) |
4574 | 1022 | ZORBA_INTEGER_OP(< ,float) | 1093 | ZORBA_REL_OP(< ,float) |
4575 | 1023 | ZORBA_INTEGER_OP(<=,float) | 1094 | ZORBA_REL_OP(<=,float) |
4576 | 1024 | ZORBA_INTEGER_OP(> ,float) | 1095 | ZORBA_REL_OP(> ,float) |
4577 | 1025 | ZORBA_INTEGER_OP(>=,float) | 1096 | ZORBA_REL_OP(>=,float) |
4578 | 1026 | ZORBA_INTEGER_OP(==,double) | 1097 | ZORBA_REL_OP(==,double) |
4579 | 1027 | ZORBA_INTEGER_OP(!=,double) | 1098 | ZORBA_REL_OP(!=,double) |
4580 | 1028 | ZORBA_INTEGER_OP(< ,double) | 1099 | ZORBA_REL_OP(< ,double) |
4581 | 1029 | ZORBA_INTEGER_OP(<=,double) | 1100 | ZORBA_REL_OP(<=,double) |
4582 | 1030 | ZORBA_INTEGER_OP(> ,double) | 1101 | ZORBA_REL_OP(> ,double) |
4583 | 1031 | ZORBA_INTEGER_OP(>=,double) | 1102 | ZORBA_REL_OP(>=,double) |
4584 | 1032 | #ifndef ZORBA_WITH_BIG_INTEGER | 1103 | #ifndef ZORBA_WITH_BIG_INTEGER |
4603 | 1033 | ZORBA_INTEGER_OP(==,long long) | 1104 | ZORBA_REL_OP(==,long long) |
4604 | 1034 | ZORBA_INTEGER_OP(!=,long long) | 1105 | ZORBA_REL_OP(!=,long long) |
4605 | 1035 | ZORBA_INTEGER_OP(< ,long long) | 1106 | ZORBA_REL_OP(< ,long long) |
4606 | 1036 | ZORBA_INTEGER_OP(<=,long long) | 1107 | ZORBA_REL_OP(<=,long long) |
4607 | 1037 | ZORBA_INTEGER_OP(> ,long long) | 1108 | ZORBA_REL_OP(> ,long long) |
4608 | 1038 | ZORBA_INTEGER_OP(>=,long long) | 1109 | ZORBA_REL_OP(>=,long long) |
4609 | 1039 | ZORBA_INTEGER_OP(==,unsigned long) | 1110 | ZORBA_REL_OP(==,unsigned long) |
4610 | 1040 | ZORBA_INTEGER_OP(!=,unsigned long) | 1111 | ZORBA_REL_OP(!=,unsigned long) |
4611 | 1041 | ZORBA_INTEGER_OP(< ,unsigned long) | 1112 | ZORBA_REL_OP(< ,unsigned long) |
4612 | 1042 | ZORBA_INTEGER_OP(<=,unsigned long) | 1113 | ZORBA_REL_OP(<=,unsigned long) |
4613 | 1043 | ZORBA_INTEGER_OP(> ,unsigned long) | 1114 | ZORBA_REL_OP(> ,unsigned long) |
4614 | 1044 | ZORBA_INTEGER_OP(>=,unsigned long) | 1115 | ZORBA_REL_OP(>=,unsigned long) |
4615 | 1045 | ZORBA_INTEGER_OP(==,unsigned long long) | 1116 | ZORBA_REL_OP(==,unsigned long long) |
4616 | 1046 | ZORBA_INTEGER_OP(!=,unsigned long long) | 1117 | ZORBA_REL_OP(!=,unsigned long long) |
4617 | 1047 | ZORBA_INTEGER_OP(< ,unsigned long long) | 1118 | ZORBA_REL_OP(< ,unsigned long long) |
4618 | 1048 | ZORBA_INTEGER_OP(<=,unsigned long long) | 1119 | ZORBA_REL_OP(<=,unsigned long long) |
4619 | 1049 | ZORBA_INTEGER_OP(> ,unsigned long long) | 1120 | ZORBA_REL_OP(> ,unsigned long long) |
4620 | 1050 | ZORBA_INTEGER_OP(>=,unsigned long long) | 1121 | ZORBA_REL_OP(>=,unsigned long long) |
4621 | 1051 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 1122 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4623 | 1052 | #undef ZORBA_INTEGER_OP | 1123 | #undef ZORBA_REL_OP |
4624 | 1053 | 1124 | ||
4625 | 1054 | ////////// miscellaneous ////////////////////////////////////////////////////// | 1125 | ////////// miscellaneous ////////////////////////////////////////////////////// |
4626 | 1055 | 1126 | ||
4627 | 1056 | #ifdef ZORBA_WITH_BIG_INTEGER | 1127 | #ifdef ZORBA_WITH_BIG_INTEGER |
4628 | 1057 | 1128 | ||
4630 | 1058 | inline int IntegerImpl::compare( IntegerImpl const &i ) const { | 1129 | template<class T> |
4631 | 1130 | inline int IntegerImpl<T>::compare( IntegerImpl<T> const &i ) const { | ||
4632 | 1059 | return value_.compare( i.value_ ); | 1131 | return value_.compare( i.value_ ); |
4633 | 1060 | } | 1132 | } |
4634 | 1061 | 1133 | ||
4636 | 1062 | inline bool IntegerImpl::is_xs_int() const { | 1134 | template<class T> |
4637 | 1135 | inline bool IntegerImpl<T>::is_xs_int() const { | ||
4638 | 1063 | return value_ >= MAPM::getMinInt32() && value_ <= MAPM::getMaxInt32(); | 1136 | return value_ >= MAPM::getMinInt32() && value_ <= MAPM::getMaxInt32(); |
4639 | 1064 | } | 1137 | } |
4640 | 1065 | 1138 | ||
4642 | 1066 | inline bool IntegerImpl::is_xs_long() const { | 1139 | template<class T> |
4643 | 1140 | inline bool IntegerImpl<T>::is_xs_long() const { | ||
4644 | 1067 | return value_ >= MAPM::getMinInt64() && value_ <= MAPM::getMaxInt64(); | 1141 | return value_ >= MAPM::getMinInt64() && value_ <= MAPM::getMaxInt64(); |
4645 | 1068 | } | 1142 | } |
4646 | 1069 | 1143 | ||
4648 | 1070 | inline int IntegerImpl::sign() const { | 1144 | template<class T> |
4649 | 1145 | inline int IntegerImpl<T>::sign() const { | ||
4650 | 1071 | return value_.sign(); | 1146 | return value_.sign(); |
4651 | 1072 | } | 1147 | } |
4652 | 1073 | 1148 | ||
4653 | 1074 | #else /* ZORBA_WITH_BIG_INTEGER */ | 1149 | #else /* ZORBA_WITH_BIG_INTEGER */ |
4654 | 1075 | 1150 | ||
4657 | 1076 | template<typename I> | 1151 | template<class T> |
4658 | 1077 | inline int IntegerImpl<I>::compare( IntegerImpl const &i ) const { | 1152 | inline int IntegerImpl<T>::compare( IntegerImpl<T> const &i ) const { |
4659 | 1078 | return value_ < i.value_ ? -1 : value_ > i.value_ ? 1 : 0; | 1153 | return value_ < i.value_ ? -1 : value_ > i.value_ ? 1 : 0; |
4660 | 1079 | } | 1154 | } |
4661 | 1080 | 1155 | ||
4664 | 1081 | template<typename I> | 1156 | template<class T> |
4665 | 1082 | inline uint32_t IntegerImpl<I>::hash() const { | 1157 | inline uint32_t IntegerImpl<T>::hash() const { |
4666 | 1083 | return static_cast<uint32_t>( value_ ); | 1158 | return static_cast<uint32_t>( value_ ); |
4667 | 1084 | } | 1159 | } |
4668 | 1085 | 1160 | ||
4671 | 1086 | template<typename I> | 1161 | template<class T> |
4672 | 1087 | inline bool IntegerImpl<I>::is_cxx_long() const { | 1162 | inline bool IntegerImpl<T>::is_cxx_long() const { |
4673 | 1088 | return ZORBA_IN_RANGE( value_, long ); | 1163 | return ZORBA_IN_RANGE( value_, long ); |
4674 | 1089 | } | 1164 | } |
4675 | 1090 | 1165 | ||
4678 | 1091 | template<typename I> | 1166 | template<class T> |
4679 | 1092 | inline bool IntegerImpl<I>::is_xs_byte() const { | 1167 | inline bool IntegerImpl<T>::is_xs_byte() const { |
4680 | 1093 | return ZORBA_IN_RANGE( value_, xs_byte ); | 1168 | return ZORBA_IN_RANGE( value_, xs_byte ); |
4681 | 1094 | } | 1169 | } |
4682 | 1095 | 1170 | ||
4685 | 1096 | template<typename I> | 1171 | template<class T> |
4686 | 1097 | inline bool IntegerImpl<I>::is_xs_int() const { | 1172 | inline bool IntegerImpl<T>::is_xs_int() const { |
4687 | 1098 | return ZORBA_IN_RANGE( value_, xs_int ); | 1173 | return ZORBA_IN_RANGE( value_, xs_int ); |
4688 | 1099 | } | 1174 | } |
4689 | 1100 | 1175 | ||
4692 | 1101 | template<typename I> | 1176 | template<class T> |
4693 | 1102 | inline bool IntegerImpl<I>::is_xs_long() const { | 1177 | inline bool IntegerImpl<T>::is_xs_long() const { |
4694 | 1103 | return ZORBA_IN_RANGE( value_, xs_long ); | 1178 | return ZORBA_IN_RANGE( value_, xs_long ); |
4695 | 1104 | } | 1179 | } |
4696 | 1105 | 1180 | ||
4699 | 1106 | template<typename I> | 1181 | template<class T> |
4700 | 1107 | inline bool IntegerImpl<I>::is_xs_short() const { | 1182 | inline bool IntegerImpl<T>::is_xs_short() const { |
4701 | 1108 | return ZORBA_IN_RANGE( value_, xs_short ); | 1183 | return ZORBA_IN_RANGE( value_, xs_short ); |
4702 | 1109 | } | 1184 | } |
4703 | 1110 | 1185 | ||
4706 | 1111 | template<typename I> | 1186 | template<class T> |
4707 | 1112 | inline bool IntegerImpl<I>::is_xs_unsignedByte() const { | 1187 | inline bool IntegerImpl<T>::is_xs_unsignedByte() const { |
4708 | 1113 | return ZORBA_IN_RANGE( value_, xs_unsignedByte ); | 1188 | return ZORBA_IN_RANGE( value_, xs_unsignedByte ); |
4709 | 1114 | } | 1189 | } |
4710 | 1115 | 1190 | ||
4713 | 1116 | template<typename I> | 1191 | template<class T> |
4714 | 1117 | inline bool IntegerImpl<I>::is_xs_unsignedInt() const { | 1192 | inline bool IntegerImpl<T>::is_xs_unsignedInt() const { |
4715 | 1118 | return ZORBA_IN_RANGE( value_, xs_unsignedInt ); | 1193 | return ZORBA_IN_RANGE( value_, xs_unsignedInt ); |
4716 | 1119 | } | 1194 | } |
4717 | 1120 | 1195 | ||
4720 | 1121 | template<typename I> | 1196 | template<class T> |
4721 | 1122 | inline bool IntegerImpl<I>::is_xs_unsignedLong() const { | 1197 | inline bool IntegerImpl<T>::is_xs_unsignedLong() const { |
4722 | 1123 | return ZORBA_IN_RANGE( value_, xs_unsignedLong ); | 1198 | return ZORBA_IN_RANGE( value_, xs_unsignedLong ); |
4723 | 1124 | } | 1199 | } |
4724 | 1125 | 1200 | ||
4727 | 1126 | template<typename I> | 1201 | template<class T> |
4728 | 1127 | inline bool IntegerImpl<I>::is_xs_unsignedShort() const { | 1202 | inline bool IntegerImpl<T>::is_xs_unsignedShort() const { |
4729 | 1128 | return ZORBA_IN_RANGE( value_, xs_unsignedShort ); | 1203 | return ZORBA_IN_RANGE( value_, xs_unsignedShort ); |
4730 | 1129 | } | 1204 | } |
4731 | 1130 | 1205 | ||
4734 | 1131 | template<typename I> | 1206 | template<class T> |
4735 | 1132 | inline int IntegerImpl<I>::sign() const { | 1207 | inline int IntegerImpl<T>::sign() const { |
4736 | 1133 | return ztd::lt0( value_ ) ? -1 : value_ > 0 ? 1 : 0; | 1208 | return ztd::lt0( value_ ) ? -1 : value_ > 0 ? 1 : 0; |
4737 | 1134 | } | 1209 | } |
4738 | 1135 | 1210 | ||
4739 | 1136 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 1211 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4740 | 1137 | 1212 | ||
4754 | 1138 | TEMPLATE_DECL(I) inline | 1213 | template<class T> |
4755 | 1139 | TEMPLATE_TYPENAME INTEGER_IMPL(I)::value_type& INTEGER_IMPL(I)::value() { | 1214 | inline typename IntegerImpl<T>::value_type& IntegerImpl<T>::value() { |
4756 | 1140 | return value_; | 1215 | return value_; |
4757 | 1141 | } | 1216 | } |
4758 | 1142 | 1217 | ||
4759 | 1143 | TEMPLATE_DECL(I) inline | 1218 | template<class T> |
4760 | 1144 | TEMPLATE_TYPENAME INTEGER_IMPL(I)::value_type const& | 1219 | inline typename IntegerImpl<T>::value_type const& |
4761 | 1145 | INTEGER_IMPL(I)::value() const { | 1220 | IntegerImpl<T>::value() const { |
4762 | 1146 | return value_; | 1221 | return value_; |
4763 | 1147 | } | 1222 | } |
4764 | 1148 | 1223 | ||
4765 | 1149 | TEMPLATE_DECL(I) | 1224 | template<class T> |
4766 | 1150 | inline std::ostream& operator<<( std::ostream &os, INTEGER_IMPL(I) const &i ) { | 1225 | inline std::ostream& operator<<( std::ostream &os, IntegerImpl<T> const &i ) { |
4767 | 1151 | return os << i.toString(); | 1226 | return os << i.toString(); |
4768 | 1152 | } | 1227 | } |
4769 | 1153 | 1228 | ||
4770 | @@ -1155,11 +1230,6 @@ | |||
4771 | 1155 | 1230 | ||
4772 | 1156 | } // namespace zorba | 1231 | } // namespace zorba |
4773 | 1157 | 1232 | ||
4774 | 1158 | #undef TEMPLATE_DECL | ||
4775 | 1159 | #undef INTEGER_IMPL | ||
4776 | 1160 | #undef INTEGER_IMPL_LL | ||
4777 | 1161 | #undef INTEGER_IMPL_ULL | ||
4778 | 1162 | |||
4779 | 1163 | #endif // ZORBA_INTEGER_H | 1233 | #endif // ZORBA_INTEGER_H |
4780 | 1164 | /* | 1234 | /* |
4781 | 1165 | * Local variables: | 1235 | * Local variables: |
4782 | 1166 | 1236 | ||
4783 | === modified file 'src/zorbatypes/numconversions.cpp' | |||
4784 | --- src/zorbatypes/numconversions.cpp 2013-03-22 19:06:44 +0000 | |||
4785 | +++ src/zorbatypes/numconversions.cpp 2013-05-08 15:05:31 +0000 | |||
4786 | @@ -15,11 +15,18 @@ | |||
4787 | 15 | */ | 15 | */ |
4788 | 16 | #include "stdafx.h" | 16 | #include "stdafx.h" |
4789 | 17 | 17 | ||
4790 | 18 | // standard | ||
4791 | 18 | #include <stdexcept> | 19 | #include <stdexcept> |
4792 | 19 | 20 | ||
4793 | 21 | // Zorba | ||
4794 | 20 | #include "common/common.h" | 22 | #include "common/common.h" |
4795 | 21 | #include "util/string_util.h" | 23 | #include "util/string_util.h" |
4797 | 22 | #include "zorbatypes/numconversions.h" | 24 | |
4798 | 25 | // local | ||
4799 | 26 | #include "decimal.h" | ||
4800 | 27 | #include "floatimpl.h" | ||
4801 | 28 | #include "integer.h" | ||
4802 | 29 | #include "numconversions.h" | ||
4803 | 23 | 30 | ||
4804 | 24 | namespace zorba { | 31 | namespace zorba { |
4805 | 25 | 32 | ||
4806 | 26 | 33 | ||
4807 | === modified file 'src/zorbatypes/numconversions.h' | |||
4808 | --- src/zorbatypes/numconversions.h 2013-03-22 19:06:44 +0000 | |||
4809 | +++ src/zorbatypes/numconversions.h 2013-05-08 15:05:31 +0000 | |||
4810 | @@ -64,6 +64,7 @@ | |||
4811 | 64 | */ | 64 | */ |
4812 | 65 | xs_long to_xs_long( xs_integer const &i ); | 65 | xs_long to_xs_long( xs_integer const &i ); |
4813 | 66 | 66 | ||
4814 | 67 | #if 0 | ||
4815 | 67 | #ifndef ZORBA_WITH_BIG_INTEGER | 68 | #ifndef ZORBA_WITH_BIG_INTEGER |
4816 | 68 | /** | 69 | /** |
4817 | 69 | * Converts an \c xs:nonNegativeInteger value to an \c xs:long. | 70 | * Converts an \c xs:nonNegativeInteger value to an \c xs:long. |
4818 | @@ -75,6 +76,7 @@ | |||
4819 | 75 | */ | 76 | */ |
4820 | 76 | xs_long to_xs_long( xs_nonNegativeInteger const &i ); | 77 | xs_long to_xs_long( xs_nonNegativeInteger const &i ); |
4821 | 77 | #endif /* ZORBA_WITH_BIG_INTEGER */ | 78 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4822 | 79 | #endif | ||
4823 | 78 | 80 | ||
4824 | 79 | /** | 81 | /** |
4825 | 80 | * Converts an \c xs:integer value to an \c xs:unsignedByte. | 82 | * Converts an \c xs:integer value to an \c xs:unsignedByte. |
4826 | 81 | 83 | ||
4827 | === added file 'src/zorbatypes/numeric_types.cpp' | |||
4828 | --- src/zorbatypes/numeric_types.cpp 1970-01-01 00:00:00 +0000 | |||
4829 | +++ src/zorbatypes/numeric_types.cpp 2013-05-08 15:05:31 +0000 | |||
4830 | @@ -0,0 +1,82 @@ | |||
4831 | 1 | /* | ||
4832 | 2 | * Copyright 2006-2008 The FLWOR Foundation. | ||
4833 | 3 | * | ||
4834 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4835 | 5 | * you may not use this file except in compliance with the License. | ||
4836 | 6 | * You may obtain a copy of the License at | ||
4837 | 7 | * | ||
4838 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
4839 | 9 | * | ||
4840 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
4841 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
4842 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
4843 | 13 | * See the License for the specific language governing permissions and | ||
4844 | 14 | * limitations under the License. | ||
4845 | 15 | */ | ||
4846 | 16 | |||
4847 | 17 | #include "stdafx.h" | ||
4848 | 18 | |||
4849 | 19 | // local | ||
4850 | 20 | #include "decimal.h" | ||
4851 | 21 | #include "floatimpl.h" | ||
4852 | 22 | #include "integer.h" | ||
4853 | 23 | |||
4854 | 24 | using namespace std; | ||
4855 | 25 | |||
4856 | 26 | namespace zorba { | ||
4857 | 27 | |||
4858 | 28 | /////////////////////////////////////////////////////////////////////////////// | ||
4859 | 29 | |||
4860 | 30 | template<class NumericType> | ||
4861 | 31 | NumericType const& numeric_consts<NumericType>::zero() { | ||
4862 | 32 | static NumericType const n(0); | ||
4863 | 33 | return n; | ||
4864 | 34 | } | ||
4865 | 35 | |||
4866 | 36 | template<class NumericType> | ||
4867 | 37 | NumericType const& numeric_consts<NumericType>::one() { | ||
4868 | 38 | static NumericType const n(1); | ||
4869 | 39 | return n; | ||
4870 | 40 | } | ||
4871 | 41 | |||
4872 | 42 | template<class NumericType> | ||
4873 | 43 | NumericType const& numeric_consts<NumericType>::neg_one() { | ||
4874 | 44 | static NumericType const n(-1); | ||
4875 | 45 | return n; | ||
4876 | 46 | } | ||
4877 | 47 | |||
4878 | 48 | // instantiate non-special cases | ||
4879 | 49 | template class numeric_consts<Decimal>; | ||
4880 | 50 | template class numeric_consts<Double>; | ||
4881 | 51 | template class numeric_consts<Float>; | ||
4882 | 52 | template class numeric_consts<Integer>; | ||
4883 | 53 | |||
4884 | 54 | NonNegativeInteger const& numeric_consts<NonNegativeInteger>::zero() { | ||
4885 | 55 | static NonNegativeInteger const n(0); | ||
4886 | 56 | return n; | ||
4887 | 57 | } | ||
4888 | 58 | |||
4889 | 59 | NonNegativeInteger const& numeric_consts<NonNegativeInteger>::one() { | ||
4890 | 60 | static NonNegativeInteger const n(1); | ||
4891 | 61 | return n; | ||
4892 | 62 | } | ||
4893 | 63 | |||
4894 | 64 | NonPositiveInteger const& numeric_consts<NonPositiveInteger>::zero() { | ||
4895 | 65 | static NonPositiveInteger const n(0); | ||
4896 | 66 | return n; | ||
4897 | 67 | } | ||
4898 | 68 | |||
4899 | 69 | NonPositiveInteger const& numeric_consts<NonPositiveInteger>::neg_one() { | ||
4900 | 70 | static NonPositiveInteger const n(-1); | ||
4901 | 71 | return n; | ||
4902 | 72 | } | ||
4903 | 73 | |||
4904 | 74 | PositiveInteger const& numeric_consts<PositiveInteger>::one() { | ||
4905 | 75 | static PositiveInteger const n(1); | ||
4906 | 76 | return n; | ||
4907 | 77 | } | ||
4908 | 78 | |||
4909 | 79 | /////////////////////////////////////////////////////////////////////////////// | ||
4910 | 80 | |||
4911 | 81 | } // namespace zorba | ||
4912 | 82 | /* vim:set et sw=2 ts=2: */ | ||
4913 | 0 | 83 | ||
4914 | === added file 'src/zorbatypes/numeric_types.h' | |||
4915 | --- src/zorbatypes/numeric_types.h 1970-01-01 00:00:00 +0000 | |||
4916 | +++ src/zorbatypes/numeric_types.h 2013-05-08 15:05:31 +0000 | |||
4917 | @@ -0,0 +1,106 @@ | |||
4918 | 1 | /* | ||
4919 | 2 | * Copyright 2006-2008 The FLWOR Foundation. | ||
4920 | 3 | * | ||
4921 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
4922 | 5 | * you may not use this file except in compliance with the License. | ||
4923 | 6 | * You may obtain a copy of the License at | ||
4924 | 7 | * | ||
4925 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
4926 | 9 | * | ||
4927 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
4928 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
4929 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
4930 | 13 | * See the License for the specific language governing permissions and | ||
4931 | 14 | * limitations under the License. | ||
4932 | 15 | */ | ||
4933 | 16 | |||
4934 | 17 | #pragma once | ||
4935 | 18 | #ifndef ZORBA_NUMERIC_CONSTS_H | ||
4936 | 19 | #define ZORBA_NUMERIC_CONSTS_H | ||
4937 | 20 | |||
4938 | 21 | namespace zorba { | ||
4939 | 22 | |||
4940 | 23 | /////////////////////////////////////////////////////////////////////////////// | ||
4941 | 24 | |||
4942 | 25 | class integer_traits; | ||
4943 | 26 | class negative_traits; | ||
4944 | 27 | class nonNegative_traits; | ||
4945 | 28 | class nonPositive_traits; | ||
4946 | 29 | class positive_traits; | ||
4947 | 30 | |||
4948 | 31 | template<class T> class IntegerImpl; | ||
4949 | 32 | typedef IntegerImpl<integer_traits> Integer; | ||
4950 | 33 | typedef IntegerImpl<negative_traits> NegativeInteger; | ||
4951 | 34 | typedef IntegerImpl<nonNegative_traits> NonNegativeInteger; | ||
4952 | 35 | typedef IntegerImpl<nonPositive_traits> NonPositiveInteger; | ||
4953 | 36 | typedef IntegerImpl<positive_traits> PositiveInteger; | ||
4954 | 37 | |||
4955 | 38 | class Decimal; | ||
4956 | 39 | |||
4957 | 40 | template<typename F> class FloatImpl; | ||
4958 | 41 | typedef FloatImpl<float> Float; | ||
4959 | 42 | typedef FloatImpl<double> Double; | ||
4960 | 43 | |||
4961 | 44 | /** | ||
4962 | 45 | * This contains references to singleton objects having constant values for the | ||
4963 | 46 | * often-used numeric constants -1, 0, and +1. | ||
4964 | 47 | * | ||
4965 | 48 | * @tparam NumericType One of Integer, NegativeInteger, NonNegativeInteger, | ||
4966 | 49 | * NonPositiveInteger, PositiveInteger, Decimal, Float, or Double. | ||
4967 | 50 | */ | ||
4968 | 51 | template<class NumericType> | ||
4969 | 52 | struct numeric_consts { | ||
4970 | 53 | static NumericType const& neg_one(); | ||
4971 | 54 | static NumericType const& zero(); | ||
4972 | 55 | static NumericType const& one(); | ||
4973 | 56 | }; | ||
4974 | 57 | |||
4975 | 58 | /** | ||
4976 | 59 | * Specialization for NegativeInteger that has only a reference to a singleton | ||
4977 | 60 | * object having the constant value -1. | ||
4978 | 61 | */ | ||
4979 | 62 | template<> | ||
4980 | 63 | struct numeric_consts<NegativeInteger> { | ||
4981 | 64 | static NegativeInteger const& neg_one(); | ||
4982 | 65 | }; | ||
4983 | 66 | |||
4984 | 67 | /** | ||
4985 | 68 | * Specialization for NonNegativeInteger that has only references to the | ||
4986 | 69 | * singleton objects having the constant values 0 and 1. | ||
4987 | 70 | */ | ||
4988 | 71 | template<> | ||
4989 | 72 | struct numeric_consts<NonNegativeInteger> { | ||
4990 | 73 | static NonNegativeInteger const& zero(); | ||
4991 | 74 | static NonNegativeInteger const& one(); | ||
4992 | 75 | }; | ||
4993 | 76 | |||
4994 | 77 | /** | ||
4995 | 78 | * Specialization for NonPositiveInteger that has only references to the | ||
4996 | 79 | * singleton objects having the constant values -1 and 0. | ||
4997 | 80 | */ | ||
4998 | 81 | template<> | ||
4999 | 82 | struct numeric_consts<NonPositiveInteger> { | ||
5000 | 83 | static NonPositiveInteger const& neg_one(); |
Validation queue starting for merge proposal. zorbatest. lambda. nu:8080/ remotequeue/ bug-1090089- 2013-04- 30T14-52- 16.682Z/ log.html
Log at: http://