pmed / v8pp

Bind C++ functions and classes into V8 JavaScript engine
http://pmed.github.io/v8pp/
Other
901 stars 121 forks source link

use std::numeric_limits::lowest() #188

Closed MangelSpec closed 1 year ago

MangelSpec commented 1 year ago

prevent issues with floating point type conversations since min doesn't return the actual minimum possible number. as an example where this caused issues:

void variant_test(std::variant<float, bool> test)
{
    printf("variant_test: ");
    if(std::holds_alternative<float>(test))
    {
        printf("float: %f\n", std::get<float>(test));
    }
    else if (std::holds_alternative<bool>(test))
    {
        printf("bool: %d\n", std::get<bool>(test));
    }
}

registering this function to javascript and calling it with (0) as argument will give the error "Unable to convert argument to variant."

image

pmed commented 1 year ago

Hi @MangelSpec

good catch, thanks a lot!

I've rebased your PR and fixed test case in #191, so I close this one.