%externalintegerfn StoI %alias "3L_IMP_S_TO_I"(%string(255) Text)
   {Note that this calculates using negative values}
   {     to avoid problems with minus infinity}
   %integer Value, Pos, Sym, Sign = 0, Base = 10, Digit
   Value = 0
   %for Pos = 1, 1, Length(Text) %cycle
      Sym = Charno(Text, Pos)
      %if Sym = '+' %or Sym = '-' %start
         %signal 4,1,Sym %if Sign # 0
         %if Sym = '-' %then Sign = -1 %else Sign = 1
      %else %if Sym = '_'
         Base = -Value;  Value = 0
      %else %if Sym > ' '
         %if '0' <= Sym <= '9' %start
            Digit = Sym-'0'
         %else %if 'A' <= Sym&95 <= 'Z'
            Digit = Sym&95-'A'+10
         %finish %else Digit = Base    {force error}
         %signal 4,1,Sym %if Digit >= Base
         Value = Value*Base-Digit
      %finish
   %repeat
   Value = -Value %unless Sign < 0
   %result = Value
%end
%endoffile
