lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 41bb715 3/6: Don't respecify the types of flo


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 41bb715 3/6: Don't respecify the types of floating literals
Date: Tue, 16 Jun 2020 15:43:48 -0400 (EDT)

branch: master
commit 41bb715fbfb065d47b32b077096534dcd41137f8
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Don't respecify the types of floating literals
    
    An expression of the form
      simple-type-specifier(expression-list)
    is equivalent [expr.type.conv] to a cast expression (no such syntax is
    available for multiple simple-type-specifiers:
      long double(3.14L); // error
    ). If that cast would be to the same type, it's redundant--for example:
      float(3.14f)
    For floating literals, an 'f' or 'L' suffix (or the lack of any suffix)
    specifies the exact type, so respecifying it is never necessary.
    
    Kept the '-Wuseless-cast' pragma for the block that contains these
    changes because it guards some other casts whose uselessness is less
    obvious or may even be implementation-dependent, e.g.:
        static_cast<char>(   1) // not "useless"
        static_cast<char>('\1') // "useless"
        int( 1234)              // "useless"
---
 numeric_io_test.cpp | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/numeric_io_test.cpp b/numeric_io_test.cpp
index ddf9ecb..c0e8f6b 100644
--- a/numeric_io_test.cpp
+++ b/numeric_io_test.cpp
@@ -267,13 +267,13 @@ int test_main(int, char*[])
     test_interconvertibility(int( 1234),  "1234", __FILE__, __LINE__);
     test_interconvertibility(int(-4321), "-4321", __FILE__, __LINE__);
 
-    test_interconvertibility(float( 0.0f),    "0", __FILE__, __LINE__);
-    test_interconvertibility(float( 1.5f),  "1.5", __FILE__, __LINE__);
-    test_interconvertibility(float(-2.5f), "-2.5", __FILE__, __LINE__);
+    test_interconvertibility(      0.0f,    "0", __FILE__, __LINE__);
+    test_interconvertibility(      1.5f,  "1.5", __FILE__, __LINE__);
+    test_interconvertibility(     -2.5f, "-2.5", __FILE__, __LINE__);
 
-    test_interconvertibility(double( 0.0),    "0", __FILE__, __LINE__);
-    test_interconvertibility(double( 1.5),  "1.5", __FILE__, __LINE__);
-    test_interconvertibility(double(-2.5), "-2.5", __FILE__, __LINE__);
+    test_interconvertibility(      0.0 ,    "0", __FILE__, __LINE__);
+    test_interconvertibility(      1.5 ,  "1.5", __FILE__, __LINE__);
+    test_interconvertibility(     -2.5 , "-2.5", __FILE__, __LINE__);
 
     test_interconvertibility( double(1.0 / 3.0), "0.3333333333333333", 
__FILE__, __LINE__);
     test_interconvertibility(0.3333333333333333, "0.3333333333333333", 
__FILE__, __LINE__);
@@ -282,9 +282,9 @@ int test_main(int, char*[])
 
 #if !defined LMI_MSVCRT
 // COMPILER !! This C runtime doesn't support long double conversions.
-    test_interconvertibility((long double)( 0.0L),    "0", __FILE__, __LINE__);
-    test_interconvertibility((long double)( 1.5L),  "1.5", __FILE__, __LINE__);
-    test_interconvertibility((long double)(-2.5L), "-2.5", __FILE__, __LINE__);
+    test_interconvertibility(      0.0L,    "0", __FILE__, __LINE__);
+    test_interconvertibility(      1.5L,  "1.5", __FILE__, __LINE__);
+    test_interconvertibility(     -2.5L, "-2.5", __FILE__, __LINE__);
     BOOST_TEST_EQUAL(numeric_io_cast<long 
double>("3.36210314311209350626e-4932"), std::numeric_limits<long 
double>::min());
 #endif // !defined LMI_MSVCRT
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]