home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / ieee / part4 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  35.2 KB

  1. From: genrad!decvax!decwrl!sun!dgh!dgh (David Hough)
  2. Subject: IEEE Calculator (part 4 of 6)
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 3, Issue 6
  7. Submitted by: decvax!decwrl!sun!dgh!dgh (David Hough)
  8.  
  9. #! /bin/sh
  10. : make a directory, cd to it, and run this through sh
  11. echo If this kit is complete, "End of Kit" will echo at the end
  12. echo Extracting base.i
  13. cat >base.i <<'End-Of-File'
  14. (* File base.i, Version 8 October 1984.  *)
  15.  
  16. procedure mpyten ( var x : internal ; n : integer  ) ;
  17.  
  18.         (* Multiplies x by 10**n, using table of powers of ten.  *)
  19.         
  20. var
  21. n1, n2 : integer ;
  22.  
  23. begin
  24. n1 := abs(n) div 32 ;
  25. n2 := abs(n) mod 32 ;
  26. if n1 < 32 then begin
  27. if n > 0 then begin
  28. if n2 > 0 then multiply( x, tensmall[n2], x ) ;
  29. if n1 > 0 then multiply( x, tenbig[n1], x) ;
  30. end
  31. else if n < 0 then begin
  32. if n2 > 0 then divide ( x, tensmall[n2], x ) ;
  33. if n1 > 0 then divide ( x, tenbig[n1], x ) ;
  34. end ;
  35. end
  36. else begin (* n is too big.  *)
  37. if n > 0 then begin
  38. makeinf(x) ;
  39. setex ( overfl ) ;
  40. end
  41. else begin
  42. makezero(x) ;
  43. setex ( underfl ) ;
  44. end ;
  45. end ;
  46. end ;
  47.  
  48.  
  49. procedure xtodec ( x : internal ; r : roundtype ;
  50.                 var s : strng ) ;
  51.                 
  52.                 (* Converts abs(x) to an integral value, then that
  53.                 value is converted to a strng of ASCII digits.  *)
  54.                 
  55.  
  56. var
  57. tf : excepset ;
  58. acc : -20..+20  ; (* divide accumulator *)
  59. i, j : integer ;
  60. carry : boolean ;
  61. nib : nibarray ;
  62. last : integer ;
  63.  
  64. begin
  65. roundint ( x, r, xprec ) ;
  66. fpstatus.curexcep := fpstatus.curexcep - [inxact] ; 
  67.         (* Don't care about inxact.  *)
  68. if kind(x) = zerokind then makeucsdstring('0 ',s) else begin
  69. s[0] := chr(0) ;
  70. last := x.exponent - 1 ; (* Last is the last active bit of the accumulator.  *)
  71.  
  72. repeat (* Get one digit per cycle until there's nothing left.  *)
  73.  
  74. (* For each digit, do a NON RESTORING divide by TEN.  *)
  75.  
  76. acc := - 10 ;
  77.  
  78. for j := 0 to last do begin 
  79.         (* Do one divide minicycle for each bit of dividend, plus one extra.  *)
  80. acc := acc + acc ; (* Double remainder.  *)
  81. if x.significand[j] then acc := acc + 1 ; (* Shift in next bit of dividend.  *)
  82.  
  83. if acc < 0 then begin (* Do add-ten cycle.  *)
  84. acc := acc + 10 ;
  85. end
  86. else begin (* Do subtract-ten cycle.    *)
  87. acc := acc - 10 ;
  88. end ;
  89. x.significand[j] := acc >= 0  ; (* Sign of this step determines quotient bit
  90.                         and whether add or subtract next time.  *)
  91. (* End around complement rotate for quotient bit.  *)
  92. end (* Divide mini-cycle.  *) ;
  93.  
  94. if acc < 0  then begin 
  95.         (* Remainder is negative so add 10.  *)
  96. acc := acc + 10 ;
  97. end ;
  98.  
  99. precatchar(' ',s) ;
  100. s[1] := chr(ord('0') + acc ) ;
  101.  
  102. j := firstbit ( x, 0, last ) ;
  103. if j <= last then 
  104.         begin
  105.         left(x, j) ;
  106.         end ;
  107. last := last - j ;
  108. until last < 0 ;
  109.         (* Keep doing divide cycles until the quotient is zero.  *)
  110.  
  111. end ;
  112.  
  113. end ;
  114.  
  115. procedure subdec (* x : internal ; p1, p2 : integer ; var s: strng *) ;
  116.         (* s receives a strng of decimal digits representing the integer in
  117.         x.significand[p1]..x.significand[p2], right justified.  *)
  118.         
  119. var
  120. j, i : integer ;
  121. nib : nibarray ;
  122.  
  123. begin
  124.  
  125. if p2 = stickybit then begin (* Avoid trying to donormalize sticky bit.  *)
  126. for i := p1 to p2 do
  127. x.significand[i-1] := x.significand[i] ;
  128. p1 := p1 - 1 ;
  129. p2 := p2 - 1 ;
  130. end ;
  131.  
  132. for i := 0 to (p1-1) do 
  133. x.significand[i] := false ; (* Clear bits outside field.  *)
  134. for i := (p2+1) to stickybit do
  135. x.significand[i] := false ;
  136.  
  137. x.exponent := p2 + 1 ;
  138. donormalize(x) ;
  139. xtodec( x, rnear, s) ;
  140. end ;
  141.  
  142.  
  143. procedure findbinten ( x : internal ; n : integer ;
  144.                 var s : strng ; var p : integer  ) ;
  145.                 
  146.         (* Converts x into s and p, s a strng of exactly n significant
  147.         digits, so
  148.                 x .=. s * 10^p *)
  149.  
  150. var
  151. e1, e2, dp : integer ;
  152. tf : excepset ;
  153. t : internal ;
  154. cc : conditioncode ;
  155. i : integer ;
  156. norm : boolean ;
  157. et, dt : integer ;
  158. fraction : integer ;
  159. spill : boolean ;
  160.  
  161. begin
  162.         (* First ESTIMATE p.
  163.                 We want a p such that
  164.                 10^(n-1) <= int(abs(x)*10^p) < 10^n
  165.                 
  166.                 For a first guess, use
  167.                 n - log10( 2**e * 1+f ) 
  168.                 which we approximate by
  169.                 n - ((77+(1/16))/256) * (e + f )
  170.                 
  171.                 
  172.                 e is broken into two pieces to get benefit of 
  173.                 22 bit product.  *)
  174.                 
  175. norm := x.significand[0] ; (* If x is not normalized then we don't force
  176.         n significant digits in E format.  *)
  177. e2 := (x.exponent-1) div 256 ; (* e = e1 + 256*e2 *)
  178. e1 := (x.exponent-1) - 256 * e2 ;
  179. fraction := xbyte(x,1,8) ;
  180. e1 := 77 * e1 + 16 * e2 ; (* First order contribution from e1 and second
  181.         order from e2. *)
  182. if norm then e1 := e1 + ( 77 * fraction ) div 256 ;
  183.         (* If normalized add in a contribution for the fraction.
  184.         If not normalized, assume significand of 1.00000...  *)
  185. et := e1 div 256 ; dt := e1 - et * 256 ;
  186.         (* We are never sure how Pascal div and mod work on negative
  187.         numbers.  *)
  188. if dt > 0  then et := et + 1 ;
  189.         (* but we try to get et as close as possible anyway to
  190.         the ceiling of e1/256.  *)
  191. e2 := 77 * e2 ;
  192. p := n  - (et + e2) ;
  193.  
  194.         (* Now remedy flaws in approximation by altering p as necessary.  *)
  195.  
  196. tf := fpstatus.curexcep  ; (* Save exceptions.  *)
  197. dp := 0 ; (* Assume no correction required.  *)
  198. repeat
  199. fpstatus.curexcep  := tf ; 
  200. (* Restore exception status.  Don't want inexact flag set
  201.                 for inappropriate p.  *)
  202. p := p + dp ; (* Correct p.  *)
  203. dp := 0 ; (* Assume no correction required.  *)
  204. t := x ;
  205. mpyten(t, p) ; (* Multiply t by appropriate power.  *)
  206. roundint( t, fpstatus.mode.round, xprec ) ;
  207.  
  208. t.sign := false ; (* Use absolute values for comparison.  *)
  209. compare ( t, tensmall[n], cc ) ;  (* t must not exceed n sig digits.  *)
  210. case cc of
  211. otherwise ;
  212. greater : dp := -1 ; (* If too big, correct and repeat.  *)
  213. equal : begin
  214.         if norm or (n=1) then begin (* We want only n digits.  *)
  215.         p := p - 1 ; (* If almost, avoid full repeat of process.  *)
  216.         t := tensmall[n-1] ;
  217.         end 
  218.         else begin (* If not normalized we want n-1 digits.  *)
  219.         p := p - 2 ;
  220.         t := tensmall[n-2] ;
  221.         end ;
  222.         end ;
  223. lesser : begin
  224.         compare(t,tensmall[n-1],cc) ;
  225.          if norm then begin (* If normalized, insure enough sig digits. *)
  226.         if cc = lesser then dp :=  + 1 ; (* If not enough digits, correct *)
  227.         end  (* Need exactly n digits.  *)
  228.         else begin (* If unnormalized, want no more than n-1 digits.  *)
  229.         if cc <> lesser then dp := -1 ; (* Try again for less than n.  *)
  230.         end ;
  231.         end ;
  232. end ;
  233. t.sign := x.sign ;
  234. {
  235. if dp <> 0 then writeln(' Power of ten correction: ',dp) ;
  236. }
  237. spill := ([underfl, overfl] * fpstatus.curexcep ) <> [] ;
  238. until (dp = 0) or (kind(t)=zerokind) or spill ;
  239.         (* Repeat until no correction necessary or over/underfl occurs.  *)
  240.         (* or the number rounds to normalized zero.  *)
  241. if spill then
  242.         begin
  243.         (* String of asterisks if overfl.  *)
  244.         s[0] := chr(0) ;
  245.         while length(s) < n do concatchar(s,'*') ;
  246.         end 
  247. else 
  248.         begin
  249.         xtodec(*2*) ( t, fpstatus.mode.round, s(*, n*) ) ; (* Get strng.  *)
  250.         end ;
  251. while length(s) < n do precatchar( '0', s ) ;
  252.         (* Add unnormalizing digits.  *)
  253. p := - p ;
  254. end ;
  255.  
  256. procedure decint ( s : strng ; var x : internal ; var e : integer ) ;
  257.  
  258.         (* DECINT converts a strng s of decimal digits into x and e
  259.         such that
  260.                 s = x * 10^e
  261.         If s >= 2^(leastsigbit+1) then the sticky bit may be set. *)
  262.  
  263. const
  264. last = 69 ; (* last bit of decint accumulator *)
  265. var
  266. i,j : integer ;
  267. acc : array[0..last] of boolean ; (* Accumulator long enough to hold 20
  268.         significant digits and a sticky bit *)
  269. carry, zero : boolean ;
  270. n : nibarray ;
  271.  
  272. procedure tenmult ; (* multiplies acc by 10 *)
  273. var
  274. i : integer ;
  275. carry : boolean ;
  276.  
  277. begin
  278. for i := 0 to (last-3) do acc[i] := acc[i+3] ; (* multiply acc by 8 *)
  279. for i := (last-2) to last do acc[i] := false ;
  280. carry := false ;
  281. for i := (last-1) downto 2 do
  282. adder( acc[i], acc[i-2], acc[i], carry) ;
  283. for i := 1 downto 0 do
  284. adder( acc[i], false, acc[i], carry) ;
  285. end ;
  286.  
  287. begin (* decint *)
  288. for i := 0 to last do acc[i] := false ;
  289. e := 0 ;
  290. zero := true ;
  291. for j := 1 to length(s) do begin
  292. if s[j] = '0' then begin
  293. if not zero then e := e + 1 ;
  294. end 
  295. else begin
  296. if not zero then begin
  297. e := e + 1 ;
  298. while (e>0) and (not acc[0]) and (not acc[1]) and (not acc[2]) and 
  299. (not acc[3]) do begin (* multiply by ten *)
  300. tenmult ;
  301. e := e - 1 ;
  302. end ;
  303. end ;
  304. zero := false ;
  305. if e > 0 then acc[last] := true (* set sticky bit on *)
  306. else begin (* add digit *)
  307. hexnibble( s[j], n) ;
  308. carry := false ;
  309. for i := (last-1) downto (last-4) do
  310. adder( acc[i], n[i+4-last], acc[i], carry) ;
  311. for i := (last-5) downto 0 do
  312. adder( acc[i], false, acc[i], carry) ;
  313. end ;
  314. end ;
  315. end ;
  316.  
  317. if zero then makezero(x) else begin
  318.         (* Now acc[0..(last-1)] represents an integer value,
  319.         acc[last] a sticky bit, to be multiplied by 10^e *)
  320.         
  321.         i := 0 ;
  322.         while ( i < last ) and not acc[i] do i := i + 1 ;
  323.                 (* search for first nonzero bit *)
  324.         x.exponent := last - i ; (* Set exponent of result *)
  325.         for j := 0 to (last-i-1) do acc[j] := acc[j+i] ;
  326.                 (* normalize *)
  327.         for j := (last-i) to (last-1) do acc[j] := false  ; 
  328.         for i := 0 to (stickybit-1) do x.significand[i] := acc[i] ;
  329.         x.significand[stickybit] := acc[last] ;
  330.         for i := stickybit to (last-1) do
  331.         x.significand[stickybit] := x.significand[stickybit] or acc[i] ;
  332.         end ;
  333. end ;
  334.  
  335. procedure putdec (* s : strng ; p1, p2 : integer ; 
  336.                 var x : internal ; var error : boolean *) ;
  337.                 
  338.                 (* Interprets s as a decimal integer, puts value in bits
  339.                 p1..p2 of x.significand.
  340.                 Sets Error if any significant bits don't fit in field.  *)
  341.  
  342. var
  343. i, j : integer ;
  344. y : internal ;
  345. e : integer ;
  346. f : excepset ;
  347.  
  348. begin
  349. decint( s, y, e ) ;
  350. f := fpstatus.curexcep ;
  351. mpyten ( y, e ) ;
  352. fpstatus.curexcep := f ; (* Ignore exceptions that may arise.  *)
  353. e := y.exponent ;
  354. error := (e > (leastsigbit+1)) ;
  355.         (* Bad news if s too big to fit in 64 bits.  *)
  356. if not error then begin
  357. if kind(y) = zerokind then begin
  358. for i := p1 to p2 do
  359. x.significand[i] := false ; (* Set up zero field.  *)
  360. end
  361. else begin
  362. if (p2-p1+1) >= e then begin (* y fits in field.  *)
  363. for i := p2 downto (p2+1-e) do
  364. x.significand[i] := y.significand[i+e-1-p2] ;
  365. for i := (p2-e) downto p1 do
  366. x.significand[i] := false ;
  367. end
  368. else begin
  369. for i := p2 downto p1 do
  370. x.significand[i] := y.significand[i+e-1-p2] ;
  371. for i := (p1-p2+e-2) downto 0 do
  372. error := error or y.significand[i] ; (* Check for lost significant bits.  *)
  373. end end end
  374. end ;
  375.  
  376. procedure todecint ( x : internal ; var s : strng ) ;
  377.  
  378. (* if x is an integer less than 2**15,
  379. then s receives the decimal digits representing x.
  380. Otherwise s is set to empty. *)
  381.  
  382. var
  383. i, k : integer ;
  384.  
  385. begin
  386. s[0] := chr(0) ;
  387. if kind(x) = zerokind then makeucsdstring('0 ',s) else
  388. if (abs(kind(x)) = normkind) and (x.exponent <= 15) and (x.exponent >= 1)
  389. then begin
  390. if zerofield ( x, x.exponent, stickybit ) then begin (* it's all integer *)
  391. k := 0 ;
  392. for i := 0 to (x.exponent-1) do begin (* Accumulate k.  *)
  393. k := k + k ;
  394. if x.significand[i] then k := k + 1 ;
  395. end ;
  396. while k > 0 do begin
  397. precatchar( chr(ord('0') + (k mod 10)), s) ;
  398. k := k div 10 ;
  399. end ;
  400. if x.sign then precatchar( '-', s )  ;
  401. end end
  402. end ;
  403.  
  404. procedure bindec (* x : internal ; var s  : strng *)  ;
  405. (* converts x to decimal format *)
  406.  
  407. var
  408. e, i, j, k : integer ;
  409. nib : nibarray ;
  410. t : strng ;
  411. tf : excepset ;
  412. ns : integer ;
  413.  
  414. begin
  415. case abs(kind(x)) of
  416. zerokind : if x.sign 
  417.     then makeucsdstring('-0',s) else  makeucsdstring('0 ',s) ;
  418.  
  419. unnormkind, normkind : begin
  420. todecint ( x, s ) ;
  421. if length(s) < 1 then begin (* Can't represent as integer; too bad.  *)
  422. ns := 19 ;
  423. case storagemode of (* Set number of significant digits output.  *)
  424. flt32 : ns := 9 ;
  425. f64 : ns := 17 ;
  426. otherwise ;
  427. end ;
  428. findbinten( x, ns, s, e ) ;
  429. tf := fpstatus.curexcep ;
  430. fpstatus.curexcep := [] ;
  431. if not (overfl in tf) then begin
  432. if e <> 0 then begin (* x not an integer so write it in E format.  *)
  433. e := e + ns-1 ;
  434. for i := length(s) downto 2 do s[i+1] := s[i] ;
  435. s[2] := '.' ;
  436. s[0] := chr(length(s)+1) ;
  437. if e <> 0 then begin
  438. concatchar(s, 'E') ;
  439. if e > 0 then concatchar(s, '+') ;
  440. intdec(e, t) ;
  441. s := concat(s,t) ;
  442. end ;
  443. end ;
  444. end ;
  445. if x.sign then precatchar('-',s) ;
  446. end ;
  447. end ;
  448.  
  449. infkind, nankind : nanascii ( x, false, s ) ;
  450.  
  451. otherwise
  452. end ;
  453. end ;
  454.  
  455.  
  456.  
  457. procedure decbin (* s : strng ; var x : internal ; var error : boolean *) ;
  458. (* converts decimal strng s to internal format *)
  459. (* error is set true if bad format *)
  460.  
  461. type
  462. stringclass = (nonnumeric, truezero, nonzero) ; (* types of strng *)
  463.  
  464. var
  465. class : stringclass ;
  466. i, k,  min : integer ;
  467. e1, e2 : integer ;
  468. sub : strng ;
  469. t : strng ;
  470. esign : boolean ;
  471. nib : nibarray ;
  472. ee, ie : integer ;
  473.  
  474.  
  475. procedure checkadd ( x, y : integer ; var z : integer ; var error : boolean ) ;
  476.         (* Computes z := x + y except if z overflows error is set to true
  477.                 and z is set to maxexp-1 or minexp+1 *)
  478. begin
  479. error := false ;
  480. z := x + y ;
  481. if (x>0) and (y>0) and (z<=0) then begin
  482. z := maxexp - 1 ;
  483. error := true ;
  484. end
  485. else if (x<0) and (y<0) and (z>=0) then begin
  486. z := minexp + 1 ;
  487. error := true ;
  488. end ;
  489. end ;
  490.  
  491. procedure bump ; (* removes first character from strng t *)
  492. begin
  493. delete (t,1,1) 
  494. end ;
  495.  
  496.  
  497. begin
  498. class := nonnumeric ;
  499. error := false ;
  500. esign := false ;
  501. x.sign := false ;
  502. x.exponent := 0 ;
  503. ee := 0 ; ie := 0 ;
  504. for i := 0 to stickybit do x.significand[i] := false ;
  505. sub[0] := chr(0) ; (* substring for accumulating significant digits *)
  506. t[0] := chr(0) ;
  507. for i := 1 to length(s) do if s[i] <> ' ' then concatchar(t,upcase(s[i])) ;
  508. concatchar(t,'!') ; (* this marks the end of the input strng *)
  509.  
  510. if t[1] = '+' then bump else if t[1] = '-' then begin (* handle negative *)
  511. x.sign := true ;
  512. bump
  513. end ;
  514. while t[1] = '0' do begin
  515. class := truezero ;
  516. bump ; (* delete leading zeros *)
  517. end ;
  518. while t[1] in digitset do begin (* digits before point *)
  519. class := nonzero ;
  520. concatchar(sub, t[1]) ;
  521. bump
  522. end ;
  523. if t[1] = '.' then begin (* check for point *)
  524. bump ;
  525. while t[1] in digitset do begin (* process digits after point *)
  526. if (t[1] <> '0') or (class = nonzero) then class := nonzero 
  527. else class := truezero ;
  528. concatchar( sub, t[1]) ;
  529. ie := ie - 1 ;
  530. bump ; 
  531. end ;  
  532. end ;
  533. ee := 0 ;
  534. if t[1] = 'E' then bump ; (* handle E for exponent *)
  535. if t[1] = '+' then bump else if t[1]='-' then begin (* exponent sign *)
  536. esign := true ;
  537. bump
  538. end ;
  539. while t[1] in digitset do begin (* exponent digits *)
  540. if ee > ((maxexp - (ord(t[1])-ord('0'))) div 10 ) then begin
  541. error := true ;
  542. ee := maxexp - 1 ;
  543. end else
  544. begin
  545. ee := 10 * ee + ord(t[1]) - ord('0') ;
  546. end ;  bump  end ;
  547. if class = truezero then x.exponent := minexp  else begin
  548. if esign then ee := -ee ;
  549. checkadd(ee,ie,ee,error) ; (* ee := ee + ie *)
  550. if not error then begin 
  551.                 (* Minimize ee if possible by adding zeros to sub *)
  552. ie := 19 - length(sub) ; (* Maximum number of zeros to add.  *)
  553. if (ee>0) and (ie>0) then begin (* Go ahead and add.  *)
  554. if ee < ie then ie := ee ; (* Only add enough to reduce ee to 0.  *)
  555. ee := ee - ie ;
  556. for i := 1 to ie do concatchar( sub, '0') ;
  557. end ;
  558. decint ( sub, x, ie ) ; (* Convert substring to x and ie *)
  559. checkadd( ee, ie, ee, error ) ; (* Add in ie to exponent.  *)
  560. end ;
  561. if not error then 
  562. mpyten ( x, ee ) ; (* Adjust x by appropriate power of ten.  *)
  563. end ;
  564. if class = nonnumeric  then 
  565.         (* the following code checks for INFs and NANs *)
  566. begin
  567. NANer ( s, false, x, error ) 
  568. end 
  569. else
  570. if length(t) > 1 then error := true ;
  571. if error  then 
  572.         begin
  573.         makenan(nanascbin,x) ;
  574.         end ;
  575. end ;
  576.  
  577. procedure display (* x : internal *) ;
  578. (* displays x in decimal and binary *)
  579.  
  580. begin
  581. write(' Hex: ') ; displayhex(x) ;
  582. write(' Dec: ') ; displaydec(x) ;
  583. end ;
  584. End-Of-File
  585. echo Extracting utility.i
  586. cat >utility.i <<'End-Of-File'
  587. (* File utility.i, Version 8 October 1984. *)
  588.  
  589. function length ( var x : strng ) : integer ;
  590.  
  591. begin (* concat *)
  592. length := ord(x[0]) ;
  593. end   (* concat *) ;
  594.  
  595. procedure displayhex ( x : internal ) ;
  596.  
  597. var s : strng ;
  598. i : integer ;
  599.  
  600. begin
  601. binhex(x,s) ;
  602. for i := 1 to length(s) do write(s[i]) ;
  603. writeln ;
  604. end ;
  605.  
  606. procedure displaydec ( x : internal ) ;
  607.  
  608. var s : strng ;
  609. i : integer ;
  610.  
  611. begin
  612. bindec(x,s) ;
  613. for i := 1 to length(s) do write(s[i]) ;
  614. writeln ;
  615. end ;
  616.  
  617. procedure concatchar ( var s : strng ; c : char ) ;
  618. (* concatenates the character c onto the end of s *)
  619. var
  620. ls : integer ;
  621. begin
  622. ls := ord(s[0]) + 1 ;
  623. s[ls] := c ;
  624. s[0] := chr(ls) ;
  625. end ;
  626.  
  627. function upcase ( c : char ) : char ;
  628. begin
  629. if ('a' <= c) and (c <= 'z') then upcase := chr(ord(c)-32) else upcase := c
  630. end  ;
  631.  
  632. function stackspace : integer ;
  633.  
  634.         (* Computes number of stack entries left.
  635.         As this number approaches zero, operation becomes dangerous.  *)
  636.  
  637. var space : integer ;
  638.  
  639. begin
  640. stackspace := 10000 ;
  641. end ;
  642.  
  643. procedure hexnibble ( h : char ; var n : nibarray ) ;
  644. (* Converts ASCII hexit h into a nibarray *)
  645. var
  646. i, w : integer ;
  647. begin
  648. if h in digitset then w := ord(h)-ord('0') else w := ord(h) - ord('A') + 10 ;
  649. for i := 3 downto 0 do begin
  650. n[i] := odd(w) ;
  651. w := w div 2 ;
  652. end ;
  653. end ;
  654.  
  655. function nibblehex (* n : nibarray ) : char *)  ;
  656. (* converts a nibarray into a hexit ASCII character *)
  657. var
  658. i, w : integer ;
  659. c : char ;
  660.  
  661. begin
  662. w := 0 ;
  663. for i := 0 to 3 do begin
  664. w := w + w ;
  665. if n[i] then w := w + 1 ;
  666. end ;
  667. if w < 10 then c := chr(ord('0') + w) else c := chr(ord('A') + w - 10 ) ;
  668. nibblehex := c ;
  669. end ;
  670.  
  671. procedure displayexcep ( es : excepset ) ;
  672.         (* Displays exception names that are enabled.  *)
  673. var i : xcpn ;
  674. begin
  675. for i := invop to inexact do
  676. if i in es then write(' ',xcpnname[i],' ') ;
  677. end ;
  678.  
  679. procedure displaystatus ;
  680.         (* Displays current mode, trap, exception flags.  *)
  681.  
  682. begin
  683. write(' Modes: ') ;
  684. case fpstatus.mode.round of
  685. rneg : write(' RM ') ;
  686. rpos : write(' RP ') ;
  687. rzero : write(' RZ ') ;
  688. otherwise
  689. end ;
  690. case fpstatus.mode.precision of
  691. sprec: write(' R24 ') ;
  692. dprec: write(' R53 ') ;
  693. otherwise
  694. end ;
  695. if fpstatus.mode.clos = proj then write(' PROJ ') ;
  696. if fpstatus.mode.norm = warning then write(' WARN ') ;
  697. case storagemode of
  698. i16 : write(' I16 ') ;
  699. i32 : write(' I32 ') ;
  700. i64 : write(' I64 ') ;
  701. flt32 : write(' F32 ') ;
  702. f64 : write(' F64 ') ;
  703. ext80 : write(' X80 ') ;
  704. otherwise
  705. end ;
  706. writeln ;
  707. if fpstatus.trap <> [] then begin (* Write out trap line.  *)
  708. write(' Traps: ') ;
  709. displayexcep( fpstatus.trap ) ;
  710. writeln ;
  711. end ;
  712. if fpstatus.excep <> [] then begin (* Write out exceptions.  *)
  713. write(' Exceptions: ') ;
  714. displayexcep( fpstatus.excep ) ;
  715. writeln ;
  716. end ;
  717. end ;
  718.  
  719. procedure trapmessage ;
  720.  
  721.         (* Announces name of trap that would occur now.  *)
  722.         
  723. var
  724. tset : excepset ;
  725. f : xcpn ;
  726.  
  727. begin
  728. tset := fpstatus.trap * fpstatus.curexcep ;
  729. if tset <> [] then begin
  730. f := invop ; (* Start with highest priority exception.  *)
  731. while (f <> cvtovfl) and not (f in tset) do f := succ(f) ;
  732. if f in tset then writeln( xcpnname[f],' TRAP occurs.  ') ;
  733. end ;
  734. end ;
  735.  
  736. procedure setex (* e : xcpn *) ;
  737.         (* Turns on exception flag in curexcep.  *)
  738. begin
  739. fpstatus.curexcep := fpstatus.curexcep  + [e] ;
  740. end ;
  741.  
  742. function zerofield (* x : internal ; p1, p2 : integer ) : boolean *) ;
  743.  
  744.         (* Returns true if x.significand[p1..p2] is all zeros.  *)
  745.         
  746. var i : integer ;
  747.  
  748. begin
  749. i := p1 ;
  750. while ( i < p2 ) and not x.significand[i] do i := i + 1 ;
  751. zerofield := ( i >= p2 ) and not x.significand[p2]  ;
  752.         (* Can't test bit p2 in main loop ; would cause range error if
  753.         p2 were stickybit, on subsequent test.  *)
  754. end ;
  755.  
  756. function firstbit (* x : internal ; p1, p2 : integer ) : integer *)  ;
  757.  
  758.         (* Returns index of leftmost onebit in field
  759.         x.significand[p1..p2].
  760.         If field is zero, returns p2+1.  *)
  761.         
  762. var i : integer ;
  763.  
  764. begin
  765. i := p1 ;
  766. while ( i < p2 ) and not x.significand[i] do i := i + 1 ;
  767. if ( i >= p2 ) and not x.significand[p2] then i := p2+1   ;
  768.         (* Can't test bit p2 in main loop ; would cause range error if
  769.         p2 were stickybit, on subsequent test.  *)
  770. firstbit := i ;
  771. end ;
  772.  
  773. function lastbit (* x : internal ; p1, p2 : integer ) : integer *)  ;
  774.  
  775.         (* Returns index of rightmost nonzero bit in field
  776.         x.significand[p1..p2].
  777.         If field is zero, returns p1-1.  *)
  778.         
  779. var i : integer ;
  780.  
  781. begin
  782. i := p2 ;
  783. while ( i > p1 ) and not x.significand[i] do i := i - 1 ;
  784. if ( i <= p1 ) and not x.significand[p1] then i := p1 - 1  ;
  785.         (* Can't test bit p1 in main loop ; would cause range error if
  786.         p1 were zero, on subsequent test.  *)
  787. lastbit := i ;
  788. end ;
  789.  
  790. function kind (* x : internal ) : integer *)  ;
  791. (* returns kind(x) but all NANs have kind=4 in order to fit int16 *)
  792. var
  793. i, tkind : integer ;
  794. begin
  795. if x.exponent = maxexp then begin (* inf or nan *)
  796. if zerofield ( x, 1, stickybit )  then tkind := ord(infkind) 
  797. else tkind := ord(nankind) ;
  798. end
  799. else 
  800. if (x.exponent <= minexp) and zerofield(x, 0, stickybit)
  801. then tkind := ord(zerokind)
  802. else if x.significand[0] = true then tkind := ord(normkind)
  803. else tkind := ord(unnormkind) ;
  804. if x.sign then tkind := -tkind ;
  805. kind := tkind ;
  806. end ;
  807.  
  808. procedure makezero (* var x : internal *) ;
  809.  
  810.         (* makes x into a zero.  Does not change sign of x *)
  811.  
  812. var i : integer ;
  813.  
  814. begin
  815. x.exponent := minexp ;
  816. for i := 0 to stickybit do x.significand[i] := false ;
  817. end ;
  818.  
  819.  
  820. procedure makeinf (* var x : internal *) ;
  821.  
  822.         (* makes x into a infinity.  Does not change sign of x *)
  823.  
  824. var i : integer ;
  825.  
  826. begin
  827. x.exponent := maxexp ;
  828. for i := 0 to stickybit do x.significand[i] := false ;
  829. end ;
  830.  
  831. procedure makenan (* n : integer ; var x : internal  *) ;
  832.  
  833.         (* makes x a NAN and inserts n in its more significant field.
  834.         Sets NV Operand flag in curexcep. *)
  835.  
  836. var
  837. i : integer ;
  838.  
  839. begin
  840. x.exponent := maxexp ;
  841. for i := 0 to stickybit do x.significand[i] := false ;
  842. i := 15 ;
  843. while n <> 0 do begin
  844. x.significand[i] := odd(n) ;
  845. n := n div 2 ;
  846. i := i - 1 ;
  847. end ;
  848. setex( invop ) ;
  849. end ;
  850.  
  851. function unzero (* x : internal ) : boolean *)  ;
  852.  
  853.         (* returns TRUE if x is an unnormalized zero,
  854.         FALSE otherwise *)
  855.  
  856.  
  857. begin
  858. unzero := zerofield( x, 0, stickybit ) and (x.exponent > minexp)  ;
  859. end ;
  860.  
  861. procedure pushstack (* x : internal *) ;
  862. (* pushes x on stack *)
  863.         (* In case of NV exception and trapping NAN, makes the NAN
  864.         non-trapping.  *)
  865.  
  866. var
  867. p : pstack  ;
  868.  
  869. begin
  870. if stackspace >= 3 then begin
  871. new(p) ;
  872. if (invop in fpstatus.curexcep) and (abs(kind(x))=nankind) then
  873. x.significand[1] := false ; (* By convention bit 1 determines trapping/
  874.                                 non-trapping.  *)
  875. p^.x := x ;
  876. p^.next := stack ;
  877. stack := p ;
  878. end else 
  879. writeln(' ERROR: not enough space for push! ') ;
  880. end ;
  881.  
  882. procedure popstack (* var x : internal *) ;
  883.         (* pops stack to x, or sets x to 0 if stack is empty *)
  884. begin
  885. if stack=nil then begin
  886. x.sign := false ;
  887. makezero(x) ;
  888. end
  889. else begin
  890. x := stack^.x ;
  891. stack := stack^.next ;
  892. if (abs(kind(x))=nankind) and x.significand[1] then (* It's a Trapping NAN. *)
  893. setex( invop ) ;
  894. end
  895. end ;
  896.  
  897. procedure donormalize (* var x : internal *) ;
  898.         (* normalizes x *)
  899.         (* Unnormalized zeros are set to normalized zeros.
  900. a           INFs and NANs are not changed *)
  901.  
  902. var
  903. i, j : integer ;
  904.  
  905. begin
  906. if x.exponent < maxexp then begin
  907. i := firstbit( x, 0, stickybit )  ;
  908. if i > stickybit then x.exponent := minexp (* zero *) else
  909. if i > 0 then begin
  910. x.exponent := x.exponent - i ;
  911. for j := i to stickybit do 
  912. x.significand[j-i] := x.significand[j] ;
  913. for j := ((stickybit+1)-i) to (stickybit-1) do
  914. x.significand[j] := x.significand[stickybit] ;
  915. {
  916. if (x.significand[stickybit]) and (i>1)  then 
  917. writeln(i,' ERROR: Normalizing Sticky Bit ') ;
  918.         (* It's OK to shift sticky bit into next to last position because
  919.         during rounding the last two positions are stuck together.
  920.         It is definitely not OK to shift a sticky bit any further left.  *)
  921. }
  922. end ;
  923. end ;
  924. end ;
  925.  
  926. procedure right (* var x : internal ; n : integer *) ;
  927.         (* does sticky right shift of internal x *)
  928.         
  929. var
  930. i : integer ;
  931.  
  932. begin
  933. {
  934. if (0 > n) or (n > stickybit) then
  935. writeln(' Funny Right ',n) ;
  936. }
  937. if n > stickybit then n := stickybit ; (* It's all the same for large n.  *)
  938. x.significand[stickybit] := not zerofield( x, (stickybit-n), stickybit) ;
  939. for i := (stickybit-1) downto n do
  940. x.significand[i] := x.significand[i-n] ;
  941. for i := (n-1) downto 0 do
  942. x.significand[i] := false ;
  943. end ;
  944.  
  945. procedure left (* var x : internal ; n : integer *) ;
  946.  
  947.         (* Lefts shifts significand of x, n times *)
  948.         
  949. var i : integer ;
  950.  
  951. begin
  952. {
  953. if (0 > n) or ( n > stickybit) then
  954. writeln(' Funny left ',n) ;
  955. }
  956. if n > stickybit then n := stickybit ;  (* All the same for large n.  *)
  957. for i := 0 to (stickybit-1-n) do
  958. x.significand[i] := x.significand[i+n] ;
  959. {
  960. if x.significand[stickybit] and (n>1)  then
  961. writeln(n,' Error: LEFT shift of STICKY bit ') ;
  962. }
  963. for i := (stickybit-n) to (stickybit-1) do
  964. x.significand[i] := x.significand[stickybit] ;
  965. end ;
  966.  
  967. procedure roundkcs (* var x : internal ; r : roundtype ;
  968.         p : precisetype  *) ;
  969.         
  970.         (* Rounds x according to rounding mode and rounding precision.
  971.         Sets Inexact flag in curexcep if appropriate. *)
  972.         
  973. var i : integer ;
  974. akx : integer ;
  975.  
  976. procedure dorn ; (* round to nearest *)
  977.  
  978. var
  979. i : integer ;
  980. carry : boolean ;
  981.  
  982. begin
  983. carry := true ;
  984. i := (leastsigbit+1) ;
  985. while (i>=0) and carry do begin
  986. adder(x.significand[i], false, x.significand[i], carry) ;
  987. i := i-1 ;
  988. end ;
  989. if carry then begin (* carry out of most significant bit occurred. *)
  990. x.significand[0] := true ;
  991. x.exponent := x.exponent + 1 ;
  992. end
  993. else begin (* Check for ambiguous case *)
  994. if zerofield( x, leastsigbit+1, stickybit )  
  995. then (* It is the ambiguous case. *)
  996. x.significand[leastsigbit] := false ; (* force round to even. *)
  997. end ;
  998. end ;
  999.  
  1000. procedure doro ; (* Round away from zero (Outward Round) *)
  1001.  
  1002. var
  1003. i : integer ;
  1004. carry : boolean ;
  1005.  
  1006. begin
  1007. carry := false ;
  1008. for i := (leastsigbit+1) to stickybit do carry := carry or x.significand[i] ;
  1009. if carry then begin (* propagate a carry *)
  1010. i := leastsigbit ;
  1011. while (i >= 0) and carry do begin
  1012. adder(x.significand[i], false, x.significand[i], carry) ;
  1013. i := i - 1 ;
  1014. end ;
  1015. if carry then begin (* Carry out occurred, so renormalize. *)
  1016. x.significand[0] := true ;
  1017. x.exponent := x.exponent + 1 ;
  1018. end ;
  1019. end ;
  1020. end ;
  1021.  
  1022. begin (* round *)
  1023. akx := abs(kind(x)) ;
  1024. if akx in [unnormkind, normkind] then begin
  1025. case p of 
  1026. sprec: begin
  1027. right(x, 40) ;
  1028. x.exponent := x.exponent + 40 ;
  1029. end ;
  1030.  
  1031. dprec : begin
  1032. right(x, 11) ;
  1033. x.exponent := x.exponent + 11 ;
  1034. end ;
  1035.  
  1036. otherwise
  1037. end ;
  1038. for i := (leastsigbit+1) to stickybit do if x.significand[i] then 
  1039. begin
  1040. setex( inxact ) ;
  1041. end ;
  1042. case r of
  1043. rnear : begin 
  1044. dorn ;
  1045. end ;
  1046. rneg : if x.sign then doro  ;
  1047. rpos : if not x.sign then doro ;
  1048. otherwise
  1049. end ;
  1050.  
  1051. for i := (leastsigbit+1) to stickybit do x.significand[i] := false ;
  1052.         (* Eliminate G, R, and S bits. *)
  1053. case p of
  1054.  sprec: begin
  1055. left(x,39) ;
  1056. x.exponent := x.exponent - 39 ; 
  1057. if not  x.significand[0] then 
  1058. begin
  1059. left( x, 1) ;
  1060. x.exponent := x.exponent - 1 ;
  1061. end ;
  1062. end ;
  1063.  
  1064. dprec: begin
  1065. left(x,10) ;
  1066. x.exponent := x.exponent - 10 ; 
  1067. if not  x.significand[0] then 
  1068. begin
  1069. left(x,1) ;
  1070. x.exponent := x.exponent - 1 ;
  1071. end ;
  1072. end ;
  1073.  
  1074. otherwise
  1075. end ;
  1076. end ;
  1077. end ;
  1078.  
  1079. procedure roundint (* var x : internal ; r : roundtype ; p : precisetype *) ;
  1080.         
  1081.         (* Rounds x to an integral value in accordance with modes.  *)
  1082.  
  1083. var
  1084. akx, i, count : integer ;
  1085.  
  1086. begin
  1087. akx := abs(kind(x)) ;
  1088. if akx in [unnormkind, normkind]  then begin
  1089. if (x.exponent >= (leastsigbit+1)) then count := 0
  1090. else if x.exponent <= (leastsigbit+1-stickybit) then count := stickybit
  1091. else count := (leastsigbit+1) - x.exponent ; 
  1092.         (* Compute shift count of bits to get rid of.  *)
  1093. case p of (* But allow for rounding to shorter precisions, too.  *)
  1094.  sprec: if count < 40 then count := 40 ;
  1095.  dprec: if count < 11 then count := 11 ;
  1096. otherwise
  1097. end ;
  1098. if count > 0 then right ( x, count) ;
  1099. roundkcs( x, r, xprec) ; (* Do rounding.  *)
  1100. if count > leastsigbit then begin (* Limit left shifts
  1101.         for 0 < x < 1 which must be rounded either to 0 or 1.  *)
  1102.         count := leastsigbit ;
  1103.         x.exponent := 1 ;
  1104.         end ;
  1105. if count > 0 then begin
  1106. left(x, count-1 ) ;
  1107. if x.significand[0] then x.exponent := x.exponent + 1 (* Rounding carry out.  *)
  1108. else left(x, 1) ;
  1109. end ;
  1110. if zerofield ( x, 0, stickybit ) then x.exponent := minexp ;
  1111.         (* No significant bits left so make it a true zero.  *)
  1112. end end ;
  1113.  
  1114.  
  1115. procedure picknan (* x, y : internal ; var z : internal *) ;
  1116.  
  1117.         (* Sets z to whichever of x or y is a NAN.
  1118.         If both are NANs, sets z to the one with the 
  1119.         greatest significand.  *)
  1120.         
  1121. var i : integer ;
  1122.  
  1123. begin
  1124. if abs(kind(x)) = nankind then 
  1125. if abs(kind(y)) = nankind then begin
  1126. i := 0 ;
  1127. while (i <= leastsigbit) and (x.significand[i] = y.significand[i]) do 
  1128.         i := i + 1 ;
  1129. if x.significand[i] then z := x else z := y ;
  1130. end 
  1131. else z := x else z := y
  1132. end ;
  1133.  
  1134. function equalinternal ( x1, x2 : internal ) : boolean ;
  1135.         (* Returns true if x1 = x2 *)
  1136. var
  1137. t : boolean ;
  1138. i : integer ;
  1139.  
  1140. begin
  1141. t := (x1.sign=x2.sign) and (x1.exponent=x2.exponent) ;
  1142. if t then for i := 0 to stickybit do
  1143. t := t and (x1.significand[i]=x2.significand[i]) ;
  1144. equalinternal := t ;
  1145. end ;
  1146.  
  1147. function concat ( x, y : strng ) : strng ;
  1148.  
  1149. var t : strng ;
  1150. i, lx, ly : integer ;
  1151.  
  1152. begin (* concat *)
  1153. t := x ;
  1154. lx := ord(x[0]) ; ly := ord(y[0]) ;
  1155. for i := 1 to ly do t[lx+i] := y[i] ;
  1156. t[0] := chr(lx+ly) ;
  1157. concat := t ;
  1158. end   (* concat *) ;
  1159.  
  1160. procedure precatchar ( c : char ; var x : strng ) ;
  1161.  
  1162. var i, ls : integer ;
  1163.  
  1164. begin (* precatchar *)
  1165. ls := ord(x[0]) ;
  1166. for i := ls downto 1 do x[i+1] := x[i] ;
  1167. x[1] := c ;
  1168. x[0] := chr(ls+1) ;
  1169. end   (* precatchar *) ;
  1170.  
  1171. procedure delete ( var x : strng ; index, count : integer ) ;
  1172.  
  1173. var i : integer ;
  1174.  
  1175. begin (* delete *)
  1176. for i := index+count to length(x) do
  1177.     x[i-count] := x[i] ;
  1178. x[0] := chr(length(x)-count) ;
  1179. end   (* delete *) ;
  1180.  
  1181. procedure makeucsdstring( x : strng; var t : strng );
  1182.     (* Converts a constant string to UCSD form. *)
  1183. var i, l : integer ;
  1184. begin
  1185. l := 0 ;
  1186. while (33 <= ord(x[l])) and (ord(x[l]) <= 126) do l := l + 1 ;
  1187. for i := l downto 1 do t[i] := x[i-1] ;
  1188. t[0] := chr(l) ;
  1189. end ;
  1190.  
  1191. procedure copy ( s : strng; index, count : integer ; var t : strng ) ;
  1192.  
  1193. var i : integer ; l : integer ;
  1194.  
  1195. begin (* copy *)
  1196. t[0] := chr(count) ;
  1197. for i := 1 to count do t[i] := s[index+i-1] ;
  1198. end   (* copy *) ;
  1199.  
  1200. procedure insert( s : strng ; var d : strng ; index : integer ) ;
  1201.  
  1202. var i,ld,ls : integer ;
  1203.  
  1204. begin (* insert *)
  1205. ls := ord(s[0]) ; ld := ord(d[0]) ;
  1206. for i := ld downto index do d[i+ls] := d[i] ;
  1207. for i := ls downto 1 do d[index+i-1] := s[i] ;
  1208. d[0] := chr(ls+ld) ;
  1209. end   (* insert *) ;
  1210.  
  1211. function pos ( c : char ; s : strng ) : integer ;
  1212.  
  1213. var i, l : integer ;
  1214.  
  1215. begin (* pos *)
  1216. l := ord(s[0]) ;
  1217. i := 1 ;
  1218. while (i <= l) and (s[i] <> c) do i := i + 1 ;
  1219. if i <= l then pos := i else pos := 0 ;
  1220. end   (* pos *) ;
  1221.  
  1222. function sequal ( s, c : strng ) : boolean ;
  1223.       (* Compares UCSD string s to C string c and returns true if equal. *)
  1224. var
  1225. i, ls, lc : integer ;
  1226.  
  1227. begin (* sequal *)
  1228. lc := 0;
  1229. ls := ord(s[0]) ;
  1230. while (33 <= ord(c[lc])) and (ord(c[lc]) <= 126) do lc := lc + 1 ;
  1231. if lc <> ls then 
  1232.     begin
  1233.     sequal := false ;
  1234.     end
  1235.  else
  1236.     begin
  1237.     i := 1 ;
  1238.     while (i <= ls) and (s[i] = c[i-1]) do i := i + 1 ;
  1239.     sequal := i > ls ;
  1240.     end ;
  1241. end   (* sequal *) ;
  1242.  
  1243.  
  1244. End-Of-File
  1245. echo Extracting init.i
  1246. cat >init.i <<'End-Of-File'
  1247.  
  1248. (* File init.i, Version 4 February 1985. *)
  1249.  
  1250.  
  1251. PROCEDURE initialize ;
  1252.  
  1253.         (* does all the initializing of tables and variables.  *)
  1254.  
  1255. var error : boolean ;
  1256.  
  1257. procedure inittensmall ;
  1258.  
  1259.         (* procedure to initialize the table of small  powers of ten *)
  1260.         
  1261. var
  1262. i : integer ;
  1263. j : integer ;
  1264. x : internal ;
  1265. carry : boolean ;
  1266. last : integer ;
  1267. error : boolean ;
  1268.  
  1269. begin
  1270. (* Make 10^0=1 *)
  1271. for i := 1 to stickybit do x.significand[i] := false ;
  1272. x.sign := false ;
  1273. x.exponent := 1 ;
  1274. x.significand[0] := true ;
  1275. tensmall[0] := x ;
  1276.  
  1277. (* Make other exact powers of ten.  *)
  1278. last := 0 ; (* Last non-zero bit. *)
  1279. for j := 1 to 28 do begin
  1280. x.exponent := x.exponent + 3 ; (* Multiply by 8 first.  *)
  1281. last := last + 2 ; (* At least 2 more significant bits.  *)
  1282. carry := false ;
  1283. for i := last downto 2 do
  1284. adder(x.significand[i-2], x.significand[i],x.significand[i],carry) ;
  1285. for i := 1 downto 0 do
  1286. adder(false, x.significand[i],x.significand[i],carry) ;
  1287. if carry then begin (* Overflowed slightly.  *)
  1288. x.exponent := x.exponent + 1 ;
  1289. last := last + 1 ;
  1290. for i := last downto 1 do
  1291. x.significand[i] := x.significand[i-1] ;
  1292. x.significand[0] := true ;
  1293. end ;
  1294. tensmall[j] := x ;
  1295. end ;
  1296.  
  1297. hexbin(' .a18f 07d7 36b9 0be5 4 h  97', tensmall[29], error ) ;
  1298. hexbin(' .c9f2 c9cd 0467 4ede c h 100', tensmall[30], error ) ;
  1299. hexbin(' .fc6f 7c40 4581 2296 4 h 103', tensmall[31], error ) ;
  1300. end ;
  1301.  
  1302. procedure inittenbig ;
  1303.  
  1304.         (* procedure to initalize the table of large powers of ten *)
  1305.         
  1306. var
  1307. error : boolean ;
  1308.  
  1309. begin
  1310. tenbig[0] := tensmall[0] ;
  1311. hexbin(' .9dc5 ada8 2b70 b59d c h 107',tenbig[1], error ) ;
  1312. hexbin(' .c278 1f49 ffcf a6d5 4 h 213',tenbig[2], error ) ;
  1313. hexbin(' .efb3 ab16 c59b 14a2 c h 319',tenbig[3], error ) ;
  1314. hexbin(' .93ba 47c9 80e9 8cdf c h 426',tenbig[4], error ) ;
  1315. hexbin(' .b616 a12b 7fe6 17aa 4 h 532',tenbig[5], error ) ;
  1316. hexbin(' .e070 f78d 3927 556a c h 638',tenbig[6], error ) ;
  1317. hexbin(' .8a52 96ff e33c c92f c h 745',tenbig[7], error ) ;
  1318. hexbin(' .aa7e ebfb 9df9 de8d c h 851',tenbig[8], error ) ;
  1319. hexbin(' .d226 fc19 5c6a 2f8c 4 h 957',tenbig[9], error ) ;
  1320. hexbin(' .8184 2f29 f2cc e375 c h 1064',tenbig[10], error ) ;
  1321. hexbin(' .9fa4 2700 db90 0ad2 4 h 1170',tenbig[11], error ) ;
  1322. hexbin(' .c4c5 e310 aef8 aa17 4 h 1276',tenbig[12], error ) ;
  1323. hexbin(' .f28a 9c07 e9b0 9c58 c h 1382',tenbig[13], error ) ;
  1324. hexbin(' .957a 4ae1 ebf7 f3d3 c h 1489',tenbig[14],error) ;
  1325. hexbin(' .b83e d8dc 0795 a262 4 h 1595',tenbig[15], error) ;
  1326. end ;
  1327.  
  1328. procedure inittenhuge ;
  1329.  
  1330. var
  1331. error : boolean ;
  1332.  
  1333. begin
  1334. hexbin(' .e319 a0ae a60e 91c6 c h 1701',tenbig[16], error) ;
  1335. hexbin(' .8bf6 1451 432d 7bc2 c h 1808', tenbig[17], error) ;
  1336. hexbin(' .ac83 fb89 6b67 95fc c h 1914', tenbig[18], error) ;
  1337. hexbin(' .d4a4 4fb4 b8fa 79af c h 2020', tenbig[19], error) ;
  1338. hexbin(' .830c f791 e54a 9d1c c h 2127', tenbig[20], error) ;
  1339. hexbin(' .a188 4b69 ade2 4964 4 h 2233', tenbig[21], error) ;
  1340. hexbin(' .c71a a36a 1f8f 01cb c h 2339', tenbig[22], error) ;
  1341. hexbin(' .f56a 298f 4370 28f3 4 h 2445', tenbig[23], error) ;
  1342. hexbin(' .973f 9ca8 cd00 a68c 4 h 2552', tenbig[24], error) ;
  1343. hexbin(' .ba6d 9b40 d7cc 9ecc c h 2658', tenbig[25], error) ;
  1344. hexbin(' .e5ca 5a0b 8d73 7f0e 4 h 2764', tenbig[26], error) ;
  1345. hexbin(' .8d9e 89d1 1346 bda5 4 h 2871', tenbig[27], error) ;
  1346. hexbin(' .ae8f 2b2c e3d5 dbe9 c h 2977', tenbig[28], error) ;
  1347. hexbin(' .d729 3020 5a0c 1b2f c h 3083', tenbig[29], error) ;
  1348. hexbin(' .849a 672a 0d2e cfd1 c h 3190', tenbig[30], error) ;
  1349. hexbin(' .a372 2c13 41fa 93de 4 h 3296', tenbig[31], error) ;
  1350. end ;
  1351.  
  1352.  
  1353.  
  1354. begin
  1355. digitset := [ '0' .. '9' ] ;
  1356. hexset := digitset + [ 'A' .. 'F' ] ;
  1357. stack := nil ;
  1358. storagemode := unrounded ;
  1359. testflag := false ;
  1360. fpstatus.mode.round := rnear ;
  1361. fpstatus.mode.precision := xprec ;
  1362. fpstatus.mode.clos := affine ;
  1363. fpstatus.mode.norm := normalizing ;
  1364. fpstatus.curexcep := [] ;
  1365. fpstatus.excep := [] ;
  1366. fpstatus.trap := [] ;
  1367. leftnan[1] := 0 ;
  1368. leftnan[2] := 24 ;
  1369. leftnan[3] := 53 ;
  1370. leftnan[4] := leastsigbit + 1 ;
  1371. rightnan[1] := leftnan[2] - 1 ;
  1372. rightnan[2] := leftnan[3] - 1 ;
  1373. rightnan[3] := leftnan[4] - 1 ;
  1374.  rightnan[4] := stickybit ;
  1375. xcpnname[cvtovfl] := 'IV' ;
  1376. xcpnname[overfl] := 'OV' ;
  1377. xcpnname[underfl] := 'UN' ;
  1378. xcpnname[div0] := 'D0' ;
  1379. xcpnname[invop] := 'NO' ;
  1380. xcpnname[inxact] := 'NX' ;
  1381. inittensmall ;
  1382. inittenbig ;
  1383. inittenhuge ;
  1384. (*
  1385. decbin ( ' 3.1415926535 89793 23846 26433', pi, error ) ;
  1386. decbin ( ' 2.7182818284 59045 23536 02874', e, error ) ;
  1387. *)
  1388. hexbin ( ' .c90fdaa22168c234c h 2', pi, error ) ;
  1389. decbin ( ' 2.7182818284 59045 23536 02874', e, error ) ;
  1390. end ;
  1391.  
  1392.  
  1393. End-Of-File
  1394. echo ""
  1395. echo "End of Kit"
  1396. exit
  1397.  
  1398.