Skip to content

ConvertStringToDouble slightly wrong #2

Description

@benibela

I have run it with the test cases of https://github.com/nigeltao/parse-number-fxx-test-data and it finds many slightly broken numbers

For example:

parsing failed: 8.589934335999999523162841796875e+09 ( 8.5899343360000000E+009) got  8.5899343359999990E+009
parsing failed: 9008309105029287 ( 9.0083091050292880E+015) got  9.0083091050292860E+015
parsing failed: 9009640786128499 ( 9.0096407861285000E+015) got  9.0096407861284980E+015
parsing failed: 9009650242502435 ( 9.0096502425024360E+015) got  9.0096502425024340E+015
parsing failed: 9009859112919659 ( 9.0098591129196600E+015) got  9.0098591129196580E+015
parsing failed: 9010553528704491 ( 9.0105535287044920E+015) got  9.0105535287044900E+015
parsing failed: 9010674631189967 ( 9.0106746311899680E+015) got  9.0106746311899660E+015
parsing failed: 9011342073688603 ( 9.0113420736886040E+015) got  9.0113420736886020E+015
parsing failed: 9011683300034947 ( 9.0116833000349480E+015) got  9.0116833000349460E+015
parsing failed: 9013156506727407 ( 9.0131565067274080E+015) got  9.0131565067274060E+015

... parsingfail.txt

program Project1;

{$mode objfpc}{$H+}

uses sysutils, PasDblStrUtils;

var s, expected: string;
  t: TStringArray;
  d: double;
  code: integer;
  expectedU64: QWord;
  expectedD: double absolute expectedU64;
begin
  while not eof do begin
    try
      readln(s);
      t := s.split(' ');
      //val(t[3], d, code);
      //if code <> 0 then writeln(s);
      d := ConvertStringToDouble(t[3]);
      expected := '$'+t[2];
      val(expected, expectedU64, code);
      if code <> 0 then writeln('true failed: ',s);
      if expectedD <> d then
        writeln('parsing failed: ', t[3], ' (', expectedD, ') got ',d);
    except
      writeln('exception: ', s);
    end;
  end;
end.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions