Bizarre floating-point behavior with vs. without extra variables, why?

后端 未结 4 483
终归单人心
终归单人心 2021-01-18 01:27

When I run the following code in VC++ 2013 (32-bit, no optimizations):

#include 
#include 
#include 

double mulpow         


        
4条回答
  •  耶瑟儿~
    2021-01-18 02:21

    9223372036854775808 is 0x8000000000000000; that is, it is equal to INT64_MIN cast to uint64_t.

    It looks like your compiler is casting the return value of floor to long long and then casting that result to unsigned long long.

    Note that it is quite usual for overflow in floating-point-to-integral conversion to yield the least representable value (e.g. cvttsd2siq on x86-64):

    When a conversion is inexact, a truncated result is returned. If a converted result is larger than the maximum signed doubleword integer, the floating-point invalid exception is raised, and if this exception is masked, the indefinite integer value (80000000H) is returned.

    (this is from the doubleword documentation, but the quadword behaviour is the same.)

提交回复
热议问题