Float32
anita1984
Posts: 23
Hi Forum ,
In the propeller object exchange obex.parallax.com/objects/202/ their is float32.Spin , they wrote:
1) _FFloat fnumA = float(fnumA)
2)_FTrunc fnumA = fix(fnumA)
3)fnumA = sin(fnumA)
Can someone please explain to me how this is working by giving an example , i know that :
_FMul fnumA = fnumA * fNumB
_FAdd fnumA = fnumA + fNumB
_FSub fnumA = fnumA - fNumB but those 3 points montined before is the problem
Thank you alot in advance,
Best regards,
Anita
Post Edited (anita1984) : 9/30/2009 2:03:16 PM GMT
In the propeller object exchange obex.parallax.com/objects/202/ their is float32.Spin , they wrote:
1) _FFloat fnumA = float(fnumA)
2)_FTrunc fnumA = fix(fnumA)
3)fnumA = sin(fnumA)
Can someone please explain to me how this is working by giving an example , i know that :
_FMul fnumA = fnumA * fNumB
_FAdd fnumA = fnumA + fNumB
_FSub fnumA = fnumA - fNumB but those 3 points montined before is the problem
Thank you alot in advance,
Best regards,
Anita
Post Edited (anita1984) : 9/30/2009 2:03:16 PM GMT
Comments
I'm not sure I understand your question, but I'll give it a try.
In the OBJ section at the top of your program, you can do something like this:
Then in the main program, you can use f32's functions something like this:
Be sure that FirstNumber, etc. are Float numbers. And note that the results of anything done with f32 will be floats, so if you need them converted to integers, then you'll have to do that conversion. To convert to Float in this example, you would use f32.Ffloat(SomeNumber). To convert to integer, you would use f32.Ftrunc to get a truncated integer, or f32.Fround to get a rounded integer.
There's slightly more information about how Float32 works if you look at the FloatMath.spin object.
I hope that is of some help,
Mark
Anita,
it's best to reply to these things on the forum so that all the forum members have a chance to help you. I'm somewhat new to the Propeller, too, and there are many more people on the forum who have a lot more experience than I do. I hope you don't mind, but I'm going to post this message on the forum so others can check my suggestion. I would hate to lead you astray.
Take a look at the OBEX object named Float32Full It will have the Sin function. Remember that to use any Float function, the number you insert must be a Float to start with. You can enter 30 by writing 30.0 to indicate that it is a float. If the number is an integer, then it must be converted to Float before you insert it into the Float function.
So let's say SomeNumber is an integer.
First, you convert it to float by writing
f32.Ffloat(SomeNumber)
Then you would write
f32.Sin(SomeNumber)
I'm not sure what the Fix function is for a float. Maybe somebody on the forum can help with that.
please can someone explain for me the Fix function for a float?
fix(fnumA)
Thank you in advance,
Anita
There is no "fix" function. There's an FTrunc and an FRound function. Both take the floating point value and convert it to an integer. The first truncates any fraction portion and the second rounds it upwards first, then truncates and converts it.
If you are looking for fix functions for displaying numbers with decimal points, then the Float packages are not the place to look. How you solve the problem of displaying decimal point numbers will depend on what you hope to use for a display, TV, VGA, etc. If that's the situation, let us know what you are using to display your outputs.
Also, I've attached a document that tells a little about the various float math packages.
Hope this is helping,
Mark
I'm using the PC_Interface.spin object, from propTerminal, Float32.spin and FloatString.spin
I used the FAdd routine of Float32 to make a sum, and tried to use the dec routine of PC_Interface to display the result, but it not works.
Then I tried to convert the result in a string, and doesn't work again.
How can I display the decimal point number on the computer screen?
Follows my code:
best regards,
Daniel Reis
are you running the chip at 80MHz? If not, you should add
at the top of your top object. PC_Interface needs all that speed for serial communication.
Also this line
will not produce the desired result if c is a float number. Float numbers are encoded differently than integers (you will see some strange value).
should work.