[llvm-bugs] [Bug 33448] New: static_cast<int16_t>(51200.0f) returns unpredictable value

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 13 22:21:54 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=33448

            Bug ID: 33448
           Summary: static_cast<int16_t>(51200.0f) returns unpredictable
                    value
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vince at nethacker.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

clang version 5.0.0 (trunk 304006)
Target: x86_64-unknown-linux-gnu
Thread model: posix

#include <iostream>

int main() {
  std::cout << static_cast<int16_t>(51200) << std::endl;
  std::cout << static_cast<int16_t>(51200.0f) << std::endl;
  return 0;
}

$ clang++ -std=c++14 static_cast.cpp && ./a.out
-14336
12160
$ clang++ -std=c++11 static_cast.cpp && ./a.out
-14336
-16512

#include <iostream>

int main() {
  std::cout << static_cast<int16_t>(51200.0f) << std::endl;
  return 0;
}

$ clang++ -std=c++11 static_cast.cpp && ./a.out
2176

$ g++ -std=c++11 static_cast.cpp && ./a.out
32767
$ g++ --version
g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170614/b9d9fe8a/attachment.html>


More information about the llvm-bugs mailing list