Coder Social home page Coder Social logo

Comments (3)

kripken avatar kripken commented on May 30, 2024

Could be undefined behavior. Try with -fsanitize=undefined.

If it's not that, please reduce this to a small testcase that is simple to compile (without gtest and other external things).

from emscripten.

pgeorge1324 avatar pgeorge1324 commented on May 30, 2024

@kripken

Could be undefined behavior. Try with -fsanitize=undefined.

If it's not that, please reduce this to a small testcase that is simple to compile (without gtest and other external things).

I wrote a testcase with minimal external things, finally i found the compile option -ffast-math used in my project is the main crime.
I know it is a compile option in gcc, does new emscripten has some similiar compile option?

#include <iostream>
#include <limits>

static const float M_INF = std::numeric_limits<float>::infinity();

int main()
{
    std::cout << std::isinf(std::numeric_limits<float>::infinity()) << std::endl;
    std::cout << std::isinf(M_INF) << std::endl;
    std::cout << (M_INF == std::numeric_limits<float>::infinity()) << std::endl;

    std::cout << "Hello, World!" << std::endl;
    return 0;
}
>> em++ .\main.cpp -ffast-math -O3 -o test.js
>> node test.js
0
0
0
Hello, World!
>> em++ .\main.cpp -O3 -o test.js            
>> node test.js                  
1
1
1
Hello, World!

from emscripten.

pgeorge1324 avatar pgeorge1324 commented on May 30, 2024

I solved it with compile option -fhonor-infinities
Clang manual has more detail information about it: clang manual

>>em++ .\main.cpp -ffast-math -fhonor-infinities -O3 -o test.js
>> node test.js                                                 
1
1
1
Hello, World!

Thanks for your reply @kripken

from emscripten.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.