| Issue |
166699
|
| Summary |
to_chars_floating_point.h assumes `int` is 32 bits
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
ZERICO2005
|
`to_chars_floating_point.h` uses `int` `unsigned int` in places where `int32_t` or `uint32_t` should be used instead
https://github.com/llvm/llvm-project/blob/main/libcxx/src/include/to_chars_floating_point.h
This should be changed to `1ul` or `UINT32_C(1)`
`static constexpr uint32_t _Exponent_mask = (1u << _Exponent_bits) - 1;`
I suppose this could also be changed to `UINT64_C(1)` for consistency as well:
`static constexpr uint64_t _Exponent_mask = (1ULL << _Exponent_bits) - 1;`
https://github.com/llvm/llvm-project/blob/main/libcxx/src/include/ryu/ryu.h
`unsigned int __mask` should be changed to `uint32_t`, and this could probably be changed to use std::countl_zero or etc
```c++
_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward(unsigned long* __index, unsigned int __mask) {
if (__mask == 0) {
return false;
}
*__index = __builtin_ctz(__mask);
return true;
}
```
Comparing `int _Precision` to `1'000'000'000` only works if `int` is larger than 32 bits. I suppose the magic value could be changed to `INT_MAX / 2` or etc to be more portable. `_Floating_to_chars_general_precision` in `to_chars_floating_point.h` uses the value of `1'000'000`.
```c++
template <class _Floating>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI to_chars_result _Floating_to_chars_scientific_precision(
char* const _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
if (_Precision < 0) {
_Precision = 6;
} else if (_Precision < 1'000'000'000) { // Match ' to fix compilation with GCC in C++11 mode
// _Precision is ok.
} else {
// ...
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs