Integer on Raphael Addilehttps://raphaeladdile.com/tags/integer/
Recent content in Integer on Raphael AddileHugo -- gohugo.ioraphael.addile@gmail.com (Raphael Miedl)raphael.addile@gmail.com (Raphael Miedl)Sun, 11 May 2014 00:00:00 +0000String to integer conversionshttps://raphaeladdile.com/post/string-to-integer-conversions/
Sun, 11 May 2014 00:00:00 +0000raphael.addile@gmail.com (Raphael Miedl)https://raphaeladdile.com/post/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.Floating point to integer conversionhttps://raphaeladdile.com/post/floating-point-to-integer-conversion/
Wed, 26 Mar 2014 00:00:00 +0000raphael.addile@gmail.com (Raphael Miedl)https://raphaeladdile.com/post/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.