home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / compiler / asic / sqrt.asi < prev    next >
Text File  |  1994-03-01  |  597b  |  50 lines

  1. REM ** FIXED POINT SQUARE ROOT **
  2. REM **   with ASIC COMPILER    **
  3. REM **   @1991, EFD Systems    **
  4.  
  5. start:
  6.  
  7. print "Enter number ";
  8. input x&
  9. if x&=0 then
  10.    end
  11. endif
  12. x&=x&*10000
  13. gosub sqrt:
  14. print "Square root = ";
  15. x=x&
  16. gosub format:
  17. print xs$
  18. goto start:
  19. end
  20.  
  21. sqrt:
  22. s1&=x&/2
  23. L01:
  24. s2&=x&/s1&
  25. s2&=s2&+s1&
  26. s2&=s2&/2
  27. if s1&>s2& then
  28.    s1&=s2&
  29.    goto L01:
  30. endif
  31. x&=s2&
  32. return
  33.  
  34. format:
  35. xi=x/100
  36. xf=x mod 100
  37. xs$=str$(xi)
  38. xs$=ltrim$(xs$)
  39. if xf<10 then
  40.    xt$=".0"
  41. else
  42.    xt$="."
  43. endif
  44. xs$=xs$+xt$
  45. xt$=str$(xf)
  46. xt$=ltrim$(xt$)
  47. xs$=xs$+xt$
  48. return
  49. end
  50.