Shop OBEX P1 Docs P2 Docs Learn Events
Float32 — Parallax Forums

Float32

anita1984anita1984 Posts: 23
edited 2009-10-26 10:28 in Propeller 1
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 smile.gif

Thank you alot in advance,
Best regards,
Anita

Post Edited (anita1984) : 9/30/2009 2:03:16 PM GMT

Comments

  • anita1984anita1984 Posts: 23
    edited 2009-09-30 14:04
    sad.gif
  • ElectricAyeElectricAye Posts: 4,561
    edited 2009-09-30 14:31
    Anita,

    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:
    
    f32 : "Float32" {Gives the OBEX object a new name of f32}
    
    
    




    Then in the main program, you can use f32's functions something like this:

    
    f32.Fadd(FirstNumber, SecondNumber)  {This adds FirstNumber to Second Number.}
    f32.Fsub(FirstNumber, SecondNumber)  {This subtracts SecondNumber from FirstNumber.}
    f32.Fmul(FirstNumber, SecondNumber)  {This multiplies FirstNumber with Second Number.}
    
    
    



    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
  • ElectricAyeElectricAye Posts: 4,561
    edited 2009-09-30 15:20
    Thank you
    Originally Sent : 9/30/2009 2:37:50 PM GMT by anita1984 said...

    Hello smile.gif ,
    Thank you for your post , but the problem

    sin(fnumA) ' for example, if fnumA = 30 , sin(fnumA)= 0.5 , am i true ?

    and what about :
    1)float(fnumA)
    2)fix(fnumA)
    Could you give me an example please , i am sorry, i am new in programming

    Thank you in advance,
    Anita

    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.
  • anita1984anita1984 Posts: 23
    edited 2009-09-30 16:22
    Thank you electricAye smile.gif

    please can someone explain for me the Fix function for a float?
    fix(fnumA)
    Thank you in advance,
    Anita
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-30 16:37
    Read the documentation that comes with the Float32 object from the Object Exchange. It describes how the whole floating point package works.

    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.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2009-09-30 17:28
    anita1984 said...
    Thank you electricAye smile.gif

    please can someone explain for me the Fix function for a float?
    fix(fnumA)
    Thank you in advance,
    Anita

    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
  • danielreisdanielreis Posts: 16
    edited 2009-10-23 17:45
    I'm with a problem to dysplay a decimal point number in PST

    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:


    OBJ
    
      term: "PC_Interface"
      mat: "Float32"
      s: "FloatString"
    
    .......
    .......
      
    PUB Main
    
      mat.start
      term.start(31, 30)
      
      c := mat.FAdd(2.0, 3.0)
      d := s.FloatToString(c)
      
      term.dec(c)
      term.str(d)
    
    




    best regards,

    Daniel Reis
  • PavelPavel Posts: 43
    edited 2009-10-23 18:45
    Daniel,

    are you running the chip at 80MHz? If not, you should add

    con
        _XINFREQ = 5_000_000
       _CLKMODE = XTAL1 + PLL16X
    
    



    at the top of your top object. PC_Interface needs all that speed for serial communication.

    Also this line

        term.dec (c)
    
    



    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).

        term.str (s.FloatString (c))
    
    



    should work.
  • danielreisdanielreis Posts: 16
    edited 2009-10-26 10:28
    Thank you very much Pavel, it works.
Sign In or Register to comment.