Thanks for using Compiler Explorer
Jakt
C++
Ada
Analysis
Assembly
C
Carbon
C++ (Circle)
CIRCT
Clean
CMake
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Erlang
Fortran
F#
Go
Haskell
HLSL
Hook
ispc
Java
Julia
Kotlin
LLVM IR
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Scala
Solidity
Swift
Toit
TypeScript Native
Visual Basic
Zig
c++ source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Compiler
FreeBSD clang 13.0.0
p0849 (modified clang 12)
Options
Source code
#include <cerrno> #include <cmath> #include <cstdlib> #include <stdexcept> #include <string_view> auto parse_float64(std::string_view s) -> double { char* ed = nullptr; errno = 0; auto v = std::strtod(s.data(), &ed); if (errno != 0) { auto msg = std::signbit(v) ? "negative" : "positive"; if (v == 0) throw std::underflow_error{msg}; else throw std::overflow_error{msg}; } else { if (ed == std::to_address(s.end())) return v; else throw std::invalid_argument{"extra bytes"}; } } #include <iostream> int main() { using namespace std::literals; for (auto flt : { "3.14e-400", "42.2172", "-1.3e1000", "5.e1000", "-2.4e-1024", }) { try { std::cout << flt << " --> " << parse_float64(flt) << '\n'; } catch (std::underflow_error& exc) { std::cout << "undeflow: " << exc.what() << '\n'; } catch (std::overflow_error& exc) { std::cout << "overflow: " << exc.what() << '\n'; } catch (std::invalid_argument& exc) { std::cout << "failed to parse: " << exc.what() << '\n'; } } }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
About the author
Changelog
Version tree