Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

Same operation, different results

$
0
0

Hi,

    When executing the program below, icc produced different results for Y and Y2. The result of Y is 12. I guess it multiplied the VALUE constant first, and got the result of 4, then cast the int 4 as long long type. Finally it is multiplied by 3 to get 12. And the value of Y2 is -4611686044197191668. Instead, it is possible to convert the type t to long long first and then multiply the variables t to produce the result of 4611686009837453316 which is long long type. Finally it is multiplied by 3 to get -4611686044197191668.

    Is this a correct behavior for intel c complier?  Sorry if i misunderstood something.

 

TestCase:

 

#include <stdio.h>

#define VALUE ((int)((long long)U1 * (long long)3) + 2)

 

int main(void)

{

    long long Y, Y2;

    int U1;

    int t;

    U1 = -2147483648;

    Y = ((long long)(VALUE * VALUE) * 3);

    t = VALUE;

    Y2 = ((long long)(t * t) * 3);

    if (Y != Y2)

        printf("%lld,%lld\n", Y, Y2);

    return 0;

}

 

The OS is:

Linux version 4.15.0-65-generic

 

Compiler Version:

icc (ICC) 19.0.4.243 20190416

 

Output:

12,-4611686044197191668

 

Expected output:

12,12

TCE Open Date: 

Friday, February 14, 2020 - 05:24

Viewing all articles
Browse latest Browse all 1175

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>