[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-22 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

--- Comment #6 from Paolo Carlini paolo.carlini at oracle dot com ---
Thanks Janis. In C++11 we have *explicit* conversion operators. Would they
help? A safe approach woould providing the operators only in c++11 mode.


[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-22 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

--- Comment #7 from Paolo Carlini paolo.carlini at oracle dot com ---
Something like:

Index: include/decimal/decimal
===
--- include/decimal/decimal(revision 203915)
+++ include/decimal/decimal(working copy)
@@ -250,8 +250,10 @@
 /// Conforming extension: Conversion from scalar decimal type.
 decimal32(__decfloat32 __z): __val(__z) {}

-// 3.2.2.5  Conversion to integral type. (DISABLED)
-//operator long long() const { return (long long)__val; }
+#if __cplusplus = 201103L
+// 3.2.2.5  Conversion to integral type.
+explicit operator long long() const { return (long long)__val; }
+#endif

 // 3.2.2.6  Increment and decrement operators.
 decimal32 operator++()
@@ -333,8 +335,10 @@
 /// Conforming extension: Conversion from scalar decimal type.
 decimal64(__decfloat64 __z): __val(__z) {}

-// 3.2.3.5  Conversion to integral type. (DISABLED)
-//operator long long() const { return (long long)__val; }
+#if __cplusplus = 201103L
+// 3.2.3.5  Conversion to integral type.
+explicit operator long long() const { return (long long)__val; }
+#endif

 // 3.2.3.6  Increment and decrement operators.
 decimal64 operator++()
@@ -417,8 +421,10 @@
 /// Conforming extension: Conversion from scalar decimal type.
 decimal128(__decfloat128 __z): __val(__z) {}

-// 3.2.4.5  Conversion to integral type. (DISABLED)
-//operator long long() const { return (long long)__val; }
+#if __cplusplus = 201103L
+// 3.2.4.5  Conversion to integral type.
+explicit operator long long() const { return (long long)__val; }
+#endif

 // 3.2.4.6  Increment and decrement operators.
 decimal128 operator++()


[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-22 Thread daniel.kruegler at googlemail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

--- Comment #8 from Daniel Krügler daniel.kruegler at googlemail dot com ---
(In reply to Paolo Carlini from comment #6)
I also would like to encourage using explicit conversion functions. This is
explicitly suggested in the updated C++11 integration document:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3407.html

[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-22 Thread janis at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

--- Comment #9 from Janis Johnson janis at gcc dot gnu.org ---
I haven't paid attention to decimal float since leaving IBM, so it was very
interesting to see the updated C++11 working paper.  It makes sense to me to
use C++11 functionality in the GNU C++ decimal float support, especially in the
case of explicit conversions.


[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-22 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

Paolo Carlini paolo.carlini at oracle dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2013-10-22
   Assignee|unassigned at gcc dot gnu.org  |paolo.carlini at oracle 
dot com
 Ever confirmed|0   |1

--- Comment #10 from Paolo Carlini paolo.carlini at oracle dot com ---
Ah good, thanks Janis. Thus let's add in C++11 mode these explicit operators
with a comment pointing to n3407. More than that is beyond the scope of this PR
but it would be nice if somebody volunteers to follow the topic, prepares
patches, etc.


[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-22 Thread q1 at oxyba dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

--- Comment #11 from ulf q1 at oxyba dot de ---
i see evil implicit conversion. 

i modified lines 254, 337 and 421 to 

explicit operator long long() const { return (long long)__val; }

like suggested in n3407.



#includedecimal/decimal
int main(){
  std::decimal::decimal32 x(101.5051);
  long long a = (long long)x; // OK
  long long b = static_castlong long(x); // OK
  //long long c = x; // error
  //long d = (long)x; // error
  //long e = static_castlong(x); // error

  std::decimal::decimal64 y(101.5051);
  long long f = (long long)y; // OK
  long long g = static_castlong long(y); // OK
  //long long h = y; // error
  //long i = (long)y; // error
  //long j = static_castlong(y); // error

  std::decimal::decimal128 z(101.5051);
  long long k = (long long)z; // OK
  long long l = static_castlong long(z); // OK
  //long long m = z; // error
  //long n = (long)z; // error
  //long o = static_castlong(z); // error
  return 0;
}


some other issues regarding std::decimal

std::is_decimal_floating_pointstd::decimal::decimalXXX in type_traits 

see page 7, chapter 3.11.1 and 2 (page 62) in
www.open-std.org/jtc1/sc22/open/n4112.pdf

std::numeric_limitsstd::decimal::decimalXXX in limits

see chapter 3.3 in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1977.html


[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-22 Thread janis at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

--- Comment #12 from Janis Johnson janis at gcc dot gnu.org ---
I obviously don't know C++ very well and the decimal float support in libstdc++
is very ugly.  It would be nice if someone rewrites it in actual C++ someday;
the tests should help with that effort.


[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-22 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

--- Comment #13 from Paolo Carlini paolo.carlini at oracle dot com ---
Thus, let's make a decision: either this is a bug, importance minor as
submitted, about conversions to integer, as appeared to be, or it's a catch all
bug about all the issues with the TR decimal + all the work toward a C++17
standard facility.


[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-21 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

--- Comment #2 from Paolo Carlini paolo.carlini at oracle dot com ---
In any case, keep in mind ulf that we are looking for help in this area: for
various reasons, the code isn't really maintained these days (eg, the original
implementor moved to another job, etc) Thus, contributions welcome!


[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-21 Thread q1 at oxyba dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

ulf q1 at oxyba dot de changed:

   What|Removed |Added

 CC||janis187 at us dot ibm.com

--- Comment #3 from ulf q1 at oxyba dot de ---
i checked the code in the file decimal (/usr/include/c++/4.7/decimal/). The
programmer already considered conversion to integers. however the lines are
commented. 


for std::decimal::decimal32
...
line 253   // 3.2.2.5  Conversion to integral type. (DISABLED)
line 254   //operator long long() const { return (long long)__val; }
... 

for std::decimal::decimal64
...
line 336   // 3.2.3.5  Conversion to integral type. (DISABLED)
line 337   //operator long long() const { return (long long)__val; }
... 

for std::decimal::decimal128
...
line 420   // 3.2.4.5  Conversion to integral type. (DISABLED)
line 421   //operator long long() const { return (long long)__val; }
... 

i uncommented it and my problems were gone. but for some reason the code is
disabled on purpose. what is the reason for it?


[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-21 Thread janis at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

--- Comment #4 from Janis Johnson janis at gcc dot gnu.org ---
I vaguely remember a problem with those conversion and have no idea now what it
was, but I'll try to find something in the mailing list archives.

decimal/decimal includes a workaround:

  /// Non-conforming extension: Conversion to integral type.
  long long decimal32_to_long_long(decimal32 __d);
  long long decimal64_to_long_long(decimal64 __d);
  long long decimal128_to_long_long(decimal128 __d);
  long long decimal_to_long_long(decimal32 __d);
  long long decimal_to_long_long(decimal64 __d);
  long long decimal_to_long_long(decimal128 __d);


[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-21 Thread janis at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

--- Comment #5 from Janis Johnson janis at gcc dot gnu.org ---
From Janis in http://gcc.gnu.org/ml/libstdc++/2009-09/msg00115.html

The TR defines, within each of the classes decimal32, decimal64, and
decimal128, the following conversion:

  // 3.2.[234].4 conversion to integral type:
  operator long long() const;

Apparently there's a way to implement this if one knows enough about
C++, but providing this implicit conversion from a decimal float type to
long long allows further implicit conversions from long long to other
types, including float, double, and long double, which are not supposed
to be allowed.  Furthermore, a conversion from a decimal float type to a
generic float type that goes through long long truncates the fractional
part of the value which is rather surprising.  This version of the patch
leaves out that conversion and provides a set of functions to convert to
long long, which made testing the rest of the functionality much easier.
Any suggestions for how to do with using the current (not C++0x)
standard?  Or is it OK to require the use of C++0x functionality with
this extension?

From Benjamin Kosnik in http://gcc.gnu.org/ml/libstdc++/2009-09/msg00127.html

I think it is not ok to require the use of C++0x with the
decimal floating point extension. It is clearly designed with C++2003 in
mind, and makes no use of C++0x features.

When you post testsuite files demonstrating this issue in detail I'll
take a look at this overload issue.

From Janis in http://gcc.gnu.org/ml/libstdc++/2009-10/msg4.html

With the submission on Monday I mentioned that this patch does not
support an implicit conversion to integral types (long long) from each
of the decimal classes.  Those are in the patch, commented out and with
a comment that now says (DISABLED).  If those are not disabled then all
of the error checks in the bad-*.cc tests fail.  I can't see how to
allow implicit conversions to long long while also prohibiting bitwise
operations with decimal floating-point operands or conversions and
casts to generic floating-point types.

I didn't find any further discussion of this issue.


[Bug c++/58815] Casting/Conversion operator for std::decimal not supported

2013-10-20 Thread daniel.kruegler at googlemail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58815

Daniel Krügler daniel.kruegler at googlemail dot com changed:

   What|Removed |Added

 CC||daniel.kruegler@googlemail.
   ||com

--- Comment #1 from Daniel Krügler daniel.kruegler at googlemail dot com ---
The notion of throws an error is somewhat misleading in this context. What
you intend to describe is that the compiler rejects the code.