A while ago, I came to the conclusion that there weren't enough unit converters in the ticalc.org archives yet, and decided to write my own.

Of course, I wouldn't be satisfied with just a TI-BASIC program where you have to run it and manually type out the quantity you want to convert, so instead I integrated it into the TI-OS homescreen. Here are some screenshots of it in operation:



Current features:
    Unit parsing (by multiplying a number by a string containing the unit)
    Multiply/divide two quantities
    Add/subtract two quantities with the same dimension
    Negation of quantities
    Take the reciprocal of a quantity
    Find the square/square root of a quantity
    Store quantities to and recall quantities from a variable
    Display quantities using SI named derived units with SI prefixes
    Display other quantities with SI base units
    Throw an error when trying to perform an operation on quantities with incompatible units
    Support for both MathPrintâ„¢ and Classic modes
    Support for the Output() command
    Support for toString()/eval()


Planned features:
    Menu with unit names
    Quantities to an arbitrary power
    Arbitrary roots of a quantity
    Comparisons between quantities
    Support for TI-BASIC commands such as Disp/Text
    Lists of quantities
    Configuration options


No download available as of now, as the code's a mess and still slightly broken, and there's not yet an easy way of initially getting a unit into a variable. It also doesn't support imperial units at the moment. In the meantime, see if you can guess how this is implemented.

I probably should also use a less boring name than "Unit Tool," if anyone has any suggestions for that.
One kiloCongrats for you!
this is cool.
Great work!

You could call it "Univerter CE," the unit converter for the CE.
This is envelope-pushing, great work Smile
Really nice work, could be a very powerful tool indeed!
legendary
Progress update - I've added actual parsing of units:

I've also added support for negation and the square, square root, and reciprocal functions, though I haven't added support for arbitrary powers and roots yet.

toString() and eval() now also work, in case you wanted to use this in a TI-BASIC program. Still no support for Disp and Output yet, but that shouldn't be too hard to add.
I went ahead and made a GitHub repository for this here: https://github.com/commandblockguy/unit-tool. No releases as of yet, as it's still crash-prone and I might change the format of stuff in the future.

I've also added support for the Output() command. I wanted to support Disp too, but it's implemented differently without an easy way for me to hook into it, and there's not much point since you can just do eval() and it will do the same thing.
I've added a few of the more common US customary units (in, ft, yd, mi, ly, acre, cup, gal, floz, pt, qt, tbsp, tsp, oz, lb, ton).

Apparently there are a lot of units out there, a lot of which are infuriatingly named the same thing but with slightly different values.

There's not currently a way to switch between preferring metric units or preferring US customary units, but I'll add that in the future.

If you have any other units you'd like to have added, feel free to submit a PR adding them to common.asm, or just reply with them here. Right now there's a limit of 256 different units, but that's easy enough to fix if necessary.

I might also add some universal constants as well, for convenience.
Turns out, I wasn't the first person who decided to write this type of program. Apparently Benjamin Moody wrote the Unit Operations app back in 2003 which is basically the same thing. I had never heard of it before today (thanks to DrDnar to pointing me to it), but taking a look at it it's absurdly similar to my program, not just with the syntax but even down to how it represents units internally.

It includes a menu for selecting units, which wasn't something that I had seriously considered before but I definitely think should be included now. Typing stuff out character-by-character on a calculator keypad is unnecessarily slow, especially for stuff involving lowercase letters. Menus are a lot faster, especially once you get the muscle memory down. Unlike Moody's app, I would probably have it automatically insert a * prior to the string if the previous token in the edit buffer is not an operator, to further save time.

I'm not sure if I like its syntax for choosing what unit something is to be displayed with using the exponent operator (e.g. 10*"m"^"ft). You can do 10*"m"/"ft" instead most of the time. Also, (not that this was relevant back in 2003), ^ causes issues with MathPrint. I was thinking about using a syntax like 10*"m"→"ft", but this would require me to do something hacky with error handlers which might cause issues with other programs.

I'm also curious on hearing people's opinions on me turning this into an application rather than a program - it would allow me to actually use the call instruction, making the code much less of a mess (and faster to write). Users who have only used TI's apps before might also find it more familiar. On the other hand, TI might not like it, it might be more confusing for users since there's an extra installation step, it would take up more space due to the relocation table, I would have to figure out how to make LibLoad work from an app, and it would be less convenient to transfer from one handheld to another in a school setting.
So this morning I decided to work on this project again. Since I touched it last, I've developed some tooling to generate apps, so I converted the project to an app. This went rather smoothly, and doing so allowed me to remove a lot of code that was just there to deal with the code having to be position-independent (e.g. trampolines, indcalls, and juggling pointers to the current function around on the stack). This should speed up future development quite a bit.

I now have the option of writing code in C, as well. I'll probably leave most of the logic in assembly for performance reasons. However, I might use C for string conversions or for menus.

I think my next step is probably to write some unit tests. The neat thing about this project is that no matter what testing methodology I use, I'll be doing unit testing Cool
Great job! Just looked at the commit and yes it's much simpler, that's pretty awesome, and I hope more programs/apps like this get done, then!

Also, that's a good pun. :clap:
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement