Post Reply 
(42S, Free42) Unit Conversion Suite
01-10-2018, 04:08 PM
Post: #1
(42S, Free42) Unit Conversion Suite
This is an adaptation of the UNITS menu from the 48. Obviously the 42S doesn't have unit-based calculation like the 48, so these are strictly numeric conversions. The attached program is in raw format.

Usage is very simple; run CONV, then choose a unit category from the menu. The unit menus work pretty much like any solver menu: enter a value, press a menu key, then press another menu key for the unit you want to convert to. Continue pressing menu keys to convert to other units. Note that there's no checking of unit consistency, so the program won't stop you from doing something zany like converting between cm and lb.

Conversion constants were obtained from my 48SX, by converting 1 of each unit to its corresponding value in the base unit for any category (usually the first one in the menu). Only the display precision was used; I didn't attempt to pry out the internal guard digits. The program was tested by converting through all units within a menu and comparing results while doing the same on my 48SX.

Some notable changes from the 48 units:
-Hz was removed from the Time menu, as it's really just shorthand for 1/s (and loses usefulness without true composite units).
-YrCal (365 days) was added to the Time menu, and Yr changed to YrSol (value unchanged).
-ga was removed from the Speed menu. In its place is a new Accel menu that compensates for the lack of composite units, and which contains m/s^2, ft/s^2, grav, and gal (the latter two taken from the Prime).
-Btu/h was added to the Power menu.
-cmH2O was added to the Press menu.
-Elec, Angl, Light, Rad, and Visc unit menus have been omitted, mostly for reasons of lacking a true unit calculation system.


There's a decent conversion program already available with Free42, but there are a couple of things that bother me about it: there's very little code reuse, so each unit conversion has a bunch of repeated code and the conversion factors are entered twice, and it's somewhat fragile in its use of the Y register to hold the underlying unit value. It also makes use of flag 1 in a way I can't really figure out what it's meant to do.

I set out to replicate the layout of the unit menus from my 48 in a way that only requires 6 lines of code to add a new conversion (2 for the menu entry, 4 for the conversion). If you're missing any exotic ones, it's easy to extend the program.

You're free to do whatever you like with this code.


.zip  Convert.zip (Size: 2.25 KB / Downloads: 7)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)