Advertisement
shiftdot515

fractions

Aug 14th, 2021
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.87 KB | None | 0 0
  1. // file factor.seq sept 19th 1994 2566 bytes
  2. variable flagx
  3. variable x
  4.  
  5. CODE /MOD_swap \ puts the remainder on top
  6. POP BX \ instead of /mod swap
  7. POP AX
  8. CWD
  9. MOV CX, BX
  10. XOR CX, DX
  11. JS 1 $
  12. IDIV BX
  13. PUSH aX
  14. PUSH dX
  15. ES:
  16. LODS WORD
  17. JMP AX
  18. 1 $: IDIV BX
  19. OR DX, DX
  20. JE 2 $
  21. ADD DX, BX
  22. DEC AX
  23. 2 $: PUSH aX
  24. PUSH dX
  25. next
  26. end-code
  27.  
  28.  
  29. : get-nth-prime ( N -- NTHPRIME )
  30.  
  31. 2*
  32. prime-array
  33. +
  34. @ ;
  35.  
  36. : is-prime? ( n -- n flag )
  37. flagx 0! \ set up flagx temp. varaible
  38. prime-array @ 1+ \ get count
  39. 1 do
  40. i get-nth-prime
  41. over = ?dup if flagx ! \ store flag in flag x
  42. leave
  43. then
  44. loop
  45. flagx @ ;
  46.  
  47.  
  48. : (factor) ( n0 -- n1 n2 n3 ... count )
  49. \ this might be better recursive?
  50. x ! \ store number into X
  51. depth >r \ store depth to calculate number of factors
  52. begin
  53. prime-array @ 1+
  54. 1 do
  55. x @ \ get number
  56. i get-nth-prime
  57. /mod_swap \ qout rem
  58. 0= if \ even division, a factor
  59. x ! \ store qout in x
  60. i get-nth-prime \ put it on the stack
  61. leave
  62. then
  63. drop
  64. loop
  65. x @ 1 =
  66. until
  67. depth
  68. r>
  69. - ;
  70.  
  71. \ the word above doesn't work for negatives, also 0
  72. \ fix for negatives is important,
  73. : factor ( n -- n1 n2 n3 ... count )
  74. dup
  75. 0<
  76. if
  77. -1 swap abs (factor) 1+
  78. \ would a divide work better?
  79. else
  80. (factor)
  81. then ;
  82.  
  83. : *loop ( x1 x2 x3 ... n -- y ) \ unfactor
  84. 1 ?do
  85. *
  86. loop ;
  87.  
  88. ' *loop alias unfactor
  89.  
  90. : ** ( n1 n2 -- n1^n2 )
  91.  
  92. ?dup 0=
  93. if drop 1
  94. else
  95. dup 1 =
  96. if drop
  97. else
  98. over swap 1-
  99. 0 do
  100. over *
  101. loop
  102. nip
  103. then
  104. then ;
  105.  
  106. // end of file ****
  107. // file matrix.seq oct 10 1994 5169 bytes
  108. \ Words for matrices
  109. \ going to use abreviation Mx for matrix
  110. 0 value v1
  111. 0 value v2
  112. \ this might to well as its own vocabulary
  113.  
  114. \ matrix should look like header-- c r --c*r2words
  115.  
  116. : 4* 2* 2* ;
  117.  
  118. \ vocabulary <matrix>
  119. \ also <matrix> definitions
  120.  
  121.  
  122. \ upperleft corner is (1,1)
  123.  
  124. : matrix ( r c -- | Matrix-name ) \ actually creates a double matrix
  125. \ which I can use for a Frac matrix
  126.  
  127.  
  128. create \ create the header for matrix-name
  129. 2dup
  130. *
  131. >r \ store the number of elements on the Return Stack
  132. here c! \ place #of columns as a byte, offset +0
  133. here 1+ c! \ place #of rows as a bytes, offset +1
  134. \ ok now allocate the necessary bytes
  135. r> \ Row*col
  136. 4* \ number of double-words needed
  137. 2+ \ one more word for the first 2 bytes.
  138. allot
  139. does> \ Matrix-name will do this on execution
  140. \ matrix-name ( --- address )
  141. 2+ \ start address of matrix
  142. ;
  143.  
  144. : @dim-of-Mx ( maddr -- max-row max-col )
  145. dup
  146. 1- c@
  147. swap
  148. 2- c@
  149. ;
  150.  
  151. : mcols@Mx ( maddr -- max-col )
  152. 2- c@
  153. ;
  154.  
  155. : ij>term# ( i j max-cols -- term# )
  156.  
  157. \ term# = max-cols(i-1)+j
  158. rot
  159. 1-
  160. *
  161. +
  162. 1-
  163. ;
  164.  
  165. : entry@ ( i j maddr -- entry )
  166. \ not doing any error checking
  167. dup>r
  168. mcols@Mx
  169. ij>term#
  170. 4*
  171. r>
  172. + frac@ ;
  173.  
  174. variable <mcol>
  175.  
  176. : init-mcol ( -- )
  177.  
  178. <mcol> 0!
  179. ;
  180.  
  181. : update-mcol ( width -- )
  182.  
  183. <mcol> @
  184. max \ leave the greater of the two
  185. <mcol> ! \ and store it
  186. ;
  187.  
  188. : is-integer? ( num den -- num den flag ) \ true when denominator = 1
  189. dup 1 = ;
  190.  
  191. : entry-width ( num den -- width )
  192.  
  193. is-integer? \ is entry a integer?
  194. if
  195. drop \ drop the 1
  196. number-of-digits
  197. else
  198. number-of-digits
  199. swap number-of-digits
  200. + 1+
  201. then
  202. ;
  203.  
  204. : (.entry)
  205. is-integer?
  206. if
  207. drop .
  208. else
  209. ./
  210. then
  211. ;
  212.  
  213. : .entry ( i j maddr -- )
  214. entry@
  215. 2dup
  216. entry-width
  217. update-mcol
  218. (.entry)
  219. ;
  220.  
  221. : entry! ( num den i j maddr -- )
  222. dup>r
  223. mcols@Mx
  224. ij>term# ( -- value term# )
  225. 4*
  226. r>
  227. + frac! ;
  228.  
  229. \ value for inner loop limit
  230. 2 value L.1
  231. 0 value v3
  232. \ 0 value addr.1
  233.  
  234. : fill-Mx ( num den maddr -- )
  235. dup
  236. @dim-of-Mx
  237. \ * 4* fill no 32-bit fill equivalent ( yet )
  238. 1+ =: l.1
  239. 1+ 1 do
  240. l.1 1 do
  241. 3dup
  242. j i
  243. rot
  244. entry!
  245. loop
  246. loop
  247. 3drop
  248. ;
  249. : make-zero ( maddr -- )
  250. 0 1 rot
  251. fill-Mx
  252. ;
  253.  
  254. : make-identity ( maddr -- )
  255. =: v1
  256. v1 make-zero \ make the Mx all zeros
  257. v1 mcols@Mx \ get the width of Mx.
  258. 1+ 1 do
  259. 1 1 i i v1 entry!
  260. loop
  261. ;
  262. 2variable z
  263.  
  264. : Mx*scalar ( maddr num den -- ) \ change Mx to Mx * scalar
  265. z frac!
  266. =: v1
  267. v1 @dim-of-Mx
  268. 1+ =: l.1
  269. 1+ 1 do \ outer loop = row
  270. l.1 1 do \ inner loop = column
  271. j i v1 entry@
  272. z frac@
  273. frac*
  274. j i v1 entry! \ thus j = row i = col
  275. loop
  276. loop
  277. ;
  278.  
  279. : Mx*integer ( maddr integer -- )
  280. 1 Mx*scalar ;
  281.  
  282. 2variable scalar
  283.  
  284. : scalar*Mx+Mx ( maddr1 maddr2 -- ) \ add maddr1 maddr2 =: mx1
  285. =: v2 \ matrix 2
  286. =: v1 \ matrix 1
  287. v1 @dim-of-mx
  288. 1+ =: l.1
  289. 1+ 1 do
  290. l.1 1 do
  291. j i v2 entry@ \ get entry from matrix.2
  292. j i v1 entry@ \ get entry form matrix.1
  293. scalar frac@ \ fetch the value for scalar
  294. frac* \ scalar * matrix.1's entry
  295. frac+
  296. j i v1 entry! \ set result to matrix.1 entry
  297. loop
  298. loop
  299. ;
  300. : Mx+mx ( maddr1 maddr2 -- ) \ mx1 := mx1 + mx2
  301. 1 1 scalar frac! \ set scalar to 1
  302. scalar*mx+mx
  303. ;
  304. : -mx+mx ( maddr1 maddr2 -- )
  305.  
  306. -1 1 scalar frac! \ set scalar to -1
  307. scalar*mx+mx
  308. ;
  309.  
  310. : mx-mx
  311. swap -mx+mx ;
  312.  
  313. : display-Mx ( maddr -- )
  314. at?
  315. =: v2 \ v1=col v2=row
  316. =: v1
  317. init-mcol
  318. dup
  319. @dim-of-Mx
  320. 1+ =: l.1 \ save columns for inner loop
  321. 1+ 1 do
  322. v2 =: v3
  323. l.1 1 do
  324. incr> v3 \ increase the row
  325. v1 v3 at
  326. i j pluck .entry
  327. loop
  328. <mcol> @ 1+ +!> v1 \ increase the columns by max width of entries
  329. loop
  330. drop
  331. ;
  332.  
  333. 3 3 Matrix r3
  334. ' display-mx alias .mx
  335.  
  336.  
  337. // file stack.seq
  338. \ stack manipulating words
  339.  
  340. code unfold ( a b -- a a b ) \ equalivalent to over swap
  341. pop bx \ analogous to pulling on the top of the stack
  342. pop ax \ and having the second term "unfold" creating a duplicate
  343. push ax \ of itself to fill the place.
  344. push ax
  345. push bx
  346. next
  347. end-code
  348.  
  349.  
  350. code make-within ( test-value min max -- value )
  351. pop cx \ max value
  352. pop bx \ min value
  353. pop ax \ test value
  354. cmp ax, cx
  355. jng here 6 +
  356. push cx \ test-value is passed through if
  357. next \ it less than max and greater than min
  358. cmp ax, bx \ if tv > max then max is returned
  359. jnl here 6 + \ if tv < min then min is returned
  360. push bx
  361. next
  362. push ax
  363. next
  364. end-code
  365.  
  366. // end of file ****
  367. // math.seq
  368. \ math words
  369.  
  370. : r/ swap over /mod swap 2* rot / + ; \ rounded division, good for integers
  371.  
  372. code u/mod ( num den -- umod uquot )
  373. pop bx
  374. pop ax
  375. xor dx, dx
  376. div bx \ dx:ax / bx -- dx=mod ax=quot
  377. push dx
  378. push ax
  379. next
  380. end-code
  381.  
  382. : umod ( num den -- umod )
  383. u/mod drop ;
  384.  
  385. : u/ ( num den -- uquot )
  386. u/mod nip ;
  387.  
  388.  
  389. : calc_sum \ ( ... #(n-1) #n n -- sum ) \ takes n single#s from the stack
  390. \ and finds the sum.
  391. 1 ?do
  392. +
  393. loop
  394. ;
  395.  
  396. : Dcalc_sum
  397. 1 ?do
  398. d+
  399. loop
  400. ;
  401.  
  402. : Dcalc_mean
  403. dup>r
  404. Dcalc_sum
  405. r>
  406. mu/mod nip ;
  407.  
  408. : MCalc_sum
  409.  
  410. 0. z 2! \ init temp 2var Z
  411. 0 ?do
  412. s>D \ convert number to double
  413. z D+! \ add to Z
  414. loop
  415. z 2@
  416. ;
  417. : MCalc_mean
  418. dup>r
  419. MCalc_sum
  420. r>
  421. M/mod nip ;
  422.  
  423.  
  424.  
  425. : calc_mean \ ( ... #(n-1) #n n -- mean ) \ takes n singles from the stack
  426. \ and calculates the mean
  427. dup>r
  428. calc_sum
  429. r>
  430. /
  431. ;
  432.  
  433.  
  434.  
  435.  
  436. // end of file ****
  437. // frac.seq 6197 bytes sept 18 1994
  438. \ Fraction math should support single numbers and signs
  439.  
  440. 0 value V1
  441. 0 value V2
  442.  
  443. \ need a symbol to use for all these types of operations
  444. \ fractions are rational numbers, or ratios so maybe ":"
  445. \
  446. \ format for ":"numbers (rational) numerator denominator
  447. \
  448. \ question: which should carry the sign?
  449. \
  450. \ probably the numerator
  451.  
  452.  
  453. : :. ( num1 den1 -- ) \ display fractional number
  454. swap
  455. (.) type
  456. ." /"
  457. .
  458. ;
  459. \ going to need a word called simplify which will need
  460. \ to factor a number
  461.  
  462. : :uncommon-factor ( n1 n2 -- uf1 uf2 )
  463. \ actually this is comming out uf2 uf1 ?
  464. \ uf1 will be what n2 has that n1 doesn't have
  465.  
  466. 2dup
  467. 0<
  468. swap
  469. 0<
  470. and
  471. if
  472. swap abs
  473. swap abs
  474.  
  475. then
  476. 2dup
  477. abs =: v2
  478. abs =: v1
  479. \ store n's into the values v1 & v2
  480. factor
  481. \ this will factor n2, leaving a result much like
  482. \ the root level of a factor tree, with a count
  483. \ on top
  484. 0 ?do
  485. v1
  486. \ 1st pass this will be n1
  487. swap
  488. /mod
  489. \ divide by a factor of n2,
  490. \ remember n2's factors are on the stack
  491. swap
  492. \ I want the remainder on top, I'm going to use
  493. \ it as a Flag for if
  494. if
  495. \ _if_ will see a nonzero as a true
  496. \ so anything that doesn't divide
  497. \ evenly will go this way
  498. \ (uncommon-factors)
  499. drop
  500. \ these aren't factors so I don't
  501. \ want them
  502. else
  503. \ factors will have a mod. of 0
  504. \ which is false
  505. =: V1
  506. \ I want to store the qoutient
  507. \ (the other factor)
  508. \ into
  509. then
  510. loop
  511. factor \ now do the same thing for n1
  512. 0 ?do
  513. v2
  514. swap
  515. /mod
  516. swap
  517. if
  518. drop
  519. else
  520. =: v2
  521. then
  522. loop
  523. \ v1 v2 this is confusing at times
  524. v2 v1 \ this might be better
  525.  
  526. \ ok what's left
  527. \ v1 will have in it the product of any of its factors
  528. \ that are uncommon with with n2
  529. \ v2 will all of n2's factors that are uncommon with n1'
  530. ;
  531.  
  532. comment:
  533. some examples: 12 36 :uncommon-factors ==> 1 3
  534. 13 17 :uncommon-factors ==> 13 17
  535. basically this word works the way I handle fractions, common-factors
  536. are dropped, or ignored and the leaving the uncommons
  537. 12 = 2*2*3
  538. 36 = 2*2*3*3
  539. comment;
  540.  
  541. ' :uncommon-factor alias :reduce1
  542.  
  543. : :no-neg-denom
  544. \ don't won't negatives in the denominator
  545. \ num dem
  546. dup 0<
  547. if
  548. swap negate
  549. swap abs
  550. then
  551. ;
  552.  
  553. \ I'm wondering if I should do some try some simple division first.
  554. : :reduce2
  555. 2dup
  556. /mod
  557. swap
  558. if drop
  559. :reduce1
  560. else
  561. \ this means num is divisible by the denominator
  562. -rot
  563. 2drop
  564. 1
  565. then
  566. ;
  567. : :reduce3
  568. 2dup > if :reduce2
  569. else
  570. 2dup
  571. swap
  572. /mod
  573. swap
  574. if
  575. drop
  576. :reduce1
  577. else
  578. >r
  579. 2drop
  580. 1
  581. r>
  582. then
  583. then
  584. :no-neg-denom
  585. ;
  586.  
  587. defer :reduce
  588.  
  589. ' :reduce3 is :reduce
  590.  
  591.  
  592. : :+ ( num1 den1 num2 den2 -- num3 den3 )
  593. pluck \ num1 den1 num2 den2 den1
  594. over \ num1 den1 num2 den2 den1 den2
  595. :uncommon-factor \ num1 den1 num2 den2 uf1 uf2
  596. swap
  597. swap >r \ num1 den1 num2 den2 uf2
  598. drop * \ num1 den1 p2 \r uf1
  599. rot \ den1 p2 num1 \r uf1
  600. r@ * \ den1 p2 p1 \r uf1
  601. + swap \ num3 den1 \r uf1
  602. r> * \ num3 den1
  603. \ :reduce
  604. ;
  605. comment:
  606. a d ae db ae + db
  607. __ + __ = ___ + ___ = _______
  608. bc ce bce bce bce
  609.  
  610. comment;
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619. comment:
  620. : :+ ( num1 den1 num2 den2 -- num3 den3 )
  621. rot \ num1 num2 den2 den1
  622. :uncommon-factor \ let's see we have num1 num2 uf1 uf2
  623. 2dup * abs >r \ the common denominator is a product of the
  624. \ uncommon-factors, store it it's the c-d
  625. \ num1 num2 uf1 uf2
  626. rot \ num1 uf1 uf2 num2
  627. * \ num1 uf1 p2
  628. -rot \ p2 num1 uf1
  629. * \ p2 p1
  630. + \ p2+p1
  631. r> \ p2+p1 c-d -- back in fraction form
  632. :reduce
  633. ;
  634. comment;
  635.  
  636. : :negate ( a b -- -a b ) \ negate the fraction on top
  637. >r
  638. negate
  639. r>
  640. ;
  641.  
  642. : :- ( num1 den1 num2 den2 -- num3 den3 )
  643. :negate
  644. :+
  645. ;
  646.  
  647. : :* ( num1 den1 num2 den2 -- num3 den3 )
  648.  
  649. rot
  650. * \ num1 num2 den3
  651. >r \ num1 num2
  652. * \ num3
  653. r> \ num3 den3
  654. :reduce
  655. ;
  656.  
  657. : :/
  658. swap :* ;
  659.  
  660.  
  661.  
  662. \s
  663. 0 value v3
  664. 0 value v4
  665.  
  666. : test-it
  667. time-reset
  668. =: v3
  669. =: v4
  670. 5000 0
  671. do
  672. v3 v4 :reduce 2drop
  673. loop
  674. .elapsed
  675.  
  676.  
  677.  
  678. // end of file ****
  679. // syntax error above, missing closing semicolon
  680. // file fraction.seq 6219 bytes Mar 8 2020
  681. \ Fraction math should support single numbers and signs
  682.  
  683. 0 value fc1
  684. 0 value fc2
  685.  
  686. ' 2variable alias frac-variable
  687. ' 2@ alias frac@
  688. ' 2! alias frac!
  689.  
  690.  
  691.  
  692. \ code /mod_swap
  693.  
  694. : ./ ( num1 den1 -- ) \ display fractional number
  695. swap
  696. (.) type
  697. ." /"
  698. .
  699. ;
  700. \ going to need a word called simplify which will need
  701. \ to factor a number
  702.  
  703. : uncommon-factors ( n1 n2 -- uf1 uf2 )
  704. \ actually this is comming out uf2 uf1 ?
  705. \ uf1 will be what n2 has that n1 doesn't have
  706.  
  707. 2dup
  708. 0<
  709. swap
  710. 0<
  711. and
  712. if
  713. swap abs
  714. swap abs
  715.  
  716. then
  717. 2dup
  718. abs =: fc2
  719. abs =: fc1
  720. \ store n's into the values fc1 & fc2
  721. factor
  722. \ this will factor n2, leaving a result much like
  723. \ the root level of a factor tree, with a count
  724. \ on top
  725. 0 ?do
  726. fc1
  727. \ 1st pass this will be n1
  728. swap
  729. /mod_swap
  730. \ divide by a factor of n2,
  731. \ remember n2's factors are on the stack
  732. \ I want the remainder on top, I'm going to use
  733. \ it as a Flag for if
  734. if
  735. \ _if_ will see a nonzero as a true
  736. \ so anything that doesn't divide
  737. \ evenly will go this way
  738. \ (uncommon-factors)
  739. drop
  740. \ these aren't factors so I don't
  741. \ want them
  742. else
  743. \ factors will have a mod. of 0
  744. \ which is false
  745. =: fc1
  746. \ I want to store the qoutient
  747. \ (the other factor)
  748. \ into
  749. then
  750. loop
  751. factor \ now do the same thing for n1
  752. 0 ?do
  753. fc2
  754. swap
  755. /mod_swap
  756. if
  757. drop
  758. else
  759. =: fc2
  760. then
  761. loop
  762. fc1 fc2
  763. \ ok what's left
  764. \ fc1 will have in it the product of any of its factors
  765. \ that are uncommon with with n2
  766. \ fc2 will have all of n2's factors that are uncommon with n1'
  767. ;
  768.  
  769. comment:
  770. some examples: 12 36 :uncommon-factors ==> 1 3
  771. 13 17 :uncommon-factors ==> 13 17
  772. basically this word works the way I handle fractions, common-factors
  773. are dropped, or ignored and the leaving the uncommons
  774. 12 = 2*2*3
  775. 36 = 2*2*3*3
  776. comment;
  777.  
  778. : frac-defined? ( frac1 -- frac1 true ; false )
  779. dup
  780. 0= if
  781. 2drop
  782. false
  783. else
  784. true
  785. then
  786. ;
  787.  
  788. : no-neg-denominator
  789. \ don't want negatives in the denominator
  790. \ num dem
  791. dup 0<
  792. if
  793. swap negate
  794. swap abs
  795. then
  796. ;
  797.  
  798. : simplify-frac
  799. over 0= if drop 1 \ convert to 0/1 if 0/n
  800. else
  801. uncommon-factors
  802. no-neg-denominator
  803. then
  804. ;
  805. : reduce-frac
  806. 2dup
  807. mod
  808. if 2dup
  809. swap
  810. /mod_swap if
  811. drop
  812. else
  813. >r
  814. 2drop
  815. 1
  816. r>
  817. then
  818. else
  819. / 1
  820. then
  821. simplify-frac
  822. ;
  823.  
  824. \ I'm not going to worry anymore about speed for now
  825. \ may be look at this again after matrices are done.
  826.  
  827. : frac+ ( num1 den1 num2 den2 -- num3 den3 )
  828. pluck
  829. over \ num1 den1 num2 den2 den1 den2
  830. uncommon-factors \ num1 den1 num2 den2 uf1 uf2
  831. >r
  832. >r
  833. rot \ num1 num2 den1 den2 \r uf2 uf1
  834. 2swap \ den1 den2 num1 num2
  835. 1 rpick \ den1 den2 num1 num2 uf2
  836. * \ den1 den2 num1 p2
  837. swap \ den1 den2 p2 num1
  838. r@ * \ den1 den2 p2 p1
  839. + \ den1 den2 num3
  840. -rot \ num3 den1 den2 \r uf2 uf1
  841. r>drop
  842. nip
  843. r> \ num3 den2 uf2, this product ( or den1 uf1 )
  844. * \ will be the least common denonimator
  845. reduce-frac
  846. ;
  847. comment:
  848. a d ae db ae + db
  849. __ + __ = ___ + ___ = _______
  850. bc ce bce bce bce
  851.  
  852. comment;
  853.  
  854. : negate-frac ( a b -- -a b ) \ negate the fraction on top
  855. >r
  856. negate
  857. r>
  858. ;
  859.  
  860. : frac- ( num1 den1 num2 den2 -- num3 den3 )
  861. negate-frac
  862. frac+
  863. ;
  864.  
  865. : frac* ( num1 den1 num2 den2 -- num3 den3 )
  866.  
  867. rot
  868. * \ num1 num2 den3
  869. >r \ num1 num2
  870. * \ num3
  871. r> \ num3 den3
  872. reduce-frac
  873. ;
  874.  
  875. : frac/
  876. swap frac* ;
  877.  
  878. : calc-center-offset ( width max-range -- offset )
  879. \ it should follow this formula
  880. \ M - (M+W)/2 = offset
  881. dup
  882. rot
  883. +
  884. 2/
  885. -
  886. ;
  887.  
  888. : number-of-digits ( n -- width )
  889. dup
  890. abs
  891. 17 1 do
  892. base @ / dup
  893. 0= if
  894. drop
  895. i
  896. leave
  897. then
  898. loop
  899. swap 0< if 1+ then
  900. ;
  901.  
  902. : .C ( n l -- )
  903. >r
  904. dup
  905. number-of-digits
  906. r@ calc-center-offset
  907. dup>r
  908. spaces
  909. .
  910. r>
  911. r>
  912. - abs 1- spaces ;
  913. \ ^
  914. \ |
  915. \ -- dot will leave an extra space
  916.  
  917. : bars ( n -- )
  918. 0 ?do
  919. ." �"
  920. loop ;
  921.  
  922. 5 value .frac-digits \ number of digits to allow for
  923. \ in the next word
  924.  
  925. : .frac ( num1 den -- )
  926. at? 2dup 2>r
  927. 1+ at
  928. .frac-digits .c
  929. 2R@ 1- at
  930. .frac-digits .c
  931. 2r> at
  932. .frac-digits bars
  933. ;
  934.  
  935.  
  936. // end of file ****
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement