-
Notifications
You must be signed in to change notification settings - Fork 1
🧹 [Refactor IEEE 80-bit float conversion using std::ldexp] #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -626,8 +626,7 @@ double ChunkDemuxer::ieee80ToDouble(const uint8_t ieee80[10]) const { | |||||
| } | ||||||
|
|
||||||
| // Convert to double | ||||||
| double result = static_cast<double>(mantissa) / (1ULL << 63); | ||||||
| result *= std::pow(2.0, static_cast<int>(exponent) - 16383); | ||||||
| double result = std::ldexp(static_cast<double>(mantissa), exponent - 16383 - 63); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the explicit
Suggested change
|
||||||
|
|
||||||
| return sign ? -result : result; | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exponentis auint16_t; the expressionexponent - 16383 - 63relies on integer promotions and may become unsigned arithmetic on platforms whereintcan’t represent alluint16_tvalues (e.g., 16-bitint), causing wraparound and incorrect scaling. To preserve the previous semantics and avoid implementation-defined conversions intostd::ldexp’sintexponent parameter, castexponenttoint(or assign to anintlocal) before doing the bias/shift subtraction.