Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Bug with std::numeric_limits<T>infinity with -compat=g using Studio 12.4

RyanOliverFeb 3 2016 — edited Feb 4 2016

Firstly, relevant details

OS/Arch: Solaris 11.2 SRU 15.5.1 on SPARC (T4)

Studio Version - Solaris Studio 12.4 (From solarisstudio IPS publisher, current)

Unless I am missing something, it seems when compiling using the gnu C++ ABI std::numeric_limits<T>infinity() isn't returning the correct values.

Sample code attached compiles and works correctly using g++ 4.8.2 (-std=c++11) and Solaris Studio 12.5 Beta (so it is a solved problem)

#include <cstdlib>
#include <cmath>
#include <cassert>
#include <limits>
#include <iostream>

int main() {
        double inf = std::numeric_limits<double>::infinity();
        double neginf = -std::numeric_limits<double>::infinity();
        float finf = std::numeric_limits<float>::infinity();
        float fneginf = -std::numeric_limits<float>::infinity();
        long double linf = std::numeric_limits<long double>::infinity();
        long double lneginf = -std::numeric_limits<long double>::infinity();
        std::cout << "Inf: " << inf << std::endl;
        std::cout << "-Inf: " << neginf << std::endl;
        std::cout << "float Inf: " << inf << std::endl;
        std::cout << "float -Inf: " << neginf << std::endl;
        std::cout << "long double Inf: " << inf << std::endl;
        std::cout << "long double -Inf: " << neginf << std::endl;

        assert(std::isinf(inf));
        assert(std::isinf(neginf));
        assert(std::isinf(finf));
        assert(std::isinf(fneginf));
        assert(std::isinf(linf));
        assert(std::isinf(lneginf));

        return EXIT_SUCCESS;
}

For 12.4 it returns

Inf: 1.06048e-314
-Inf: -1.06048e-314
float Inf: 1.06048e-314
float -Inf: -1.06048e-314
long double Inf: 1.06048e-314
long double -Inf: -1.06048e-314
Assertion failed: std::isinf(inf), file foo.cc, line 21
Abort (core dumped)

Its certainly not giving back HUGE_VAL{,L,F}

Stripping out the assertions and isinf checks the above also does what you expect it to do using RW libCstd, stlport4 and stdcxx4.

Is there any quick and dirty fix?

This post has been answered by RyanOliver on Feb 3 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 3 2016
Added on Feb 3 2016
2 comments
784 views