| 1 | // Copyright (C) 2009-2025 Free Software Foundation, Inc. |
| 2 | // |
| 3 | // This file is part of the GNU ISO C++ Library. This library is free |
| 4 | // software; you can redistribute it and/or modify it under the |
| 5 | // terms of the GNU General Public License as published by the |
| 6 | // Free Software Foundation; either version 3, or (at your option) |
| 7 | // any later version. |
| 8 | |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | |
| 14 | // You should have received a copy of the GNU General Public License along |
| 15 | // with this library; see the file COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // { dg-require-effective-target dfprt } |
| 19 | |
| 20 | // ISO/IEC TR 24733 3.2.7 Unary arithmetic operators. |
| 21 | |
| 22 | #include <decimal/decimal> |
| 23 | #include <testsuite_hooks.h> |
| 24 | |
| 25 | using namespace std::decimal; |
| 26 | |
| 27 | decimal32 a32 (20), b32 (-20); |
| 28 | decimal64 a64 (124), b64 (-124); |
| 29 | decimal128 a128 (5001), b128 (-5001); |
| 30 | |
| 31 | void |
| 32 | unary_plus_32 (void) |
| 33 | { |
| 34 | decimal32 a; |
| 35 | |
| 36 | a = +a32; VERIFY (a == a32); |
| 37 | a = +b32; VERIFY (a == b32); |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | unary_minus_32 (void) |
| 42 | { |
| 43 | decimal32 a; |
| 44 | |
| 45 | a = -a32; VERIFY (a == b32); |
| 46 | a = -b32; VERIFY (a == a32); |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | unary_plus_64 (void) |
| 51 | { |
| 52 | decimal64 a; |
| 53 | |
| 54 | a = +a64; VERIFY (a == a64); |
| 55 | a = +b64; VERIFY (a == b64); |
| 56 | } |
| 57 | |
| 58 | void |
| 59 | unary_minus_64 (void) |
| 60 | { |
| 61 | decimal64 a; |
| 62 | |
| 63 | a = -a64; VERIFY (a == b64); |
| 64 | a = -b64; VERIFY (a == a64); |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | unary_plus_128 (void) |
| 69 | { |
| 70 | decimal128 a; |
| 71 | |
| 72 | a = +a128; VERIFY (a == a128); |
| 73 | a = +b128; VERIFY (a == b128); |
| 74 | } |
| 75 | |
| 76 | void |
| 77 | unary_minus_128 (void) |
| 78 | { |
| 79 | decimal128 a; |
| 80 | |
| 81 | a = -a128; VERIFY (a == b128); |
| 82 | a = -b128; VERIFY (a == a128); |
| 83 | } |
| 84 | |
| 85 | int main () |
| 86 | { |
| 87 | unary_plus_32 (); |
| 88 | unary_minus_32 (); |
| 89 | unary_plus_64 (); |
| 90 | unary_minus_64 (); |
| 91 | unary_plus_128 (); |
| 92 | unary_minus_128 (); |
| 93 | } |