Oberon Community Platform Forum
December 12, 2019, 08:42:12 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Utilities.StrToFloat  (Read 3722 times)
fnecati
Jr. Member
**
Posts: 60


« on: December 17, 2008, 12:01:21 PM »

Using str:="1.0E+3",  StrToFloat procedure cannot detect optional "+" character, so conversion to float  is wrong.

In Utilities.StrToFloat procedure;


   IF (s[p] = "d") OR (s[p] = "D") OR (s[p] = "e") OR (s[p] = "E") THEN
      INC(p); e := 0;
      IF s[p] = "-" THEN negE := TRUE; INC(p) ELSE negE := FALSE END;
      WHILE (s[p] = "0") DO INC(p) END;
      WHILE ("0" <= s[p]) & (s[p] <= "9") DO
         e := e * 10 + (ORD(s[p]) - 30H);
         INC(p);
      END;
      IF negE THEN y := y / Reals.Ten(e)
      ELSE y := y * Reals.Ten(e) END;
   END;

==> should be corrected as ( I think )

   IF (s[p] = "d") OR (s[p] = "D") OR (s[p] = "e") OR (s[p] = "E") THEN
      INC(p); e := 0;
      IF s[p] = "-" THEN negE := TRUE; INC(p)
      ELSIF s[p] = "+" THEN negE := FALSE; INC(p)  (* <<<< *)
      ELSE
         negE := FALSE
      END;
      WHILE (s[p] = "0") DO INC(p) END;
      WHILE ("0" <= s[p]) & (s[p] <= "9") DO
         e := e * 10 + (ORD(s[p]) - 30H);
         INC(p);
      END;
      IF negE THEN y := y / Reals.Ten(e)
      ELSE y := y * Reals.Ten(e) END;
   END;

Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #1 on: December 17, 2008, 12:16:29 PM »

Included in revision 1820.

Thanks!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!