annotate liboctave/util/oct-inttypes.cc @ 22079:e0dbd81fd9b1

provide wrapper for frexp and frexpf (bug #48363) * bootstrap.conf (gnulib_modules): Add modules frexp and frexpf. * liboctave/wrappers/math-wrappers.c, liboctave/wrappers/math-wrappers.h: New files. * liboctave/wrappers/module.mk: Add math-wrappers.{c,h}. * lo-mappers.cc, lo-mappers.h (octave::math::frexp): New functions. (octave::math::log2): Use them instead of std::frexp. * data.cc (Feps): Use octave::math::frexp instead of std::frexp. * oct-inttypes.cc (dblesplit): Likewise.
author Mike Miller <mtmiller@octave.org>
date Sun, 03 Jul 2016 09:54:43 -0700
parents d18c63a45070
children e43d83253e28
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
1 /*
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18634
diff changeset
3 Copyright (C) 2004-2015 John W. Eaton
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4 Copyright (C) 2008-2009 Jaroslav Hajek
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
5
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
7
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
11 option) any later version.
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
12
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
16 for more details.
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
17
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
20 <http://www.gnu.org/licenses/>.
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
21
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
22 */
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
23
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
24 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21202
diff changeset
25 # include "config.h"
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
26 #endif
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
27
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
28 #include "fpucw-wrappers.h"
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
29 #include "lo-error.h"
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
30 #include "oct-inttypes.h"
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
31
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
32 template <typename T>
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
33 const octave_int<T> octave_int<T>::zero (static_cast<T> (0));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
34
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
35 template <typename T>
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
36 const octave_int<T> octave_int<T>::one (static_cast<T> (1));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
37
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
38 // define type names.
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
39 #define DECLARE_OCTAVE_INT_TYPENAME(TYPE, TYPENAME) \
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
40 template <> \
8319
c374691576f6 Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8293
diff changeset
41 OCTAVE_API const char * \
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
42 octave_int<TYPE>::type_name () { return TYPENAME; }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
43
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
44 DECLARE_OCTAVE_INT_TYPENAME (int8_t, "int8")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
45 DECLARE_OCTAVE_INT_TYPENAME (int16_t, "int16")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
46 DECLARE_OCTAVE_INT_TYPENAME (int32_t, "int32")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
47 DECLARE_OCTAVE_INT_TYPENAME (int64_t, "int64")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
48 DECLARE_OCTAVE_INT_TYPENAME (uint8_t, "uint8")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
49 DECLARE_OCTAVE_INT_TYPENAME (uint16_t, "uint16")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
50 DECLARE_OCTAVE_INT_TYPENAME (uint32_t, "uint32")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
51 DECLARE_OCTAVE_INT_TYPENAME (uint64_t, "uint64")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
52
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
53 template <class T>
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
54 template <class S>
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
55 T
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
56 octave_int_base<T>::convert_real (const S& value)
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
57 {
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
58 // Compute proper thresholds.
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
59 static const S thmin = compute_threshold (static_cast<S> (min_val ()),
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
60 min_val ());
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
61 static const S thmax = compute_threshold (static_cast<S> (max_val ()),
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
62 max_val ());
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
63 if (octave::math::isnan (value))
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
64 {
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
65 return static_cast<T> (0);
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
66 }
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
67 else if (value < thmin)
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
68 {
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
69 return min_val ();
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
70 }
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
71 else if (value > thmax)
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
72 {
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
73 return max_val ();
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
74 }
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
75 else
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
76 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
77 S rvalue = octave::math::round (value);
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
78 return static_cast<T> (rvalue);
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
79 }
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
80 }
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
81
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
82 #define INSTANTIATE_CONVERT_REAL_1(T, S) \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
83 template \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
84 OCTAVE_API \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
85 T \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
86 octave_int_base<T>::convert_real (const S&)
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
87
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
88 #define INSTANTIATE_CONVERT_REAL(S) \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
89 INSTANTIATE_CONVERT_REAL_1 (int8_t, S); \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
90 INSTANTIATE_CONVERT_REAL_1 (uint8_t, S); \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
91 INSTANTIATE_CONVERT_REAL_1 (int16_t, S); \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
92 INSTANTIATE_CONVERT_REAL_1 (uint16_t, S); \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
93 INSTANTIATE_CONVERT_REAL_1 (int32_t, S); \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
94 INSTANTIATE_CONVERT_REAL_1 (uint32_t, S); \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
95 INSTANTIATE_CONVERT_REAL_1 (int64_t, S); \
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
96 INSTANTIATE_CONVERT_REAL_1 (uint64_t, S)
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
97
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
98 INSTANTIATE_CONVERT_REAL (double);
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
99 INSTANTIATE_CONVERT_REAL (float);
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
100 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
101 INSTANTIATE_CONVERT_REAL (long double);
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
102 #endif
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
103
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
104 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
105
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
106 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
107
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
108 #define DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES(T) \
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
109 template <typename xop> \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
110 bool \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
111 octave_int_cmp_op::external_mop (double x, T y) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
112 { \
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
113 unsigned int oldcw = octave_begin_long_double_rounding (); \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
114 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
115 bool retval = xop::op (static_cast<long double> (x), \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
116 static_cast<long double> (y)); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
117 \
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
118 octave_end_long_double_rounding (oldcw); \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
119 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
120 return retval; \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
121 } \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
122 \
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
123 template <typename xop> \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
124 bool \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
125 octave_int_cmp_op::external_mop (T x, double y) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
126 { \
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
127 unsigned int oldcw = octave_begin_long_double_rounding (); \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
128 \
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
129 bool retval = xop::op (static_cast<long double> (x), \
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
130 static_cast<long double> (y)); \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
131 \
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
132 octave_end_long_double_rounding (oldcw); \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
133 \
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
134 return retval; \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
135 }
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
136
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
137 DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES (int64_t)
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
138 DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES (uint64_t)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
139
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
140 #define INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP(OP, T) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
141 template OCTAVE_API bool \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
142 octave_int_cmp_op::external_mop<octave_int_cmp_op::OP> (double, T); \
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
143 template OCTAVE_API bool \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
144 octave_int_cmp_op::external_mop<octave_int_cmp_op::OP> (T, double)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
145
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
146 #define INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS(T) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
147 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (lt, T); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
148 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (le, T); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
149 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (gt, T); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
150 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (ge, T); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
151 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (eq, T); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
152 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (ne, T)
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
153
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
154 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS (int64_t);
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
155 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS (uint64_t);
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
156
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
157 uint64_t
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
158 octave_external_uint64_uint64_mul (uint64_t x, uint64_t y)
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
159 {
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
160 unsigned int oldcw = octave_begin_long_double_rounding ();
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
161
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
162 uint64_t retval = octave_int_arith_base<uint64_t, false>::mul_internal (x, y);
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
163
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
164 octave_end_long_double_rounding (oldcw);
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
165
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
166 return retval;
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
167 }
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
168
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
169 int64_t
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
170 octave_external_int64_int64_mul (int64_t x, int64_t y)
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
171 {
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
172 unsigned int oldcw = octave_begin_long_double_rounding ();
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
173
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
174 int64_t retval = octave_int_arith_base<int64_t, true>::mul_internal (x, y);
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
175
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
176 octave_end_long_double_rounding (oldcw);
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
177
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
178 return retval;
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
179 }
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
180
18005
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
181 // Note that if we return long double it is apparently possible for
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
182 // truncation to happen at the point of storing the result in retval,
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
183 // which can happen after we end long double rounding. Attempt to avoid
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
184 // that problem by storing the full precision temporary value in the
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
185 // integer value before we end the long double rounding mode.
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
186 // Similarly, the conversion from the 64-bit integer type to long double
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
187 // must also occur in long double rounding mode.
18005
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
188
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
189 #define OCTAVE_LONG_DOUBLE_OP(T, OP, NAME) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
190 T \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
191 external_double_ ## T ## _ ## NAME (double x, T y) \
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
192 { \
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
193 unsigned int oldcw = octave_begin_long_double_rounding (); \
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
194 \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
195 T retval = T (x OP static_cast<long double> (y.value ())); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
196 \
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
197 octave_end_long_double_rounding (oldcw); \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
198 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
199 return retval; \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
200 } \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
201 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
202 T \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
203 external_ ## T ## _double_ ## NAME (T x, double y) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
204 { \
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
205 unsigned int oldcw = octave_begin_long_double_rounding (); \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
206 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
207 T retval = T (static_cast<long double> (x.value ()) OP y); \
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
208 \
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
209 octave_end_long_double_rounding (oldcw); \
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
210 \
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
211 return retval; \
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
212 }
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
213
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
214 #define OCTAVE_LONG_DOUBLE_OPS(T) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
215 OCTAVE_LONG_DOUBLE_OP (T, +, add); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
216 OCTAVE_LONG_DOUBLE_OP (T, -, sub); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
217 OCTAVE_LONG_DOUBLE_OP (T, *, mul); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
218 OCTAVE_LONG_DOUBLE_OP (T, /, div)
18005
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
219
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
220 OCTAVE_LONG_DOUBLE_OPS(octave_int64);
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
221 OCTAVE_LONG_DOUBLE_OPS(octave_uint64);
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
222
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
223 #endif
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
224
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
225 #else
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
226
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
227 // Define comparison operators
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
228
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
229 template <typename xop>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
230 bool
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8797
diff changeset
231 octave_int_cmp_op::emulate_mop (uint64_t x, double y)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
232 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
233 static const double xxup = std::numeric_limits<uint64_t>::max ();
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
234 // This converts to the nearest double. Unless there's an equality, the
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
235 // result is clear.
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
236 double xx = x;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
237 if (xx != y)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
238 return xop::op (xx, y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
239 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
240 {
21004
f7e416862e90 doc: fix spelling of "occurred".
Rafael Laboissiere <rafael@laboissiere.net>
parents: 19861
diff changeset
241 // If equality occurred we compare as integers.
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
242 if (xx == xxup)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
243 return xop::gtval;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
244 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
245 return xop::op (x, static_cast<uint64_t> (xx));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
246 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
247 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
248
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
249 template <typename xop>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
250 bool
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8797
diff changeset
251 octave_int_cmp_op::emulate_mop (int64_t x, double y)
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
252 {
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
253 static const double xxup = std::numeric_limits<int64_t>::max ();
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
254 static const double xxlo = std::numeric_limits<int64_t>::min ();
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
255 // This converts to the nearest double. Unless there's an equality, the
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
256 // result is clear.
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
257 double xx = x;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
258 if (xx != y)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
259 return xop::op (xx, y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
260 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
261 {
21004
f7e416862e90 doc: fix spelling of "occurred".
Rafael Laboissiere <rafael@laboissiere.net>
parents: 19861
diff changeset
262 // If equality occurred we compare as integers.
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
263 if (xx == xxup)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
264 return xop::gtval;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
265 else if (xx == xxlo)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
266 return xop::ltval;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
267 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
268 return xop::op (x, static_cast<int64_t> (xx));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
269 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
270
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
271 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
272
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
273 // We define double-int operations by reverting the operator
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
274
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
275 // A trait class reverting the operator
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
276 template <typename xop>
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
277 class rev_op
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
278 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
279 public:
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
280 typedef xop op;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
281 };
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
282
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
283 #define DEFINE_REVERTED_OPERATOR(OP1,OP2) \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
284 template <> \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
285 class rev_op<octave_int_cmp_op::OP1> \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
286 { \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
287 public: \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
288 typedef octave_int_cmp_op::OP2 op; \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
289 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
290
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
291 DEFINE_REVERTED_OPERATOR(lt,gt);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
292 DEFINE_REVERTED_OPERATOR(gt,lt);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
293 DEFINE_REVERTED_OPERATOR(le,ge);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
294 DEFINE_REVERTED_OPERATOR(ge,le);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
295
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
296 template <typename xop>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
297 bool
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8797
diff changeset
298 octave_int_cmp_op::emulate_mop (double x, uint64_t y)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
299 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
300 typedef typename rev_op<xop>::op rop;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
301 return mop<rop> (y, x);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
302 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
303
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
304 template <typename xop>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
305 bool
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8797
diff changeset
306 octave_int_cmp_op::emulate_mop (double x, int64_t y)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
307 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
308 typedef typename rev_op<xop>::op rop;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
309 return mop<rop> (y, x);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
310 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
311
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
312 // Define handlers for int64 multiplication
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
313
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
314 template <>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
315 uint64_t
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
316 octave_int_arith_base<uint64_t, false>::mul_internal (uint64_t x, uint64_t y)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
317 {
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
318 // Get upper words
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
319 uint64_t ux = x >> 32;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
320 uint64_t uy = y >> 32;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
321 uint64_t res;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
322 if (ux)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
323 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
324 if (uy)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
325 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
326 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
327 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
328 uint64_t ly = static_cast<uint32_t> (y);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
329 uint64_t uxly = ux*ly;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
330 if (uxly >> 32)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
331 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
332 uxly <<= 32; // never overflows
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
333 uint64_t lx = static_cast<uint32_t> (x);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
334 uint64_t lxly = lx*ly;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
335 res = add (uxly, lxly);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
336 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
337 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
338 else if (uy)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
339 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
340 uint64_t lx = static_cast<uint32_t> (x);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
341 uint64_t uylx = uy*lx;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
342 if (uylx >> 32)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
343 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
344 uylx <<= 32; // never overflows
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
345 uint64_t ly = static_cast<uint32_t> (y);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
346 uint64_t lylx = ly*lx;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
347 res = add (uylx, lylx);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
348 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
349 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
350 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
351 uint64_t lx = static_cast<uint32_t> (x);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
352 uint64_t ly = static_cast<uint32_t> (y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
353 res = lx*ly;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
354 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
355
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
356 return res;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
357
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
358 overflow:
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
359 return max_val ();
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
360 }
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
361
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
362 template <>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
363 int64_t
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
364 octave_int_arith_base<int64_t, true>::mul_internal (int64_t x, int64_t y)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
365 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
366 // The signed case is far worse. The problem is that
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
367 // even if neither integer fits into signed 32-bit range, the result may
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
368 // still be OK. Uh oh.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
369
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
370 // Essentially, what we do is compute sign, multiply absolute values
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
371 // (as above) and impose the sign.
21302
8376de2eaf00 define OCTAVE_HAVE_FAST_INT_OPS in octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
372 // FIXME: can we do something faster if we OCTAVE_HAVE_FAST_INT_OPS?
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
373
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
374 uint64_t usx = octave_int_abs (x);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
375 uint64_t usy = octave_int_abs (y);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
376 bool positive = (x < 0) == (y < 0);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
377
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
378 // Get upper words
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
379 uint64_t ux = usx >> 32;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
380 uint64_t uy = usy >> 32;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
381 uint64_t res;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
382 if (ux)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
383 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
384 if (uy)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
385 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
386 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
387 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
388 uint64_t ly = static_cast<uint32_t> (usy);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
389 uint64_t uxly = ux*ly;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
390 if (uxly >> 32)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
391 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
392 uxly <<= 32; // never overflows
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
393 uint64_t lx = static_cast<uint32_t> (usx);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
394 uint64_t lxly = lx*ly;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
395 res = uxly + lxly;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
396 if (res < uxly)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
397 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
398 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
399 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
400 else if (uy)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
401 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
402 uint64_t lx = static_cast<uint32_t> (usx);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
403 uint64_t uylx = uy*lx;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
404 if (uylx >> 32)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
405 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
406 uylx <<= 32; // never overflows
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
407 uint64_t ly = static_cast<uint32_t> (usy);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
408 uint64_t lylx = ly*lx;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
409 res = uylx + lylx;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
410 if (res < uylx)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
411 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
412 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
413 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
414 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
415 uint64_t lx = static_cast<uint32_t> (usx);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
416 uint64_t ly = static_cast<uint32_t> (usy);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
417 res = lx*ly;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
418 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
419
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
420 if (positive)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
421 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
422 if (res > static_cast<uint64_t> (max_val ()))
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
423 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
424 return max_val ();
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
425 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
426 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
427 return static_cast<int64_t> (res);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
428 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
429 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
430 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
431 if (res > static_cast<uint64_t> (-min_val ()))
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
432 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
433 return min_val ();
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
434 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
435 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
436 return -static_cast<int64_t> (res);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
437 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
438
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
439 overflow:
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
440 return positive ? max_val () : min_val ();
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
441
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
442 }
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
443
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
444 #define INT_DOUBLE_BINOP_DECL(OP,SUFFIX) \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
445 template <> \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
446 OCTAVE_API octave_ ## SUFFIX \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
447 operator OP (const octave_ ## SUFFIX & x, const double& y)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
448
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
449 #define DOUBLE_INT_BINOP_DECL(OP,SUFFIX) \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
450 template <> \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
451 OCTAVE_API octave_ ## SUFFIX \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
452 operator OP (const double& x, const octave_ ## SUFFIX & y)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
453
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
454 INT_DOUBLE_BINOP_DECL (+, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
455 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14427
diff changeset
456 return (y < 0) ? x - octave_uint64 (-y) : x + octave_uint64 (y);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
457 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
458
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
459 DOUBLE_INT_BINOP_DECL (+, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
460 { return y + x; }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
461
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
462 INT_DOUBLE_BINOP_DECL (+, int64)
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
463 {
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
464 if (fabs (y) < static_cast<double> (octave_int64::max ()))
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
465 return x + octave_int64 (y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
466 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
467 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
468 // If the number is within the int64 range (the most common case,
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
469 // probably), the above will work as expected. If not, it's more
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
470 // complicated - as long as y is within _twice_ the signed range, the
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
471 // result may still be an integer. An instance of such an operation is
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
472 // 3*2**62 + (1+intmin ('int64')) that should yield int64 (2**62) + 1.
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
473 // So what we do is to try to convert y/2 and add it twice. Note that
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
474 // if y/2 overflows, the result must overflow as well, and that y/2
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
475 // cannot be a fractional number.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
476 octave_int64 y2 (y / 2);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
477 return (x + y2) + y2;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
478 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
479 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
480
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
481 DOUBLE_INT_BINOP_DECL (+, int64)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
482 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
483 return y + x;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
484 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
485
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
486 INT_DOUBLE_BINOP_DECL (-, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
487 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
488 return x + (-y);
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
489 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
490
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
491 DOUBLE_INT_BINOP_DECL (-, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
492 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
493 if (x <= static_cast<double> (octave_uint64::max ()))
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14427
diff changeset
494 return octave_uint64 (x) - y;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
495 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
496 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
497 // Again a trick to get the corner cases right. Things like
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14427
diff changeset
498 // 3**2**63 - intmax ('uint64') should produce the correct result, i.e.
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14427
diff changeset
499 // int64 (2**63) + 1.
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
500 const double p2_64 = std::pow (2.0, 64);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
501 if (y.bool_value ())
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
502 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
503 const uint64_t p2_64my = (~y.value ()) + 1; // Equals 2**64 - y
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
504 return octave_uint64 (x - p2_64) + octave_uint64 (p2_64my);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
505 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
506 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
507 return octave_uint64 (p2_64);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
508 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
509 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
510
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
511 INT_DOUBLE_BINOP_DECL (-, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
512 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
513 return x + (-y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
514 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
515
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
516 DOUBLE_INT_BINOP_DECL (-, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
517 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
518 static const bool twosc = (std::numeric_limits<int64_t>::min ()
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
519 < -std::numeric_limits<int64_t>::max ());
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
520 // In case of symmetric integers (not two's complement), this will probably
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
521 // be eliminated at compile time.
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
522 if (twosc && y.value () == std::numeric_limits<int64_t>::min ())
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
523 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14427
diff changeset
524 return octave_int64 (x + std::pow (2.0, 63));
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
525 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
526 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
527 return x + (-y);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
528 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
529
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
530 // NOTE:
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
531 // Emulated mixed multiplications are tricky due to possible precision loss.
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
532 // Here, after sorting out common cases for speed, we follow the strategy
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
533 // of converting the double number into the form sign * 64-bit integer *
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
534 // 2**exponent, multiply the 64-bit integers to get a 128-bit number, split that
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
535 // number into 32-bit words and form 4 double-valued summands (none of which
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
536 // loses precision), then convert these into integers and sum them. Though it
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
537 // is not immediately obvious, this should work even w.r.t. rounding (none of
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
538 // the summands lose precision).
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
539
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
540 // Multiplies two unsigned 64-bit ints to get a 128-bit number represented
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
541 // as four 32-bit words.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
542 static void
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
543 umul128 (uint64_t x, uint64_t y, uint32_t w[4])
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
544 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
545 uint64_t lx = static_cast<uint32_t> (x);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
546 uint64_t ux = x >> 32;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
547 uint64_t ly = static_cast<uint32_t> (y);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
548 uint64_t uy = y >> 32;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
549 uint64_t a = lx * ly;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
550 w[0] = a; a >>= 32;
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
551 uint64_t uxly = ux*ly;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
552 uint64_t uylx = uy*lx;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
553 a += static_cast<uint32_t> (uxly); uxly >>= 32;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
554 a += static_cast<uint32_t> (uylx); uylx >>= 32;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
555 w[1] = a; a >>= 32;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
556 uint64_t uxuy = ux * uy;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
557 a += uxly; a += uylx; a += uxuy;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
558 w[2] = a; a >>= 32;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
559 w[3] = a;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
560 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
561
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
562 // Splits a double into bool sign, unsigned 64-bit mantissa and int exponent
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
563 static void
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
564 dblesplit (double x, bool& sign, uint64_t& mtis, int& exp)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
565 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
566 sign = x < 0; x = fabs (x);
22079
e0dbd81fd9b1 provide wrapper for frexp and frexpf (bug #48363)
Mike Miller <mtmiller@octave.org>
parents: 22073
diff changeset
567 x = octave::math::frexp (x, &exp);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
568 exp -= 52;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
569 mtis = static_cast<uint64_t> (ldexp (x, 52));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
570 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
571
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
572 // Gets a double number from a
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
573 // 32-bit unsigned integer mantissa, exponent, and sign.
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
574 static double
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
575 dbleget (bool sign, uint32_t mtis, int exp)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
576 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
577 double x = ldexp (static_cast<double> (mtis), exp);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
578 return sign ? -x : x;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
579 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
580
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
581 INT_DOUBLE_BINOP_DECL (*, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
582 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
583 if (y >= 0 && y < octave_uint64::max () && y == octave::math::round (y))
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
584 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
585 return x * octave_uint64 (static_cast<uint64_t> (y));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
586 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
587 else if (y == 0.5)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
588 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
589 return x / octave_uint64 (static_cast<uint64_t> (2));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
590 }
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
591 else if (y < 0 || octave::math::isnan (y) || octave::math::isinf (y))
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
592 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
593 return octave_uint64 (x.value () * y);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
594 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
595 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
596 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
597 bool sign;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
598 uint64_t my;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
599 int e;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
600 dblesplit (y, sign, my, e);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
601 uint32_t w[4];
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
602 umul128 (x.value (), my, w);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
603 octave_uint64 res = octave_uint64::zero;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
604 for (short i = 0; i < 4; i++)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
605 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
606 res += octave_uint64 (dbleget (sign, w[i], e));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
607 e += 32;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
608 }
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
609 return res;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
610 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
611 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
612
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
613 DOUBLE_INT_BINOP_DECL (*, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
614 { return y * x; }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
615
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
616 INT_DOUBLE_BINOP_DECL (*, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
617 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
618 if (fabs (y) < octave_int64::max () && y == octave::math::round (y))
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
619 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
620 return x * octave_int64 (static_cast<int64_t> (y));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
621 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
622 else if (fabs (y) == 0.5)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
623 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
624 return x / octave_int64 (static_cast<uint64_t> (4*y));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
625 }
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
626 else if (octave::math::isnan (y) || octave::math::isinf (y))
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
627 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
628 return octave_int64 (x.value () * y);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
629 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
630 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
631 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
632 bool sign;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
633 uint64_t my;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
634 int e;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
635 dblesplit (y, sign, my, e);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
636 uint32_t w[4];
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
637 sign = (sign != (x.value () < 0));
8293
ad5bb02d267a workaround missing std::abs(int64_t) in MSVC
Jaroslav Hajek <highegg@gmail.com>
parents: 8202
diff changeset
638 umul128 (octave_int_abs (x.value ()), my, w);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
639 octave_int64 res = octave_int64::zero;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
640 for (short i = 0; i < 4; i++)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
641 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
642 res += octave_int64 (dbleget (sign, w[i], e));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
643 e += 32;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
644 }
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
645 return res;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
646 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
647 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
648
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
649 DOUBLE_INT_BINOP_DECL (*, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
650 { return y * x; }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
651
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
652 DOUBLE_INT_BINOP_DECL (/, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
653 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
654 return octave_uint64 (x / static_cast<double> (y));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
655 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
656
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
657 DOUBLE_INT_BINOP_DECL (/, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
658 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
659 return octave_int64 (x / static_cast<double> (y));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
660 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
661
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
662 INT_DOUBLE_BINOP_DECL (/, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
663 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
664 if (y >= 0 && y < octave_uint64::max () && y == octave::math::round (y))
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
665 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
666 return x / octave_uint64 (y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
667 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
668 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
669 return x * (1.0/y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
670 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
671
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
672 INT_DOUBLE_BINOP_DECL (/, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
673 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
674 if (fabs (y) < octave_int64::max () && y == octave::math::round (y))
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
675 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
676 return x / octave_int64 (y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
677 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
678 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
679 return x * (1.0/y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
680 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
681
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
682 #define INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP,T1,T2) \
9237
3c1762c7e787 Add missing xxx_API decoration and remove misplaced ones
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9013
diff changeset
683 template OCTAVE_API bool \
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8797
diff changeset
684 octave_int_cmp_op::emulate_mop<octave_int_cmp_op::OP> (T1 x, T2 y)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
685
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
686 #define INSTANTIATE_INT64_DOUBLE_CMP_OP(OP) \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
687 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, int64_t); \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
688 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, uint64_t); \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
689 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, int64_t, double); \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
690 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, uint64_t, double)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
691
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
692 INSTANTIATE_INT64_DOUBLE_CMP_OP(lt);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
693 INSTANTIATE_INT64_DOUBLE_CMP_OP(le);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
694 INSTANTIATE_INT64_DOUBLE_CMP_OP(gt);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
695 INSTANTIATE_INT64_DOUBLE_CMP_OP(ge);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
696 INSTANTIATE_INT64_DOUBLE_CMP_OP(eq);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
697 INSTANTIATE_INT64_DOUBLE_CMP_OP(ne);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
698
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
699 #endif
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
700
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
701 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
702 octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
703 pow (const octave_int<T>& a, const octave_int<T>& b)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
704 {
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
705 octave_int<T> retval;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
706
8864
4d328b8979c8 simplify integer power
Jaroslav Hajek <highegg@gmail.com>
parents: 8856
diff changeset
707 octave_int<T> zero = static_cast<T> (0);
4d328b8979c8 simplify integer power
Jaroslav Hajek <highegg@gmail.com>
parents: 8856
diff changeset
708 octave_int<T> one = static_cast<T> (1);
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
709
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
710 if (b == zero || a == one)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
711 retval = one;
8864
4d328b8979c8 simplify integer power
Jaroslav Hajek <highegg@gmail.com>
parents: 8856
diff changeset
712 else if (b < zero)
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
713 {
8864
4d328b8979c8 simplify integer power
Jaroslav Hajek <highegg@gmail.com>
parents: 8856
diff changeset
714 if (a == -one)
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
715 retval = (b.value () % 2) ? a : one;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
716 else
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
717 retval = zero;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
718 }
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
719 else
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
720 {
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
721 octave_int<T> a_val = a;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
722 T b_val = b; // no need to do saturation on b
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
723
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
724 retval = a;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
725
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
726 b_val -= 1;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
727
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
728 while (b_val != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
729 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
730 if (b_val & 1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
731 retval = retval * a_val;
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
732
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
733 b_val = b_val >> 1;
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
734
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
735 if (b_val)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
736 a_val = a_val * a_val;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
737 }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
738 }
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
739
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
740 return retval;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
741 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
742
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
743 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
744 octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
745 pow (const double& a, const octave_int<T>& b)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
746 { return octave_int<T> (pow (a, b.double_value ())); }
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
747
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
748 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
749 octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
750 pow (const octave_int<T>& a, const double& b)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
751 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
752 return ((b >= 0 && b < std::numeric_limits<T>::digits && b == octave::math::round (b))
8195
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
753 ? pow (a, octave_int<T> (static_cast<T> (b)))
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
754 : octave_int<T> (pow (a.double_value (), b)));
8195
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
755 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
756
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
757 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
758 octave_int<T>
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
759 pow (const float& a, const octave_int<T>& b)
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
760 { return octave_int<T> (pow (a, b.float_value ())); }
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
761
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
762 template <typename T>
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
763 octave_int<T>
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
764 pow (const octave_int<T>& a, const float& b)
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
765 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
766 return ((b >= 0 && b < std::numeric_limits<T>::digits && b == octave::math::round (b))
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
767 ? pow (a, octave_int<T> (static_cast<T> (b)))
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
768 : octave_int<T> (pow (a.double_value (), static_cast<double> (b))));
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
769 }
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
770
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
771 // FIXME: Do we really need a differently named single-precision
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
772 // function integer power function here instead of an overloaded
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
773 // one?
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
774 template <typename T>
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
775 octave_int<T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
776 powf (const float& a, const octave_int<T>& b)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
777 { return octave_int<T> (pow (a, b.float_value ())); }
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
778
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
779 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
780 octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
781 powf (const octave_int<T>& a, const float& b)
8195
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
782 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
783 return ((b >= 0 && b < std::numeric_limits<T>::digits && b == octave::math::round (b))
8195
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
784 ? pow (a, octave_int<T> (static_cast<T> (b)))
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
785 : octave_int<T> (pow (a.double_value (), static_cast<double> (b))));
8195
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
786 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
787
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
788 #define INSTANTIATE_INTTYPE(T) \
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 6105
diff changeset
789 template class OCTAVE_API octave_int<T>; \
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 6105
diff changeset
790 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const octave_int<T>&); \
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
791 template OCTAVE_API octave_int<T> pow (const double&, const octave_int<T>&); \
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
792 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const double&); \
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
793 template OCTAVE_API octave_int<T> pow (const float&, const octave_int<T>&); \
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
794 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const float&); \
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
795 template OCTAVE_API octave_int<T> powf (const float&, const octave_int<T>&); \
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
796 template OCTAVE_API octave_int<T> powf (const octave_int<T>&, const float&); \
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 6105
diff changeset
797 template OCTAVE_API octave_int<T> \
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
798 bitshift (const octave_int<T>&, int, const octave_int<T>&);
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
799
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
800 INSTANTIATE_INTTYPE (int8_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
801 INSTANTIATE_INTTYPE (int16_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
802 INSTANTIATE_INTTYPE (int32_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
803 INSTANTIATE_INTTYPE (int64_t);
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
804
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
805 INSTANTIATE_INTTYPE (uint8_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
806 INSTANTIATE_INTTYPE (uint16_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
807 INSTANTIATE_INTTYPE (uint32_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
808 INSTANTIATE_INTTYPE (uint64_t);
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
809
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
810 /*
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
811
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
812 %!assert (intmax ("int64") / intmin ("int64"), int64 (-1))
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
813 %!assert (intmin ("int64") / int64 (-1), intmax ("int64"))
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
814 %!assert (int64 (2**63), intmax ("int64"))
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
815 %!assert (uint64 (2**64), intmax ("uint64"))
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
816 %!test
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
817 %! a = 1.9*2^61; b = uint64 (a); b++; assert (b > a);
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
818 %!test
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
819 %! a = -1.9*2^61; b = int64 (a); b++; assert (b > a);
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
820 %!test
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
821 %! a = int64 (-2**60) + 2; assert (1.25*a == (5*a)/4);
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
822 %!test
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
823 %! a = uint64 (2**61) + 2; assert (1.25*a == (5*a)/4);
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
824 %!assert (int32 (2**31+0.5), intmax ("int32"))
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
825 %!assert (int32 (-2**31-0.5), intmin ("int32"))
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
826 %!assert ((int64 (2**62)+1)**1, int64 (2**62)+1)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
827 %!assert ((int64 (2**30)+1)**2, int64 (2**60+2**31) + 1)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
828
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
829 %!assert (uint8 (char (128)), uint8 (128))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
830 %!assert (uint8 (char (255)), uint8 (255))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
831 %!assert (int8 (char (128)), int8 (128))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
832 %!assert (int8 (char (255)), int8 (255))
18628
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
833
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
834 %!assert (uint16 (char (128)), uint16 (128))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
835 %!assert (uint16 (char (255)), uint16 (255))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
836 %!assert (int16 (char (128)), int16 (128))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
837 %!assert (int16 (char (255)), int16 (255))
18628
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
838
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
839 %!assert (uint32 (char (128)), uint32 (128))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
840 %!assert (uint32 (char (255)), uint32 (255))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
841 %!assert (int32 (char (128)), int32 (128))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
842 %!assert (int32 (char (255)), int32 (255))
18628
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
843
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
844 %!assert (uint64 (char (128)), uint64 (128))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
845 %!assert (uint64 (char (255)), uint64 (255))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
846 %!assert (int64 (char (128)), int64 (128))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21302
diff changeset
847 %!assert (int64 (char (255)), int64 (255))
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
848 */