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

Proposed by Paul J. Lucas on 2013-05-09
Status: Merged
Approved by: Paul J. Lucas on 2013-05-15
Approved revision: 11473
Merged at revision: 11451
Proposed branch: lp:~paul-lucas/zorba/bug-1090089
Merge into: lp:zorba
Diff against target: 896 lines (+218/-189)
34 files modified
src/compiler/parser/symbol_table.cpp (+0/-2)
src/diagnostics/diagnostic_en.xml (+2/-2)
src/diagnostics/pregenerated/dict_en.cpp (+1/-1)
src/functions/func_sequences_impl.cpp (+5/-5)
src/types/casting.cpp (+54/-7)
src/zorbatypes/decimal.cpp (+71/-104)
src/zorbatypes/floatimpl.cpp (+34/-43)
src/zorbatypes/integer.cpp (+16/-18)
src/zorbatypes/integer.h (+11/-5)
test/fots/CMakeLists.txt (+0/-2)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-01.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-02.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-03.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-04.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-05.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-06.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-07.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-08.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-09.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-10.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-11.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/numerics/xs_float-12.xml.res (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-01.xq (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-02.xq (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-03.xq (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-04.xq (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-05.xq (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-06.xq (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-07.xq (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-08.xq (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-09.xq (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-10.xq (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-11.xq (+1/-0)
test/rbkt/Queries/zorba/numerics/xs_float-12.xq (+1/-0)
To merge this branch: bzr merge lp:~paul-lucas/zorba/bug-1090089
Reviewer Review Type Date Requested Status
Matthias Brantner 2013-05-14 Approve on 2013-05-15
Paul J. Lucas Approve on 2013-05-09
Review via email: mp+163085@code.launchpad.net

Commit message

Rewrote decimal reduction code -- fixes rounding and FOTS distinct-values tests.

Description of the change

Rewrote decimal reduction code -- fixes rounding and FOTS distinct-values tests.

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

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

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

  28 tests did not succeed - changes not commited.

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

Zorba Build Bot (zorba-buildbot) wrote :

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

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

  14 tests did not succeed - changes not commited.

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

Zorba Build Bot (zorba-buildbot) wrote :

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

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

  5 tests did not succeed - changes not commited.

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

Zorba Build Bot (zorba-buildbot) wrote :

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

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

  3 tests did not succeed - changes not commited.

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

Paul J. Lucas (paul-lucas) wrote :

Note: even though FOTS test orderBy52a now fails, I think it worked before by "accident." The code is more consistent now, so orderBy52a now fails in the same way that the other FOTS orderBy tests fail.

Zorba Build Bot (zorba-buildbot) wrote :

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

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

  5 tests did not succeed - changes not commited.

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

Zorba Build Bot (zorba-buildbot) wrote :

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

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

  4 tests did not succeed - changes not commited.

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

Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1090089-2013-05-14T18-46-51.049Z is finished. The final status was:

All tests succeeded!

Zorba Build Bot (zorba-buildbot) wrote :

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

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

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

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

  1 tests did not succeed - changes not commited.

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

Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1090089-2013-05-15T15-42-59.231Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/compiler/parser/symbol_table.cpp'
2--- src/compiler/parser/symbol_table.cpp 2013-05-09 18:03:47 +0000
3+++ src/compiler/parser/symbol_table.cpp 2013-05-14 23:54:28 +0000
4@@ -242,7 +242,6 @@
5 return new xs_decimal(text);
6 }
7
8-// Will return NULL if std::range_error is raised
9 xs_double* symbol_table::doubleval(char const* text, size_t length)
10 {
11 try {
12@@ -253,7 +252,6 @@
13 }
14 }
15
16-// Will return NULL if std::range_error is raised
17 xs_integer* symbol_table::integerval(char const* text, size_t length)
18 {
19 try {
20
21=== modified file 'src/diagnostics/diagnostic_en.xml'
22--- src/diagnostics/diagnostic_en.xml 2013-05-04 21:54:40 +0000
23+++ src/diagnostics/diagnostic_en.xml 2013-05-14 23:54:28 +0000
24@@ -1301,9 +1301,9 @@
25
26 <diagnostic code="FOCA0003">
27 <comment>
28- Input value too large for integer.
29+ Input value too large for integer.
30 </comment>
31- <value>"$1": value too large for integer</value>
32+ <value>"$1": value${ of type 2} too large for $3?3:{integer}</value>
33 </diagnostic>
34
35 <diagnostic code="FOCA0005">
36
37=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
38--- src/diagnostics/pregenerated/dict_en.cpp 2013-05-04 21:54:40 +0000
39+++ src/diagnostics/pregenerated/dict_en.cpp 2013-05-14 23:54:28 +0000
40@@ -32,7 +32,7 @@
41 { "FOAR0002", "numeric operation overflow/underflow${: 1}" },
42 { "FOCA0001", "\"$1\": value too large for decimal" },
43 { "FOCA0002", "$1" },
44- { "FOCA0003", "\"$1\": value too large for integer" },
45+ { "FOCA0003", "\"$1\": value${ of type 2} too large for $3?3:{integer}" },
46 { "FOCA0005", "NaN supplied as float/double value" },
47 { "FOCA0006", "\"$1\": string to be cast to decimal has too many digits of precision" },
48 { "FOCH0001", "\"$1\": invalid code point" },
49
50=== modified file 'src/functions/func_sequences_impl.cpp'
51--- src/functions/func_sequences_impl.cpp 2013-03-24 20:40:03 +0000
52+++ src/functions/func_sequences_impl.cpp 2013-05-14 23:54:28 +0000
53@@ -79,7 +79,7 @@
54 pos = to_xs_long(ipos);
55 }
56 }
57- catch (std::range_error&)
58+ catch (std::exception const&)
59 {
60 return false;
61 }
62@@ -601,7 +601,7 @@
63 pos = to_xs_long(ipos);
64 len = to_xs_long(ilen);
65 }
66- catch (std::range_error&)
67+ catch (std::range_error const&)
68 {
69 goto done;
70 }
71@@ -791,7 +791,7 @@
72 {
73 store::Item* posItem = static_cast<const const_expr*>(posExpr)->get_val();
74
75- xs_integer pos = posItem->getIntegerValue();;
76+ xs_integer pos( posItem->getIntegerValue() );
77
78 if (inputExpr->get_expr_kind() == relpath_expr_kind)
79 {
80@@ -799,14 +799,14 @@
81
82 csize numSteps = pathExpr->numSteps();
83
84- if (pos > Integer(0) && numSteps == 2)
85+ if (pos.sign() > 0 && numSteps == 2)
86 {
87 xs_long pos2;
88 try
89 {
90 pos2 = posItem->getLongValue();
91 }
92- catch (std::range_error&)
93+ catch (std::range_error const&)
94 {
95 goto done;
96 }
97
98=== modified file 'src/types/casting.cpp'
99--- src/types/casting.cpp 2013-05-09 00:21:51 +0000
100+++ src/types/casting.cpp 2013-05-14 23:54:28 +0000
101@@ -148,6 +148,45 @@
102 }
103
104
105+void throwFOCA0003Exception(const zstring& str, const ErrorInfo& info)
106+{
107+ if (info.theSourceType)
108+ {
109+ throw XQUERY_EXCEPTION(
110+ err::FOCA0003,
111+ ERROR_PARAMS(
112+ str,
113+ info.theSourceType->toSchemaString(),
114+ info.theTargetType->toSchemaString()
115+ ),
116+ ERROR_LOC( info.theLoc )
117+ );
118+ }
119+ else
120+ {
121+ TypeManager& tm = GENV_TYPESYSTEM;
122+
123+ xqtref_t sourceType =
124+ tm.create_builtin_atomic_type(info.theSourceTypeCode,
125+ TypeConstants::QUANT_ONE);
126+
127+ xqtref_t targetType =
128+ tm.create_builtin_atomic_type(info.theTargetTypeCode,
129+ TypeConstants::QUANT_ONE);
130+
131+ throw XQUERY_EXCEPTION(
132+ err::FOCA0003,
133+ ERROR_PARAMS(
134+ str,
135+ sourceType->toSchemaString(),
136+ targetType->toSchemaString()
137+ ),
138+ ERROR_LOC( info.theLoc )
139+ );
140+ }
141+}
142+
143+
144 void throwFORG0001Exception(const zstring& str, const ErrorInfo& info)
145 {
146 if (info.theTargetType)
147@@ -375,14 +414,14 @@
148 {
149 try
150 {
151- const xs_nonNegativeInteger n(strval.c_str());
152+ xs_nonNegativeInteger const n(strval.c_str());
153 aFactory->createNonNegativeInteger(result, n);
154 }
155- catch (const std::invalid_argument& )
156+ catch ( std::invalid_argument const& )
157 {
158 throwFORG0001Exception(strval, errInfo);
159 }
160- catch (const std::range_error& )
161+ catch ( std::range_error const& )
162 {
163 RAISE_ERROR(err::FOAR0002, errInfo.theLoc, ERROR_PARAMS(strval));
164 }
165@@ -954,13 +993,17 @@
166
167 T1_TO_T2(flt, int)
168 {
169+ xs_float const f( aItem->getFloatValue() );
170+ if ( !f.isFinite() )
171+ throwFOCA0002Exception(aItem->getStringValue(), errInfo);
172 try
173 {
174- aFactory->createInteger(result, xs_integer(aItem->getFloatValue()));
175+ xs_integer const n( f );
176+ aFactory->createInteger(result, n);
177 }
178 catch (const std::exception&)
179 {
180- throwFOCA0002Exception(aItem->getStringValue(), errInfo);
181+ throwFOCA0003Exception(aItem->getStringValue(), errInfo);
182 }
183 }
184
185@@ -1007,13 +1050,17 @@
186
187 T1_TO_T2(dbl, int)
188 {
189+ xs_double const d( aItem->getDoubleValue() );
190+ if ( !d.isFinite() )
191+ throwFOCA0002Exception(aItem->getStringValue(), errInfo);
192 try
193 {
194- aFactory->createInteger(result, xs_integer(aItem->getDoubleValue()));
195+ xs_integer const n( d );
196+ aFactory->createInteger(result, n);
197 }
198 catch (const std::exception& )
199 {
200- throwFOCA0002Exception(aItem->getStringValue(), errInfo);
201+ throwFOCA0003Exception(aItem->getStringValue(), errInfo);
202 }
203 }
204
205
206=== modified file 'src/zorbatypes/decimal.cpp'
207--- src/zorbatypes/decimal.cpp 2013-05-09 00:21:51 +0000
208+++ src/zorbatypes/decimal.cpp 2013-05-14 23:54:28 +0000
209@@ -27,6 +27,8 @@
210 #include "integer.h"
211 #include "numconversions.h"
212
213+using namespace std;
214+
215 namespace zorba {
216
217 ///////////////////////////////////////////////////////////////////////////////
218@@ -35,7 +37,7 @@
219
220 void Decimal::parse( char const *s, value_type *result, int parse_options ) {
221 if ( !*s )
222- throw std::invalid_argument( "empty string" );
223+ throw invalid_argument( "empty string" );
224
225 s = ascii::trim_start_space( s );
226 char const *const first_non_ws = s;
227@@ -58,13 +60,11 @@
228 ++s;
229 }
230 if ( *s )
231- throw std::invalid_argument(
232- BUILD_STRING( '"', *s, "\": invalid character" )
233- );
234+ throw invalid_argument( BUILD_STRING( '"', *s, "\": invalid character" ) );
235
236 if ( first_trailing_ws ) {
237 ptrdiff_t const size = first_trailing_ws - first_non_ws;
238- char *const copy = std::strncpy( new char[ size + 1 ], first_non_ws, size );
239+ char *const copy = ::strncpy( new char[ size + 1 ], first_non_ws, size );
240 copy[ size ] = '\0';
241 *result = copy;
242 delete[] copy;
243@@ -73,98 +73,66 @@
244 }
245
246 /**
247- * Remove trailing .99999 or .000001.
248- * Find four or five consecutive 9 or 0 after decimal point and eliminate them.
249+ * Rounds .xxx9999xxx or .xxx000000xxx.
250 */
251 void Decimal::reduce( char *s ) {
252- char *dot = strrchr( s, '.' );
253- if ( !dot ) // not a floating point number
254+ char *const dot = ::strrchr( s, '.' );
255+ if ( !dot ) // not a floating-point number
256 return;
257
258 bool has_e = false;
259- char *e = strrchr( s, 'E' );
260- if ( !e )
261- e = strrchr( s, 'e' );
262- if ( !e )
263- e = s + strlen( s );
264+ char *e = ::strpbrk( s, "eE" );
265+ if ( !e )
266+ e = s + ::strlen( s ); // eliminates a special-case
267 else
268 has_e = true;
269-
270- char *digits = e - 1;
271- for ( int pos = (int)(digits - dot); pos > 8; --pos, --digits ) {
272- if ( *digits == '9' ) {
273- if ( digits[-1] == '9' && digits[-2] == '9' && digits[-3] == '9' ) {
274- if ( ascii::is_digit( digits[1] ) && digits[1] >= '5' )
275- digits -= 4;
276- else if ( digits[-4] == '9' )
277- digits -= 5;
278- else
279- continue;
280-
281- // now add 1 to remaining digits
282- char *last_digit = digits;
283- while ( digits >= s ) {
284- if ( digits[0] == '.' ) {
285- // skip
286- } else if ( digits[0] == '9' ) {
287- digits[0] = '0';
288- if ( last_digit == digits )
289- --last_digit;
290- } else {
291- if ( ascii::is_digit( digits[0] ) )
292- digits[0]++;
293- break;
294- }
295- --digits;
296- }
297- if ( last_digit[0] != '.' )
298- ++last_digit;
299- else if ( has_e ) {
300- last_digit[1] = '0';
301- last_digit += 2;
302- }
303- if ( digits < s || !ascii::is_digit( digits[0] ) ) {
304- memmove( s + 1, s, last_digit - s );
305- ++last_digit;
306- if ( ascii::is_digit( s[0] ) )
307- s[0] = '1';
308- else
309- s[1] = '1';
310- if ( has_e ) { // increment the exponent
311- ++dot;
312- dot[0] = dot[-1];
313- dot[-1] = '.';
314- sprintf( e + 1, "%d", atoi( e + 1 ) + 1 );
315- --last_digit;
316- }
317- }
318- int const e_len = strlen( e );
319- memmove( last_digit, e, e_len );
320- last_digit[ e_len ] = 0;
321- break;
322- }
323- } else if ( *digits == '0' ) {
324- if ( digits[-1] == '0' && digits[-2] == '0' && digits[-3] == '0' ) {
325- if ( ascii::is_digit( digits[1] ) && digits[1] < '5' )
326- digits -= 4;
327- else if ( digits[-4] == '0' )
328- digits -= 5;
329- else
330- continue;
331- while ( *digits == '0' )
332- --digits;
333- if ( *digits != '.' )
334- ++digits;
335- else if ( has_e ) {
336- digits[1] = '0';
337- digits += 2;
338- }
339- int const e_len = strlen( e );
340- memmove( digits, e, e_len );
341- digits[ e_len ] = '\0';
342- break;
343- }
344- }
345+ char *digit = e - 1;
346+
347+ if ( ::strncmp( dot + 1, "9999", 3 ) == 0 ) {
348+ // The "leading nines" case, e.g., 12.9999[34][E56]
349+ if ( has_e ) {
350+ ::memmove( dot + 2, e, strlen( e ) + 1 );
351+ dot[1] = '0';
352+ } else
353+ ::memmove( dot, e, strlen( e ) + 1 );
354+ digit = dot - 1;
355+ char const *const first = *s == '-' ? s + 1 : s;
356+ while ( true ) {
357+ if ( *digit == '9' ) {
358+ *digit = '0';
359+ if ( digit == first ) {
360+ // slide to the right to insert a leading '1'
361+ ::memmove( digit + 1, digit, strlen( digit ) + 1 );
362+ *digit = '1';
363+ break;
364+ }
365+ --digit;
366+ } else {
367+ ++digit[0]; // e.g., 12 => 13
368+ break;
369+ }
370+ }
371+ return;
372+ }
373+
374+ if ( char *const nines = ::strstr( dot + 1, "9999" ) ) {
375+ // The "in-the-middle nines" case, e.g., 12.349999[56][E78]
376+ ++nines[-1]; // e.g., .xxx19 => .xxx29
377+ ::memmove( nines, e, strlen( e ) + 1 );
378+ return;
379+ }
380+
381+ if ( char *zeros = ::strstr( dot + 1, "000000" ) ) {
382+ // The "zeros" case, e.g., 12.0000003, 12.340000005.
383+ if ( zeros == dot + 1 && has_e )
384+ ++zeros; // leave one 0 after . and before E
385+ ::memmove( zeros, e, strlen( e ) + 1 );
386+ if ( !has_e ) {
387+ char *const last = s + ::strlen( s ) - 1;
388+ if ( *last == '.' )
389+ *last = '\0';
390+ }
391+ return;
392 }
393 }
394
395@@ -189,7 +157,7 @@
396 if ( f != f ||
397 f == std::numeric_limits<float>::infinity() ||
398 f == -std::numeric_limits<float>::infinity() )
399- throw std::invalid_argument( "float value = infinity" );
400+ throw invalid_argument( "float value = infinity" );
401 value_ = f;
402 }
403
404@@ -197,19 +165,19 @@
405 if ( d != d ||
406 d == std::numeric_limits<double>::infinity() ||
407 d == -std::numeric_limits<double>::infinity() )
408- throw std::invalid_argument( "double value = infinity" );
409+ throw invalid_argument( "double value = infinity" );
410 value_ = d;
411 }
412
413 Decimal::Decimal( Double const &d ) {
414 if ( !d.isFinite() )
415- throw std::invalid_argument( "double value = infinity" );
416+ throw invalid_argument( "double value = infinity" );
417 value_ = d.getNumber();
418 }
419
420 Decimal::Decimal( Float const &f ) {
421 if ( !f.isFinite() )
422- throw std::invalid_argument( "float value = infinity" );
423+ throw invalid_argument( "float value = infinity" );
424 value_ = f.getNumber();
425 }
426
427@@ -252,14 +220,14 @@
428
429 Decimal& Decimal::operator=( Double const &d ) {
430 if ( !d.isFinite() )
431- throw std::invalid_argument( "not finite" );
432+ throw invalid_argument( "not finite" );
433 value_ = d.getNumber();
434 return *this;
435 }
436
437 Decimal& Decimal::operator=( Float const &f ) {
438 if ( !f.isFinite() )
439- throw std::invalid_argument( "not finite" );
440+ throw invalid_argument( "not finite" );
441 value_ = f.getNumber();
442 return *this;
443 }
444@@ -389,7 +357,7 @@
445 if ( value >= MAPM::getMinInt64() ) {
446 // hash it as int64
447 value.toIntegerString( bufp );
448- std::stringstream ss( bufp );
449+ stringstream ss( bufp );
450 int64_t n;
451 ss >> n;
452 assert( ss.eof() );
453@@ -400,7 +368,7 @@
454 } else if ( value <= MAPM::getMaxUInt64() ) {
455 // hash it as uint64
456 value.toIntegerString( bufp );
457- std::stringstream ss( bufp );
458+ stringstream ss( bufp );
459 uint64_t n;
460 ss >> n;
461 assert( ss.eof() );
462@@ -411,7 +379,7 @@
463
464 // In all other cases, hash it as double
465 value.toFixPtString( bufp, ZORBA_FLOAT_POINT_PRECISION );
466- std::stringstream ss( bufp );
467+ stringstream ss( bufp );
468 double n;
469 ss >> n;
470 assert( ss.eof() );
471@@ -422,7 +390,7 @@
472
473 zstring Decimal::toString( value_type const &value, bool minusZero,
474 int precision ) {
475- char buf[ 1024 ];
476+ char buf[ 2048 ];
477
478 if ( minusZero ) {
479 if ( value.sign() == 0 )
480@@ -440,10 +408,9 @@
481 //
482 if ( strchr( buf, '.' ) != 0 ) {
483 // remove trailing 0's
484- char *last = buf + strlen( buf ) - 1;
485- while ( *last == '0' && last > buf )
486- *last-- = '\0';
487-
488+ char *last = buf + strlen( buf );
489+ while ( *--last == '0' )
490+ *last = '\0';
491 if ( *last == '.' ) // remove '.' if no digits after it
492 *last = '\0';
493 }
494
495=== modified file 'src/zorbatypes/floatimpl.cpp'
496--- src/zorbatypes/floatimpl.cpp 2013-05-09 00:21:51 +0000
497+++ src/zorbatypes/floatimpl.cpp 2013-05-14 23:54:28 +0000
498@@ -130,7 +130,7 @@
499 } else if ( strncmp( s, "NaN", 3 ) == 0 ) {
500 value_ = FloatImpl<FloatType>::nan().value_;
501 s += 3;
502- } else if ( strncmp( s, "+INF", 4 ) == 0 ) {
503+ } else if ( strncmp( s, "+INF", 4 ) == 0 ) { // allowed by XSD 1.1
504 value_ = FloatImpl<FloatType>::pos_inf().value_;
505 s += 4;
506 } else
507@@ -351,11 +351,7 @@
508 return "0";
509 if ( isNegZero() )
510 return "-0";
511-
512- // TODO: make xs_int
513- char buf[174];
514- sprintf( buf, "%d", (int)value_ );
515- return buf;
516+ return ztd::to_string( static_cast<long long>( value_ ) );
517 }
518
519 template<typename F>
520@@ -379,9 +375,9 @@
521 #if 1
522 // This is the "spec" implementation, i.e., it is an exact application of
523 // the spec in http://www.w3.org/TR/xpath-functions/#casting
524- MAPM decimal_mapm( value_ );
525- decimal_mapm = decimal_mapm.round( precision_ );
526- return Decimal::toString( decimal_mapm, isNegZero(), max_precision() );
527+ MAPM temp( value_ );
528+ temp = temp.round( precision_ );
529+ return Decimal::toString( temp, isNegZero(), max_precision() );
530 #else
531 std::stringstream stream;
532 stream.precision(7);
533@@ -410,42 +406,37 @@
534 return result;
535 #endif
536 } else {
537- char format[15];
538- sprintf( format, "%%#1.%dE", static_cast<int>( precision_ ) );
539-
540 char buf[174];
541- sprintf( buf, format, static_cast<double>( value_ ) );
542-
543- char *e = strchr( buf, 'E' );
544- char *zeros = e ? e - 1 : buf + strlen( buf ) - 1;
545-
546- while ( *zeros == '0' )
547- --zeros;
548-
549- if ( e ) {
550- if ( *zeros == '.' )
551- ++zeros;
552-
553- zeros[1] = 'E';
554+ sprintf( buf, "%#1.*E", (int)precision_, (double)value_ );
555+ char *e = ::strchr( buf, 'E' );
556+
557+ //
558+ // Clean-up, part 1: remove trailing zeros from mantissa
559+ // e.g.: xx.xx12300Exx => xx.xx123Exx
560+ //
561+ char *zero = e - 1;
562+ while ( *zero == '0' && zero[-1] != '.' )
563+ --zero;
564+ if ( zero < e - 1 )
565+ ::memmove( zero + 1, e, strlen( e ) + 1 );
566+
567+ //
568+ // Clean-up, part 2: remove '+' and leading '0' from exponent
569+ // e.g: 1E+xx => 1Exx, 1E-0x => 1E-x
570+ //
571+ e = ::strchr( buf, 'E' );
572+ char *dest = ++e;
573+ switch ( *e ) {
574+ case '-':
575+ ++dest;
576+ // no break;
577+ case '+':
578+ ++e;
579+ }
580+ if ( *e == '0' )
581 ++e;
582-
583- if ( *e == '+' )
584- ++e;
585- else if ( *e == '-' ) {
586- ++zeros;
587- zeros[1] = '-';
588- ++e;
589- }
590-
591- while ( *e == '0' )
592- ++e;
593-
594- memmove( (void*)(zeros + 2), e, strlen( e ) + 1 );
595- } else {
596- if ( *zeros == '.' )
597- --zeros;
598- zeros[1] = '\0';
599- }
600+ if ( dest < e )
601+ ::memmove( dest, e, strlen( e ) + 1 );
602
603 Decimal::reduce( buf );
604 return buf;
605
606=== modified file 'src/zorbatypes/integer.cpp'
607--- src/zorbatypes/integer.cpp 2013-05-07 00:39:46 +0000
608+++ src/zorbatypes/integer.cpp 2013-05-14 23:54:28 +0000
609@@ -19,7 +19,6 @@
610 // standard
611 #include <cerrno>
612 #include <cstdlib>
613-#include <sstream>
614
615 // Zorba
616 #include <zorba/internal/unique_ptr.h>
617@@ -38,12 +37,6 @@
618
619 ///////////////////////////////////////////////////////////////////////////////
620
621-ostream& operator<<( ostream &o, MAPM const &m ) {
622- unique_ptr<char[]> const buf( new char[ m.exponent() + 3 ] );
623- m.toIntegerString( buf.get() );
624- return o << buf.get();
625-}
626-
627 void integer_traits::throw_error( string const &what, bool throw_range_error ) {
628 if ( throw_range_error )
629 throw range_error( what );
630@@ -52,27 +45,32 @@
631
632 void integer_traits::throw_error( MAPM const &n, char const *op,
633 bool throw_range_error ) {
634- ostringstream oss;
635- oss << n;
636- string const what( BUILD_STRING( oss.str(), ": not ", op, " 0" ) );
637+ unique_ptr<char[]> const buf( new char[ n.exponent() + 3 ] );
638+ n.toIntegerString( buf.get() );
639+ string const what( BUILD_STRING( buf.get(), ": not ", op, " 0" ) );
640 throw_error( what, throw_range_error );
641 }
642
643 ///////////////////////////////////////////////////////////////////////////////
644
645+#ifndef ZORBA_WITH_BIG_INTEGER
646+template<class T>
647+typename IntegerImpl<T>::value_type IntegerImpl<T>::ftoi( double d ) {
648+ value_type const v( d >= 0 ? floor( d ) : ceil( d ) );
649+ if ( v < 0 && d > 0 )
650+ throw range_error(
651+ BUILD_STRING( '"', d, "\": value too large for integer" )
652+ );
653+ return v;
654+}
655+#endif /* ZORBA_WITH_BIG_INTEGER */
656+
657 template<class T>
658 void IntegerImpl<T>::parse( char const *s, bool throw_range_error ) {
659 #ifdef ZORBA_WITH_BIG_INTEGER
660 Decimal::parse( s, &value_, Decimal::parse_integer );
661 #else
662- try {
663- value_ = ztd::aton<value_type>( s );
664- }
665- catch ( std::range_error const &e ) {
666- if ( throw_range_error )
667- throw;
668- throw invalid_argument( e.what() );
669- }
670+ value_ = ztd::aton<value_type>( s );
671 #endif /* ZORBA_WITH_BIG_INTEGER */
672 T::check_value( value_, throw_range_error );
673 }
674
675=== modified file 'src/zorbatypes/integer.h'
676--- src/zorbatypes/integer.h 2013-05-07 00:39:46 +0000
677+++ src/zorbatypes/integer.h 2013-05-14 23:54:28 +0000
678@@ -50,8 +50,6 @@
679
680 ///////////////////////////////////////////////////////////////////////////////
681
682-std::ostream& operator<<( std::ostream&, MAPM const& );
683-
684 struct integer_traits {
685 static int const default_value = 0;
686
687@@ -138,6 +136,8 @@
688 }
689 };
690
691+///////////////////////////////////////////////////////////////////////////////
692+
693 template<class TraitsType>
694 class IntegerImpl {
695 public:
696@@ -199,6 +199,8 @@
697 *
698 * @tparam TraitsType2 The traits type of \a i.
699 * @param i The %IntegerImpl to copy from.
700+ * @throw std::invalid_argument if \a i contains a value that is invalid for
701+ * this type of integer.
702 */
703 template<class TraitsType2>
704 IntegerImpl( IntegerImpl<TraitsType2> const &i );
705@@ -212,6 +214,8 @@
706 * @tparam TraitsType2 The traits type of \a i.
707 * @param i The %IntegerImpl to assign from.
708 * @return Returns \c *this.
709+ * @throw std::invalid_argument if \a i contains a value that is invalid for
710+ * this type of integer.
711 */
712 template<class TraitsType2>
713 IntegerImpl& operator=( IntegerImpl<TraitsType2> const &i );
714@@ -552,13 +556,13 @@
715
716 value_type value_;
717
718+#ifdef ZORBA_WITH_BIG_INTEGER
719+ IntegerImpl( value_type const &v ) : value_( v ) { }
720+
721 static value_type ftoi( double d ) {
722 return value_type( d >= 0 ? floor( d ) : ceil( d ) );
723 }
724
725-#ifdef ZORBA_WITH_BIG_INTEGER
726- IntegerImpl( value_type const &v ) : value_( v ) { }
727-
728 static value_type ftoi( MAPM const &d ) {
729 return d.sign() >= 0 ? d.floor() : d.ceil();
730 }
731@@ -573,6 +577,8 @@
732 }
733 #else /* ZORBA_WITH_BIG_INTEGER */
734
735+ static value_type ftoi( double d );
736+
737 static value_type ftoi( value_type v ) {
738 return v; // intentional no-op
739 }
740
741=== modified file 'test/fots/CMakeLists.txt'
742--- test/fots/CMakeLists.txt 2013-05-08 20:14:47 +0000
743+++ test/fots/CMakeLists.txt 2013-05-14 23:54:28 +0000
744@@ -157,8 +157,6 @@
745 EXPECTED_FOTS_FAILURE (fn-available-environment-variables fn-available-environment-variables-011 0)
746 EXPECTED_FOTS_FAILURE (fn-deep-equal K2-SeqDeepEqualFunc-36 0)
747 EXPECTED_FOTS_FAILURE (fn-deep-equal K2-SeqDeepEqualFunc-37 0)
748-EXPECTED_FOTS_FAILURE (fn-distinct-values cbcl-distinct-values-002 1090089)
749-EXPECTED_FOTS_FAILURE (fn-distinct-values cbcl-distinct-values-002b 1090089)
750 EXPECTED_FOTS_FAILURE (fn-environment-variable environment-variable-005 0)
751 EXPECTED_FOTS_FAILURE (fn-environment-variable environment-variable-006 0)
752 EXPECTED_FOTS_FAILURE (fn-environment-variable environment-variable-007 0)
753
754=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-01.xml.res'
755--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-01.xml.res 1970-01-01 00:00:00 +0000
756+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-01.xml.res 2013-05-14 23:54:28 +0000
757@@ -0,0 +1,1 @@
758+1.899
759
760=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-02.xml.res'
761--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-02.xml.res 1970-01-01 00:00:00 +0000
762+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-02.xml.res 2013-05-14 23:54:28 +0000
763@@ -0,0 +1,1 @@
764+2
765
766=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-03.xml.res'
767--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-03.xml.res 1970-01-01 00:00:00 +0000
768+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-03.xml.res 2013-05-14 23:54:28 +0000
769@@ -0,0 +1,1 @@
770+1.6
771
772=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-04.xml.res'
773--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-04.xml.res 1970-01-01 00:00:00 +0000
774+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-04.xml.res 2013-05-14 23:54:28 +0000
775@@ -0,0 +1,1 @@
776+10
777
778=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-05.xml.res'
779--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-05.xml.res 1970-01-01 00:00:00 +0000
780+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-05.xml.res 2013-05-14 23:54:28 +0000
781@@ -0,0 +1,1 @@
782+-1.9
783
784=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-06.xml.res'
785--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-06.xml.res 1970-01-01 00:00:00 +0000
786+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-06.xml.res 2013-05-14 23:54:28 +0000
787@@ -0,0 +1,1 @@
788+-2
789
790=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-07.xml.res'
791--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-07.xml.res 1970-01-01 00:00:00 +0000
792+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-07.xml.res 2013-05-14 23:54:28 +0000
793@@ -0,0 +1,1 @@
794+-1.6
795
796=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-08.xml.res'
797--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-08.xml.res 1970-01-01 00:00:00 +0000
798+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-08.xml.res 2013-05-14 23:54:28 +0000
799@@ -0,0 +1,1 @@
800+-10
801
802=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-09.xml.res'
803--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-09.xml.res 1970-01-01 00:00:00 +0000
804+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-09.xml.res 2013-05-14 23:54:28 +0000
805@@ -0,0 +1,1 @@
806+1
807
808=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-10.xml.res'
809--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-10.xml.res 1970-01-01 00:00:00 +0000
810+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-10.xml.res 2013-05-14 23:54:28 +0000
811@@ -0,0 +1,1 @@
812+1
813
814=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-11.xml.res'
815--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-11.xml.res 1970-01-01 00:00:00 +0000
816+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-11.xml.res 2013-05-14 23:54:28 +0000
817@@ -0,0 +1,1 @@
818+1.234
819
820=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/xs_float-12.xml.res'
821--- test/rbkt/ExpQueryResults/zorba/numerics/xs_float-12.xml.res 1970-01-01 00:00:00 +0000
822+++ test/rbkt/ExpQueryResults/zorba/numerics/xs_float-12.xml.res 2013-05-14 23:54:28 +0000
823@@ -0,0 +1,1 @@
824+1.9
825
826=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-01.xq'
827--- test/rbkt/Queries/zorba/numerics/xs_float-01.xq 1970-01-01 00:00:00 +0000
828+++ test/rbkt/Queries/zorba/numerics/xs_float-01.xq 2013-05-14 23:54:28 +0000
829@@ -0,0 +1,1 @@
830+xs:float(1.899)
831
832=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-02.xq'
833--- test/rbkt/Queries/zorba/numerics/xs_float-02.xq 1970-01-01 00:00:00 +0000
834+++ test/rbkt/Queries/zorba/numerics/xs_float-02.xq 2013-05-14 23:54:28 +0000
835@@ -0,0 +1,1 @@
836+xs:float(1.999)
837
838=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-03.xq'
839--- test/rbkt/Queries/zorba/numerics/xs_float-03.xq 1970-01-01 00:00:00 +0000
840+++ test/rbkt/Queries/zorba/numerics/xs_float-03.xq 2013-05-14 23:54:28 +0000
841@@ -0,0 +1,1 @@
842+xs:float(1.59999)
843
844=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-04.xq'
845--- test/rbkt/Queries/zorba/numerics/xs_float-04.xq 1970-01-01 00:00:00 +0000
846+++ test/rbkt/Queries/zorba/numerics/xs_float-04.xq 2013-05-14 23:54:28 +0000
847@@ -0,0 +1,1 @@
848+xs:float(9.999)
849
850=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-05.xq'
851--- test/rbkt/Queries/zorba/numerics/xs_float-05.xq 1970-01-01 00:00:00 +0000
852+++ test/rbkt/Queries/zorba/numerics/xs_float-05.xq 2013-05-14 23:54:28 +0000
853@@ -0,0 +1,1 @@
854+xs:float(-1.89999)
855
856=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-06.xq'
857--- test/rbkt/Queries/zorba/numerics/xs_float-06.xq 1970-01-01 00:00:00 +0000
858+++ test/rbkt/Queries/zorba/numerics/xs_float-06.xq 2013-05-14 23:54:28 +0000
859@@ -0,0 +1,1 @@
860+xs:float(-1.999)
861
862=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-07.xq'
863--- test/rbkt/Queries/zorba/numerics/xs_float-07.xq 1970-01-01 00:00:00 +0000
864+++ test/rbkt/Queries/zorba/numerics/xs_float-07.xq 2013-05-14 23:54:28 +0000
865@@ -0,0 +1,1 @@
866+xs:float(-1.59999)
867
868=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-08.xq'
869--- test/rbkt/Queries/zorba/numerics/xs_float-08.xq 1970-01-01 00:00:00 +0000
870+++ test/rbkt/Queries/zorba/numerics/xs_float-08.xq 2013-05-14 23:54:28 +0000
871@@ -0,0 +1,1 @@
872+xs:float(-9.999)
873
874=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-09.xq'
875--- test/rbkt/Queries/zorba/numerics/xs_float-09.xq 1970-01-01 00:00:00 +0000
876+++ test/rbkt/Queries/zorba/numerics/xs_float-09.xq 2013-05-14 23:54:28 +0000
877@@ -0,0 +1,1 @@
878+xs:float(1.0000001)
879
880=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-10.xq'
881--- test/rbkt/Queries/zorba/numerics/xs_float-10.xq 1970-01-01 00:00:00 +0000
882+++ test/rbkt/Queries/zorba/numerics/xs_float-10.xq 2013-05-14 23:54:28 +0000
883@@ -0,0 +1,1 @@
884+xs:float(1.00000001)
885
886=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-11.xq'
887--- test/rbkt/Queries/zorba/numerics/xs_float-11.xq 1970-01-01 00:00:00 +0000
888+++ test/rbkt/Queries/zorba/numerics/xs_float-11.xq 2013-05-14 23:54:28 +0000
889@@ -0,0 +1,1 @@
890+xs:float(1.234000001)
891
892=== added file 'test/rbkt/Queries/zorba/numerics/xs_float-12.xq'
893--- test/rbkt/Queries/zorba/numerics/xs_float-12.xq 1970-01-01 00:00:00 +0000
894+++ test/rbkt/Queries/zorba/numerics/xs_float-12.xq 2013-05-14 23:54:28 +0000
895@@ -0,0 +1,1 @@
896+xs:float(1.89999123)

Subscribers

People subscribed via source and target branches