[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug 1815423] Re: x86_64 TCG: Incorrect floating point cast to int.

From: Thomas Huth
Subject: [Bug 1815423] Re: x86_64 TCG: Incorrect floating point cast to int.
Date: Thu, 09 Jan 2020 13:23:06 -0000

** Changed in: qemu
       Status: Fix Committed => Fix Released

You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

  x86_64 TCG: Incorrect floating point cast to int.

Status in QEMU:
  Fix Released

Bug description:
  I used exaample from:

  #include <stdio.h>
  #include <math.h>

  int main(int argc, char** argv) {
    float a = INFINITY;
    float b = -INFINITY;
    float c = NAN;

    printf("float %f %f %f\n", a, b, c); 
    printf("int %d %d %d\n", (int) a, (int) b, (int) c); 
    printf("uint %u %u %u\n", (unsigned int) a, (unsigned int) b, (unsigned 
int) c); 
    printf("lint %ld %ld %ld\n", (long int) a, (long int) b, (long int) b); 
    printf("luint %lu %lu %lu\n", (unsigned long int) a, (unsigned long int) b, 
(unsigned long int) c); 

    return 0;

  And got different results on real computer and on qemu.

  output from real HW is the same as on stackoverflow:

  $ gcc test.c && ./a.out 
  float inf -inf nan
  int -2147483648 -2147483648 -2147483648
  uint 0 0 0
  lint -9223372036854775808 -9223372036854775808 -9223372036854775808
  luint 0 9223372036854775808 9223372036854775808

  But on qemu I got another results:

  float inf -inf nan
  int 2147483647 -2147483648 2147483647
  uint 4294967295 0 4294967295
  lint 9223372036854775807 -9223372036854775808 -9223372036854775808
  luint 18446744073709551615 9223372036854775808 9223372036854775807

  qemu launch string:
  /qemu-system-x86_64 -m 1024 -cpu core2duo -serial stdio -netdev 
user,id=network0 -device e1000,netdev=network0 -kernel my_kernel

  qemu version:
  x86_64-softmmu/qemu-system-x86_64 --version
  QEMU emulator version 3.1.50 (v3.1.0-1676-ge47f81b617-dirty)
  Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers

  This bug affect some javascript (surprise) calculations:

  var conversion = "01234567890";
  var x;
  var result = conversion[x & 42];

  In example, var x is "undefined"
  and when do calculation "x & 42" on js we should get 0 (it is documented 
feature), but actually got "42"

  and "result" sould be "0" but actually we got "undefined"

To manage notifications about this bug go to:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]