Improved floating point calculator. with source *fixed*
codeviper
Posts: 208
sorry the version i posted before had some major bugs I faxed them.
Duane Degn helped revise the F32 and floatstring2 drivers.
thanks man :thumb:
In using the prop as a real computer I needed a real calculator.
so i quickly took what was there and hacked together this one.
I improved it and now you cannot type over the 7 digit limit.
and i like the first number then second then answer format more.
to run this as is you need.
a PS2 keyboard on the pins the demoboard uses.
a NTSC TV with the DAC on the bins for the demoboard.
and a working propeller.
here is the source.
later on i may add PI and trig support to it.
Duane Degn helped revise the F32 and floatstring2 drivers.
thanks man :thumb:
In using the prop as a real computer I needed a real calculator.
so i quickly took what was there and hacked together this one.
I improved it and now you cannot type over the 7 digit limit.
and i like the first number then second then answer format more.
to run this as is you need.
a PS2 keyboard on the pins the demoboard uses.
a NTSC TV with the DAC on the bins for the demoboard.
and a working propeller.
here is the source.
later on i may add PI and trig support to it.
zip
40K
Comments
and why cant i get this to go over 7 digits, i think it has to do with Float to string.
is there something better i can use.
Im working on a resistor calculator next. pic the colors and get the number or pick the number and get the colors.
I want to include a calculator feature on one of my touchscreen projects.
The FloatString2 object is set to 7 digits by default. You can change it with the "SetPrecision" method.
I'd suggest moving the line
to the first line after "repeat" so it shows up with each new calculation.
I really like how you can use the answer to the previous calculation as the first number in the next set of calculations.
Your power operator "^" is set up for integer math. You'll want to use the "Pow" method of the floating point object.
F32 is a new floating point object that includes all the previous float methods inside just one cog. It's faster and smaller than the other float objects.
I don't know if the version in the OBEX has been updated with the most recent bug fix but the latest version can be found here.
If you move the variables from the VAR section to a DAT section, you can use F32 from several different objects (such as your top object and floatString2), you'd only have one object start F32 and you'd need to make sure it wasn't called by two different cogs at the same time.
I'm not sure if I'm remembering correctly, but I thought someone on the forum had made a program to emulate one of the HP scientific calculators.
soon i will add a parser for the trig functions.
one day i hope to make a formula parser..... one day
I tried to adjust the limit of precision but it just messed up floatstring2 so I am leaving it as is for now.
is there a better version or does someone know who to alter it? it seems to be limited to 7 digit precision.
like another floating point driver?
or should i be happy that i got this far?
An example, using the attached code.
I haven't looked at the latest upload yet. The attached code includes some changes to the ealier code to see about changing the number of displayed digits. I also used the float version of the power function and switched the floating point object to F32.
I also modified F32 so the float string object (also modified) could share it with the top object. I'm not sure if this made the program any smaller though.
Anyway, with the mods, the above eleven digit number is possible to display.
There are many cases when using integer math will be more accurate than floating point math on the Prop.
For example, I think if one were to add 1234567899 + 111111100 and the Prop, you'd get 1345678999 as the (correct) answer. Using floating point, the answer would be 1345679000.
Of course there are plenty of times floating point will be a better choice. I don't know of a firm rule of when one should be used instead of the other. I tend to use floating point for trig calculations and use integer for most addition, subtraction, multiplication and division needs.
and thanks for all the help.
I try my best to communicate but I always get a sort of do it yourself attitude.
I know one way to get super correct FP but its a bit slow.
I could write an algorithm that did math the way we do math one digit at a time from the string.
it would not be impossible the addition and subtraction would be easy it would be the multiply and divide that would get hairy.
So what double-precision floating point solutions currently exist for the Prop?
UCSD Pascal or Turbo C via CP/M?
Gcc via ZOG?
A Forth FP library converted to PropForth? (I.e. FP for PF.)
Anything else?
There's a little bit of 64-bit floating point stuff on the Propeller Wiki site. It only describes +-*/ functions. I don't know if there is any trig stuff done with 64-bits on the Prop or not.
Someone did release an object to use an external 64-bit floating point chip.
I'd like to see something like F32 done with 64 bits. F64 anyone?
I would like to draw your attention to the "True Calculator" of H. Thimbleby. He said:
"Existing calculators are unreliable and difficult to use and they are marketed misleadingly.
A new calculator is described that is simple, reliable and very powerful."
You can google more on the net about this interesting project. The main point is that he was
and he is right. Calculator manufacturers continue to sell incompetent technology to an uncritical
public, even today.
Yes, "True Calculator" can be done with the Prop. I am in a 80% completed project, - Proper Calculator -,
where I am using the FPU64 for 14 digits precision number crunching, to tell you the truth. This makes
programming much easier and I am lazy by default. The SPIN/PASM project depends heavily on the
multi-core capability of the processor.
To make a "True Calculator" with the Propeller you will need a multi-line display, some basic word
processing code with parsing and a flexible, non-linear equation solver, to begin with. The whole
thing is very inspiring whent it starts to work. It is realy enjoyable to calculate with it. User learns
correct math at lightning speed without too much effort.
cessnapilot
I look forward to seeing your "Proper Calculator".
It took me a bit to find a copy of "True Calculator". There were a lot of dead links in the first pages I checks.
Here's a link to an active copy.
IIRC, you're the one who posted the FPU64 object.
I am working on an algorithm that will do math like we do math one digit at a time.
I don't know how long it might take me to get multiply and divide down but my final goal will be 100 digit precision.
basic logic of this is
each number will have digits in an array. for adding and subtracting we will do exactly the same and do it place by place.
for multiply the scan method one digit on the bottom number will be multiplied by each place on the top number and added to the answer.
and divide will be done in a similar way.
if anyone wants to beat me to this fine.
but it can be done in spin.
it wont be the fastest car on the lot but it will be accurate, and fast enough for a calculator.
hard to implement, but most of his basic proposals can be worked out. The result is something like an
easy to use nano mathlab merged with a simple full screen editor. I found J. Crenshaw's series of
articles about "How to buid a compiler" very useful to implement the parser. I have stringent requirements
to put something on OBEX, so it will take time to fulfill them. I would like it to be display unspecific, so
TV or low resolution VGA is planned for display of the Proper Calculator. The task to make a hand-held
version will be left for the interesting user.
codeviper: That is very interesting. With hundred digits you can display the exact number of protons in
the universe or the national debt of some countries in (euro) cent accuracy. To be more serious, your
plans seems to be a good project to learn a lot and invent something new. As for a debugging tool I
recommend to use a TI-92 as it can handle a large number of integer digits. As far as I know it uses a
4-bit processor.
Istvan
Thanks for the newer version of the article.
I keep hoping to find the FPU-64 chip at Parallax or Sparkfun so can share the shipping cost with other electronic items.
I don't mind paying $25 for the chip, I'd just rather not also have to pay $15 shipping.
Since I don't really need 64-bit precision with any of my current projects, I'll probably wait a while before purchasing the chip.
It requires the following setup:
NTSC Video starting on P12
Sound Outputs on P10 & 11
If you want you can Save "MyCalc.BIN" to the Root of your Propeller's SD Card using your PC.
MyCalc 2_1 - Archive [Date 2012.12.15 Time 11.19].zip
MyCalc.bin
I wanted a way to exit out of the MyCalc program so I revised MyCalc 2
Changes in V2.1 - Dec 15, 2012 by zappman
The program now displays the following 3 lines on start up.
MY CALCUATOR Ver 2.1
Function Keys are + - / * ^
Q or q then Enter will Reboot System
You can now reboot your Propeller Chip by typing "Q" or "q" then the Enter key
I start via a Lauch Menu Program that loaded in my Propeller boards EEPROM.
Now I have a way to get back to the Launch Program Menu
Hope you enjoy the Program, Zappman