Skip to content

Support hexfloat in cstdfloat_iostream.hpp - #1471

Merged
NAThompson merged 1 commit into
developfrom
issue-1118
Sep 19, 2026
Merged

NAThompson merged 1 commit into
developfrom
issue-1118

Conversation

@NAThompson

Copy link
Copy Markdown
Collaborator

No description provided.

@NAThompson

Copy link
Copy Markdown
Collaborator Author

Main file which exhibits the fix:


#include <iomanip>
#include <iostream>
#include <sstream>

int main()
{
    using boost::float128_t;

    const float128_t x =
        BOOST_FLOAT128_C(3.141592653589793238462643383279502884);

    // Exercise hexfloat output.
    std::stringstream ss;
    ss << std::hexfloat << x;

    std::cout << "hexfloat: " << ss.str() << '\n';

    // Exercise hexfloat input / round-trip.
    float128_t y = 0;
    ss >> y;

    std::cout << "round-trip equal: " << std::boolalpha << (x == y) << '\n';

    // Precision should not affect std::hexfloat.
    std::stringstream a;
    std::stringstream b;

    a << std::hexfloat << std::setprecision(3)  << x;
    b << std::hexfloat << std::setprecision(30) << x;

    std::cout << "precision 3:  " << a.str() << '\n';
    std::cout << "precision 30: " << b.str() << '\n';
    std::cout << "same: " << (a.str() == b.str()) << '\n';

    // Uppercase hexfloat.
    std::stringstream upper;
    upper << std::uppercase << std::hexfloat << x;

    std::cout << "uppercase: " << upper.str() << '\n';

    // Directly parse a hexadecimal floating-point value.
    std::stringstream in("0x1.921fb54442d18469898cc51701b8p+1");

    float128_t z = 0;
    in >> z;

    std::cout << "parsed pi equal: " << (z == x) << '\n';
}

On develop:

➜  math git:(develop) ✗ ./a.out
hexfloat: 3.141593e+00
round-trip equal: false
precision 3:  3.142e+00
precision 30: 3.141592653589793238462643383280e+00
same: false
uppercase: 3.141593e+00
parsed pi equal: false

And on this branch:

➜  math git:(develop) ✗ ./a.out
hexfloat: 3.141593e+00
round-trip equal: false
precision 3:  3.142e+00
precision 30: 3.141592653589793238462643383280e+00
same: false
uppercase: 3.141593e+00
parsed pi equal: false

Closes #1118

@NAThompson

Copy link
Copy Markdown
Collaborator Author

@ckormanyos: If you could take a quick look . . .

@NAThompson
NAThompson merged commit dde3200 into develop Sep 19, 2026
64 of 66 checks passed
@NAThompson
NAThompson deleted the issue-1118 branch September 19, 2026 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant