r/cpp • {fmt} • Dec 02 '19

{fmt} 6.1 released with improved floating-point formatting, locale support, faster compile times and more

https://github.com/fmtlib/fmt/releases/tag/6.1.0
212 Upvotes

34 comments sorted by

View all comments

11

u/boredcircuits Dec 02 '19

Awesome work!

I'm curious, what's the rationale behind this change?

Changed formatting of octal zero with prefix from "0o0" to "0":

13

u/aearphen {fmt} Dec 02 '19

Thanks! The rationale is consistency with C++20 `std::format` and more generally with the syntax of octal numbers in C++. `0o` is a Pythonism and doesn't mean anything in C++.

8

u/sahsahaha Dec 02 '19

Huh?

Isn't it just common sense that if 0x is for hex, then surely...

No, I didn't expect familiar things to have familiar prefixes or anything at all.

23

u/aearphen {fmt} Dec 02 '19

Personally I'd prefer if C and C++ used `0o` for octal but that ship has sailed long time ago =).

1

u/nintendiator2 Dec 04 '19

This has always irked me about C and C++. It makes it a pita to format numbers in arrays and stuff like that nicely, for when you are splitting off numbers in source code with thousands separators and the like.

Then again, I guess it better stays at it is. If the Committee attempt to fix it they are likely to force all decimal literals to be 0a....

9

u/[deleted] Dec 02 '19

[removed] — view removed comment

8

u/[deleted] Dec 02 '19

fun fact, all zero literals are octal as they start with zero

-2

u/[deleted] Dec 03 '19

[removed] — view removed comment

6

u/[deleted] Dec 03 '19

the literal doesn't reflect the representation, if i understand correctly. So whether you put 0x10, 16, 0b10000, or 020 they are all represented the same in memory. So 6 + 0x10 is the same as 6 + 16

1

u/mujjingun Dec 03 '19

no, 0+6 is decimal 6 because octal 0 + decimal 6 = decimal 6.

0

u/[deleted] Dec 03 '19

[removed] — view removed comment

5

u/mujjingun Dec 03 '19

There is no rule. Once the numbers get interpreted as a certain base, there is no base anymore, they are just numbers. Octal 0 = zero, decimal 6 = six. zero plus six = six.

1

u/sahsahaha Dec 03 '19

The issue is that I simply didn't know as I never really needed octal for anything.

And then, my question kind of becomes... Why?

Was octal introduced before hexadecimal?

4

u/boredcircuits Dec 03 '19

I get that much, bit the description here implies that 0o is still used for other numbers besides 0. So 8 is printed as 0o10, but 0 is printed as 0 instead of 0o0. That's bizarre behavior.

But maybe I'm reading to much into that description, and it's using the unfortunate 0 prefix across the board for octal, so 8 prints as 010? That's more understandable, at least. And consistent.

I do hope scnlib or whatever it's called allows for parsing both types of prefixes. Leading zeros turning decimal numbers to octal was a mistake. But it's less of a problem with printing, as you can just make up your own prefix if you need.

5

u/aearphen {fmt} Dec 03 '19

Actually there is a mistake in the changelog. The change was from `00` to `0`, not from `0o0` to `0`. I'll fix the description.

4

u/boredcircuits Dec 03 '19

Ah. That makes so much more sense!