Browse Source

+ strreal.pp, strreal2.pp

Jonas Maebe 25 years ago
parent
commit
7d7d8e45b9
2 changed files with 85 additions and 0 deletions
  1. 42 0
      tests/test/strreal.pp
  2. 43 0
      tests/test/strreal2.pp

+ 42 - 0
tests/test/strreal.pp

@@ -0,0 +1,42 @@
+const
+  s: array[0..16] of string[13] =
+    ('99999.900000',
+     '99999.990000',
+     '99999.999000',
+     '99999.999900',
+     '99999.999990',
+     '99999.999999',
+     '100000.000000',
+     '100000.000000',
+     '100000.000000',
+     '100000.000000',
+     '100000.000000',
+     '100000.000000',
+     '100000.000000',
+     '100000.000000',
+     '100000.000000',
+     '100000.000000',
+     '100000.000000');
+
+var
+  e,e2,e3: double;
+  s2: string;
+  c: longint;
+
+begin
+  e := 100000.0;
+  e2 := 0.1;
+  c := 0;
+  repeat
+    e3 := e-e2;
+    str(e3:0:6,s2);
+    writeln(s2);
+    if s2 <> s[c] then
+      begin
+        writeln('  Error, should be ',s[c]);
+        halt(1);
+      end;
+    e2 := e2 /10.0;
+    inc(c);
+  until e2 < 1e-17;
+end.

+ 43 - 0
tests/test/strreal2.pp

@@ -0,0 +1,43 @@
+const
+  s: array[1..21] of string =
+    ('10.00000000000000000',
+     '1.00000000000000000',
+     '0.10000000000000000',
+     '0.01000000000000000',
+     '0.00100000000000000',
+     '0.00010000000000000',
+     '0.00001000000000000',
+     '0.00000100000000000',
+     '0.00000010000000000',
+     '0.00000001000000000',
+     '0.00000000100000000',
+     '0.00000000010000000',
+     '0.00000000001000000',
+     '0.00000000000100000',
+     '0.00000000000010000',
+     '0.00000000000001000',
+     '0.00000000000000100',
+     '0.00000000000000010',
+     '0.00000000000000001',
+     '0.00000000000000000',
+     '0.00000000000000000');
+
+var
+  e: extended;
+  c: longint;
+  s2: string;
+
+begin
+  e := 10.0;
+  for c := 1 to 21 do
+    begin
+      str(e:0:17,s2);
+      writeln(s2);
+      if s2 <> s[c] then
+        begin
+          writeln('  Error, should be ',s[c]);
+          halt(1);
+        end;
+      e := e / 10.0;
+    end;
+end.