View Full Version : Improved floating point calculator. with source *fixed*

codeviper

04-07-2012, 09:50 PM

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.

codeviper

04-08-2012, 09:30 AM

i added source will someone say something?

codeviper

04-09-2012, 05:52 AM

I wonder why the only other calculator in the forums is integer only?

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.

Duane Degn

04-09-2012, 03:30 PM

Cool calculator.

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

Term.Str(string("> "))

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 (http://forums.parallax.com/showthread.php?125498-Any-ways-to-speed-up-Float32&p=1070785&viewfull=1#post1070785).

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.

codeviper

04-15-2012, 04:23 AM

its been improved I have uploaded new source in the first post.

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.

Mike Green

04-15-2012, 04:27 AM

All of the floating point objects use single precision IEEE format for their number representation and that's limited to about 7 digits of precision.

codeviper

04-15-2012, 04:29 AM

is there a way around that?

like another floating point driver?

or should i be happy that i got this far?

Mike Green

04-15-2012, 04:47 AM

The way around it is to write your own multiple precision floating point or fixed point arithmetic package since there isn't any yet. It would be a good learning experience.

Duane Degn

04-15-2012, 05:10 AM

Depending on the way you want data presented, even if you don't have more than seven digits of precision, you might want to display more than seven digits.

An example, using the attached code.

>10000000*1000=10000000000

>

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.

codeviper

04-15-2012, 05:27 AM

thanks thanks thanks, i didnt want to reinvent the wheel. you see I have done that too many times. worst thing is when I figured things out, and then got laughed at for not knowing someone else did it already.

codeviper

04-15-2012, 06:13 AM

yikes I made a mistake I am fixing it, don't use the new file

Duane Degn

04-15-2012, 08:30 AM

The example I gave above showing the program using numbers with more than seven digits will only give correct answers if the number of significant digits remain at around seven. So basically, you can use more than seven digits as long as the extra digits are zero.

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.

codeviper

04-15-2012, 04:14 PM

I got ya.

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.

User Name

04-20-2012, 01:52 AM

All of the floating point objects use single precision IEEE format for their number representation and that's limited to about 7 digits of precision.

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?

Duane Degn

04-20-2012, 02:10 AM

So what double-precision floating point solutions currently exist for the Prop?

There's a little bit of 64-bit floating point stuff on the Propeller Wiki (http://propeller.wikispaces.com/MATH)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?

cessnapilot

04-21-2012, 07:07 AM

codewiper:

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

Duane Degn

04-21-2012, 05:34 PM

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 (http://www.cs.swan.ac.uk/calculators/resources/truecalc.pdf).

IIRC, you're the one who posted the FPU64 object.

codeviper

04-21-2012, 08:22 PM

sorry between school and the contest which seems to have only two entrants I have been busy.

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.

cessnapilot

04-23-2012, 06:45 AM

Duane Degn: I attached a 19 pages newer version of that article. Some of the author's ideas are really

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

Duane Degn

04-23-2012, 07:43 AM

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.

zappman

12-15-2012, 04:56 PM

MyCalc Version 2.1 for "NTSC TV PMC" - a floating point calculator

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.

97859

97860

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