The following looks like errant behavior:

entity fp_parse_bug is
end entity;

architecture bug of fp_parse_bug is
  type real_vector is array (natural range <>) of real;
  constant ones : real_vector(1 to 15) := (
    0.9,
    0.999,
    0.999999,
    0.99999999,
    0.9999999999,
    0.999999999999,
    0.99999999999999,
    0.9999999999999999,
    0.999999999999999999,
    0.99999999999999999999,
    0.9999999999999999999999,
    0.999999999999999999999999,
    0.99999999999999999999999999,
    0.9999999999999999999999999999,
    0.999999999999999999999999999999
    );
begin
  process is
  begin
    for i in ones'range loop
      report real'image(ones(i)) severity note;
    end loop;
    wait;
  end process;
end architecture;

$ ghdl -i fp_parse_bug.vhdl && ghdl -m fp_parse_bug && ./fp_parse_bug 
fp_parse_bug.vhdl:27:7:@0ms:(report note): 9.0e-1
fp_parse_bug.vhdl:27:7:@0ms:(report note): 9.99e-1
fp_parse_bug.vhdl:27:7:@0ms:(report note): 9.99999e-1
fp_parse_bug.vhdl:27:7:@0ms:(report note): 9.999999899999998e-1
fp_parse_bug.vhdl:27:7:@0ms:(report note): 9.999999998999999e-1
fp_parse_bug.vhdl:27:7:@0ms:(report note): 9.99999999999e-1
fp_parse_bug.vhdl:27:7:@0ms:(report note): 9.9999999999999e-1
fp_parse_bug.vhdl:27:7:@0ms:(report note): 9.999999999999998e-1
fp_parse_bug.vhdl:27:7:@0ms:(report note): 1.0
fp_parse_bug.vhdl:27:7:@0ms:(report note): 1.0
fp_parse_bug.vhdl:27:7:@0ms:(report note): 1.0
fp_parse_bug.vhdl:27:7:@0ms:(report note): 1.0
fp_parse_bug.vhdl:27:7:@0ms:(report note): 3.728534220838433e7
fp_parse_bug.vhdl:27:7:@0ms:(report note): 1.804034495613185e15
fp_parse_bug.vhdl:27:7:@0ms:(report note): 1.309073718033478e18

I sure don't expect 1.31e18 and friends when I enter an approximation to 
1.0! I know I've started to put more digits in than the precision of a 
real, but shouldn't this just be dropped, instead of corrupting the number? 

For comparison, here is how it's handled in C:

#include <stdio.h>

int main() {
  printf("%.15f\n", 0.9);
  printf("%.15f\n", 0.999);
  printf("%.15f\n", 0.999999);
  printf("%.15f\n", 0.99999999);
  printf("%.15f\n", 0.9999999999);
  printf("%.15f\n", 0.999999999999);
  printf("%.15f\n", 0.99999999999999);
  printf("%.15f\n", 0.9999999999999999);
  printf("%.15f\n", 0.999999999999999999);
  printf("%.15f\n", 0.99999999999999999999);
  printf("%.15f\n", 0.9999999999999999999999);
  printf("%.15f\n", 0.999999999999999999999999);
  printf("%.15f\n", 0.99999999999999999999999999);
  printf("%.15f\n", 0.9999999999999999999999999999);
  printf("%.15f\n", 0.999999999999999999999999999999);
}

$ gcc -o nobug nobug.c
$ ./nobug
0.900000000000000
0.999000000000000
0.999999000000000
0.999999990000000
0.999999999900000
0.999999999999000
0.999999999999990
1.000000000000000
1.000000000000000
1.000000000000000
1.000000000000000
1.000000000000000
1.000000000000000
1.000000000000000
1.000000000000000


-- 
Wesley J. Landaker <[EMAIL PROTECTED]> <xmpp:[EMAIL PROTECTED]>
OpenPGP FP: 4135 2A3B 4726 ACC5 9094  0097 F0A9 8A4C 4CD6 E3D2

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Ghdl-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/ghdl-discuss

Reply via email to