Recent

Author Topic: Floating Point Error  (Read 3911 times)

greertr

  • Full Member
  • ***
  • Posts: 113
    • Virtual Pilot Dashboard
Floating Point Error
« on: December 05, 2016, 03:47:45 pm »
I've pretty much finished a little project at Source Forge, but there's one little bug I have been able to resolve.  When you load up the application, you get a floating point error.  If you go past the error, the application works just fine.  I don't remember using anything but integers and strings in the source code.

If anyone could help, please download the application from source forge and see if you get an error on load, and if you're a genius, help me figure out what's causing it.

https://sourceforge.net/projects/pilot-dashboard/

thx in adv

Greer

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
Re: Floating Point Error
« Reply #1 on: December 05, 2016, 04:14:57 pm »
Have you tried debug mode with range-checking and overflow checking turned on?
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

greertr

  • Full Member
  • ***
  • Posts: 113
    • Virtual Pilot Dashboard
Re: Floating Point Error
« Reply #2 on: December 05, 2016, 05:01:30 pm »
Yup - no errors or messages

It seems to only happen when I copy the .exe file out of the project directory and run it on the desktop.  At first I thought it might just be my antivirus so i downloaded and ran it on a laptop that has no a/v on it and got the error.  After the first execution the error stops appearing.
« Last Edit: December 05, 2016, 05:03:57 pm by greertr »

Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Re: Floating Point Error
« Reply #3 on: December 05, 2016, 05:25:34 pm »
Two things:

1. SpVoice is an OleVariant, not a variant. There's a huge difference.
2, Interfacing with MS dll's, including some COM objects requires you to save and load the 8087 Control word, since ms messes up the fpu error flags.

AD 2: google for example, basically:
Code: Pascal  [Select][+][-]
  1. Save8087CW := Get8087ControlWord;
  2. Set8087CW($133F);  // ms compatible FPU flags, it basically says "Do not raise floating point exceptions. EVER!"
  3. ... your code
  4. ... when done:
  5. Set8087CW(Save8087CW);

I haven't got the time to compile this on Windows (I am on Linux), but this answer is correct. Maybe there are more errors, but ad 2 is REALLY important.
« Last Edit: December 05, 2016, 05:30:15 pm by Thaddy »
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11384
  • FPC developer.
Re: Floating Point Error
« Reply #4 on: December 05, 2016, 05:36:05 pm »
The portable way of doing that btw is

Code: Pascal  [Select][+][-]
  1. uses
  2.  math;
  3.  
  4.  SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision])

greertr

  • Full Member
  • ***
  • Posts: 113
    • Virtual Pilot Dashboard
Re: Floating Point Error
« Reply #5 on: December 05, 2016, 06:16:52 pm »
i'm putting the code snippets in...

marcov, your snippet comliled okand appears to have fixed the error

thx to both of you
« Last Edit: December 05, 2016, 06:35:09 pm by greertr »

Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Re: Floating Point Error
« Reply #6 on: December 05, 2016, 10:25:06 pm »
The portable way of doing that btw is

Code: Pascal  [Select][+][-]
  1. uses
  2.  math;
  3.  
  4.  SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision])

Tnx Marco. Did not know that one ;)

@greertr
Just be sure you save and restore, like in my example, on Windows.
Maybe there is a portable way to do that too?
« Last Edit: December 05, 2016, 10:29:08 pm by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018