home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d969 / ace.lha / ACE / ACE-2.0.lha / MAIN.lha / include / longval.h < prev    next >
Text File  |  1994-01-10  |  1KB  |  80 lines

  1. { This include file is provided as a
  2.   means of overcoming limitations
  3.   inherent in DATA/READ and VAL.
  4.  
  5.   In the former case, all numeric DATA 
  6.   values are currently stored as single
  7.   precision values by ACE. 
  8.  
  9.   In the latter case, VAL always
  10.   returns a single-precision result
  11.   since it is not known at compile time
  12.   which numeric type will be represented 
  13.   by a given string. 
  14.  
  15.   The result in both cases is that when
  16.   a LONG integer value exceeds 8 digits,
  17.   information is lost when the number is
  18.   converted into the single-precision
  19.   format.
  20.  
  21.   longval&(num$) - Takes a string argument and returns the long integer
  22.            value represented by the argument.     
  23.  
  24.   Author: David J Benn
  25.     Date: 1st,2nd January 1993
  26. }   
  27.  
  28. SUB spacestripped$(x$)
  29. shortint l,i,s
  30.  
  31.  '..strip ALL whitespace from x$ 
  32.  '..(VAL does this too).
  33.  
  34.  y$=""
  35.  i=1
  36.  l=len(x$)
  37.  
  38.  while i<=l
  39.    s$=mid$(x$,i,1)
  40.    if s$ > " " then y$=y$+s$
  41.    ++i
  42.  wend
  43.  
  44.  spacestripped$ = y$
  45. END SUB
  46.  
  47. SUB longval&(num$)
  48. longint l,i,s,sign,num
  49.  
  50.  '..return the long integer value
  51.  '..represented by num$.
  52.  
  53.  num$ = spacestripped$(num$)
  54.  
  55.  '..leading + or - ?
  56.  first$=mid$(num$,1,1) 
  57.  if first$="-" or first$="+" then
  58.    case 
  59.      first$="-" : sign = -1
  60.      first$="+" : sign =  1
  61.    end case
  62.    num$=right$(num$,len(num$)-1)
  63.  else
  64.    sign=1
  65.  end if
  66.  
  67.  '..get value
  68.  i=1
  69.  l=len(num$)
  70.  
  71.  repeat 
  72.    s=asc(mid$(num$,i,1))
  73.    num = num*10& + s-asc("0")    
  74.    ++i
  75.  until i>l or s<asc("0") or s>asc("9")
  76.  
  77.  longval& = num*sign
  78. END SUB
  79.   
  80.