MathMax/MathMin giving (maybe) wrong results.

 

While working on the project "Build an API-Tracer", which is finally done and published, I came across this "issue". 

Is this considered a bug? Or not. To my understanding it is a bug.


    Print(FLT_MAX);
    Print(LONG_MAX);
    Print(MathMax(FLT_MAX, LONG_MAX));


This code will give FLT_MAX as result, but shouldnt it give LONG_MAX as result??


Here is the output from my shiny new API-Tracer... 

 
Dominik Christian Egert:

While working on the project "Build an API-Tracer", which is finally done and published, I came across this "issue". 

Is this considered a bug? Or not. To my understanding it is a bug.



This code will give FLT_MAX as result, but shouldnt it give LONG_MAX as result??


Here is the output from my shiny new API-Tracer... 

Why do you think it should give the result LONG_MAX? FLT_MAX is twenty orders of magnitude greater than LONG_MAX (FLT_MAX: 3.402823e+38 ; LONG_MAX: 9.223372e+18).

 
Petr Nosek #:

Why do you think it should give the result LONG_MAX? FLT_MAX is twenty orders of magnitude greater than LONG_MAX (FLT_MAX: 3.402823e+38 ; LONG_MAX: 9.223372e+18).

Ohh, I missed that "detail", thank you for pointing this out.

 

long is 64 bits: 1 sign bit + 63 integer bits (the magnitude is determined by integer bits)

  So, LONG_MAX ≈ 2^63 (9.223372036854775808e+18)


float is 32 bits: 1 sign bit + 8 exponent bits + 23 mantissa bits (the magnitude is determined by 2^(exponent bits - 1))

  So, FLT_MAX ≈ 2^ (2^7) 2^128 (3.40282366e+38)


double is 64 bits: 1 sign bit + 11 exponent bits + 52 mantissa bits (the magnitude is determined by 2^(exponent bits - 1))

  So, DBL_MAX ≈ 2^ (2^10) 2^1024 (1.7976931348623158e+308)