https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87744
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- Based on that, I'm not sure what libc++ does is actually better than what libstdc++ does today (i.e. refuse to compile if the results would be wrong). I think the patch above would make sense though. I'm sure it could be optimized, I was more concerned with getting the results right than with performance. The first loop in operator% could just be a single left shift by the difference in the number of leading zeros between __l and __x. And halve() should just be a right shift (and "halve" isn't a reserved name).