String to integer conversions

There are various functions for converting strings to integers in the C++ standard library. This post is a small overview of these functions. I’ll start with the simplest and go to the more fully featured ones at the end. The atoi family. These functions coming from C represent the minimal set of functionality for a string to integer conversion. int atoi(const char *str); It only takes a single argument, a c-string and interprets it as a base-10 number. [Read More]

Floating point to integer conversion

This post serves mainly as a personal reminder and came up due to a question on stackoverflow.com. The question was: How exactly does C++ casting between numeric types work? In my code, I do something like the following: double a = 3.0; uint64_t b = static_cast(a); double c = static_cast(b); Interestingly, this works as I would expect (a == c), as long as a is positive, but if a is negative, c ends up as an arbitrarily large positive number. [Read More]