Shop OBEX P1 Docs P2 Docs Learn Events
Floating Point Routines — Parallax Forums

Floating Point Routines

brsbrs Posts: 33
edited 2006-06-22 13:41 in Propeller 1
I'm having difficulty using the Sin and Cos functions included in the Float32Full.spin file obtained from the objects library. It appears negative values are not being computed correctly. For example, the following two computations:

tmp := f.Sin(f.FDiv(PI,4.0))
tmp := f.Sin(f.FDiv(-PI,4.0))

should result in 0.70710678 and -0.70710678, respectively. However, my propeller is outputting 0.70710678 for both.

Float32Full.spin is coded in assembly to which I have little experience in. Any suggestions?

Regards,
B

Comments

  • cgraceycgracey Posts: 14,206
    edited 2006-06-10 04:13
    B,

    Runtime expressions are always treated as integer. So, that -PI is getting two's-complemented as a binary number - this is not what you need. You need to use CONSTANT(-PI) to have this properly computed (at compile time). I may need to modify the compiler to prohibit any integer operations on floating point constants to get people around this pitfall. I'll be thinking about what to do in these cases that makes the most sense. Sorry for the trouble.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • brsbrs Posts: 33
    edited 2006-06-10 17:42
    Thanks Chip. I'll give that a try.

    B
  • brsbrs Posts: 33
    edited 2006-06-13 11:15
    It still appears negative Sine values are being computed incorrectly. For example, the following six calculations yield the same result of 0.7071044:

    tmp := f.Sin(f.FDiv(PI,4.0))
    tmp := f.Sin(f.FDiv(-PI,4.0))

    tmp := f.Sin(f.FDiv(PI,4.0))
    tmp := f.Sin(f.FDiv(constant(-PI),4.0))

    tmp := f.Sin(0.7854)
    tmp := f.Sin(-0.7854)

    I'm using the parallax four line serial lcd and debug_lcd.spin object as my debugger. Any suggestions?

    Regards,
    B

    Post Edited (brs) : 6/13/2006 3:41:44 PM GMT
  • cgraceycgracey Posts: 14,206
    edited 2006-06-13 16:26
    It looks like there must be a bug in that floating point object. We will contact the author and ask him to fix it. Sorry about this.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • brsbrs Posts: 33
    edited 2006-06-15 02:07
    Any news on the Float32Full.spin object?
  • cgraceycgracey Posts: 14,206
    edited 2006-06-15 05:51
    I believe the author is in Europe right now and we are waiting for him to return. It may take another week to get this fixed. Are you adventurous? You might try seeing if there is anything obviously wrong in the code.
    brs said...
    Any news on the Float32Full.spin object?
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • camtcamt Posts: 45
    edited 2006-06-15 17:41
    Hi, I'm the author and as Chip said I'm travelling in Europe until Jun 22, and won't be able to check the code until I return to the office. There was an old version posted briefly, so you may want to confirm that you have the most up-to-date version dated V1.0 May 17, 2006 (It's the one currently posted). I'll check into this on my return to the office. Sorry for the delay.

    Cam Thompson
  • camtcamt Posts: 45
    edited 2006-06-22 13:41
    B,

    The code for Sin/Cos in Float32Full was slightly out of sync with the correct code in Float32. The testing was done using Float32, so the problem in Float32Full slipped by. They are now in sync, and I've included a new set of routines (the only change is Float32Full). The most up-to-date version of Float32Full is now V1.1 - June 22, 2006.

    Cam Thompson
    Micromega Corporation
Sign In or Register to comment.