Przeglądaj źródła

* fixed FormatFloat for non-x86 (mantis 9384)

git-svn-id: trunk@8220 -
Jonas Maebe 18 lat temu
rodzic
commit
49a545aef2
3 zmienionych plików z 18 dodań i 4 usunięć
  1. 1 0
      .gitattributes
  2. 6 4
      rtl/objpas/sysutils/sysstr.inc
  3. 11 0
      tests/webtbs/tw9384.pp

+ 1 - 0
.gitattributes

@@ -8367,6 +8367,7 @@ tests/webtbs/tw9299.pp -text
 tests/webtbs/tw9306a.pp -text
 tests/webtbs/tw9306b.pp -text
 tests/webtbs/tw9309.pp -text
+tests/webtbs/tw9384.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 6 - 4
rtl/objpas/sysutils/sysstr.inc

@@ -1970,11 +1970,13 @@ Var
       Str(Value:Width+8,Digits);
       { Find and cut out exponent. Always the
         last 6 characters in the string.
-        -> 0000E+0000                         }
-      I:=Length(Digits)-5;
-      Val(Copy(Digits,I+1,5),Exp,J);
+        -> 0000E+0000                         
+        *** No, not always the last 6 characters, this depends on
+            the maximally supported precision (JM)}
+      I:=Pos('E',Digits);
+      Val(Copy(Digits,I+1,255),Exp,J);
       Exp:=Exp+1-(Placehold[1]+Placehold[2]);
-      Delete(Digits, I, 6);
+      Delete(Digits, I, 255);
       { Str() always returns at least one digit after the decimal point.
         If we don't want it, we have to remove it. }
       If (Decimals=0) And (Placehold[1]+Placehold[2]<= 1) Then

+ 11 - 0
tests/webtbs/tw9384.pp

@@ -0,0 +1,11 @@
+program test_formatloat;
+{$mode objfpc}{$H+}
+uses
+  SysUtils;
+var
+  ef : Extended;
+begin
+  ef := 12;
+  if (FormatFloat('#.#######E-0',ef) <> '1.2E1') then
+    halt(1);
+end.