Skip to content

<locale>: wrong field extraction for hexfloats, or special cases like inf #1259

@fsb4000

Description

@fsb4000

Describe the bug
We don't match strtod / strtof when doing field extraction for hexfloats, or special cases like inf

Command-line test case

C:\Temp>type main.cpp
#include <cassert>
#include <cmath>
#include <sstream>

template<typename Float>
void test()
{
    {
        const char str[] = "0x125p-1 ";
        std::stringstream f(str);
        Float v;
        f >> v;
        assert (v == 0x125p-1);
        assert (f.good());
    }
    {
        const char str[] =  "inf ";
        std::stringstream f(str);
        Float v;
        f >> v;
        assert (v == INFINITY);
        assert (f.good());
    }
    {
        const char str[] =  "INF ";
        std::stringstream f(str);
        Float v;
        f >> v;
        assert (v == INFINITY);
        assert (f.good());
    }
    {
        const char str[] =  "-inf ";
        std::stringstream f(str);
        Float v;
        f >> v;
        assert (v == -INFINITY);
        assert (f.good());
    }
    {
        const char str[] =  "-INF ";
        std::stringstream f(str);
        Float v;
        f >> v;
        assert (v == -INFINITY);
        assert (f.good());
    }
    {
        const char str[] =  "nan ";
        std::stringstream f(str);
        Float v;
        f >> v;
        assert (std::isnan(v));
        assert (f.good());
    }
    {
        const char str[] =  "NAN ";
        std::stringstream f(str);
        Float v;
        f >> v;
        assert (std::isnan(v));
        assert (f.good());
    }
}

int main()
{
    test<float>();
    test<double>();
    test<long double>();

    {
        const char str[] =  "3.40283e+39 "; // unrepresentable
        std::stringstream f(str);
        float v;
        f >> v;
        assert (v == HUGE_VAL);
        assert (f.fail());
    }
    {
        const char str[] = "-3.40283e+38 "; // unrepresentable
        std::stringstream f(str);
        float v;
        f >> v;
        assert (v == -HUGE_VAL);
        assert (f.fail());
    }
    {
        const char str[] =  "1.79779e+309 "; // unrepresentable
        std::stringstream f(str);
        double v;
        f >> v;
        assert (v == HUGE_VAL);
        assert (f.fail());
    }
    {
        const char str[] =  "-1.79779e+308 "; // unrepresentable
        std::stringstream f(str);
        double v;
        f >> v;
        assert (v == -HUGE_VAL);
        assert (f.fail());
    }
    {
        const char str[] = "1.19973e+4933 "; // unrepresentable
        std::stringstream f(str);
        long double v;
        f >> v;
        assert (v == HUGE_VAL);
        assert (f.fail());
    }
    {
        const char str[] = "-1.18974e+4932 "; // unrepresentable
        std::stringstream f(str);
        long double v;
        f >> v;
        assert (v == -HUGE_VAL);
        assert (f.fail());
    }
}

C:\Temp>cl /EHsc /W4 /WX /std:c++17 main.cpp
Оптимизирующий компилятор Microsoft (R) C/C++ версии 19.28.29213 для x64
(C) Корпорация Майкрософт (Microsoft Corporation).  Все права защищены.

main.cpp
Microsoft (R) Incremental Linker Version 14.28.29213.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe
main.obj

C:\Temp>main
Assertion failed: v == 0x125p-1, file main.cpp, line 13

Expected behavior
All tests should pass.

STL version
Microsoft Visual Studio Community 2019 Preview Version 16.8.0 Preview 2.0

Additional context
Skipped libcxx test

# STL bug: We don't match strtod / strtof when doing field extraction for hexfloats, or special cases like inf
std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/get_double.pass.cpp FAIL
std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/get_float.pass.cpp FAIL
std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/get_long_double.pass.cpp FAIL

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions