Jump to content
  • entries
    4
  • comments
    13
  • views
    7,121

Lesson 3a: Better Temperature Conversion Words


Lee Stewart

1,218 views

blog-0398761001439699602.png

We can write better temperature conversion words than we did at the end of the last lesson. If you thought that the words using /MOD were contrived to introduce /MOD , you were mostly on target. To obviate the necessity of using /MOD , all we need to do is to manage the dividend before division by adding half of the divisor. As before, we must adjust the sign of the rounding term to match the sign of the dividend and adjust the conversion formula such that the rounding term is an integer.

For TC>TF , the rounding formula is

 

F = 9C/5 ± 0.5 + 32

F = (9C ± 2.5)/5 +32

and, for an integer rounding term, we have

F = (18C ± 5)/10 + 32

Now, we can write the new definition for TC>TF :

 

: TC>TF
( degC -- degF )

18 * DUP SGN 5 * + 10 / 32 + ;

 

Similarly, for TF>TC :

 

C = 5(F - 32)/9 ± 0.5

C = (5(F - 32) ± 4.5)/9

C = (10(F - 32) ± 9)/18

 

and, the new definition for TF>TC :

: TF>TC
( degF -- degC )

32 - 10 * DUP SGN 9 * + 18 / ;

 

It would be a good exercise for you to walk through the execution and track the stack contents for each of the above words, much as we did in Lesson 3.

As always, I need your feedback to make this tutorial more useful.

 

 

  • Like 3

1 Comment


Recommended Comments

I've not forgotten! Things should slow down at work in January, then I'll start over from the beginning (I've forgotten everything already).

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...