Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Divide by zero

  1. #1
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264

    Divide by zero

    Correct me if I'm wrong, but people who use to program in Borland C++ would experience divide by zero messages, right? I think it is because in opengl32.dll, it does some calculations that can cause a divide by zero. There was a solution to get rid of the messages I think. Anyone remember?
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  2. #2
    Junior Member Regular Contributor
    Join Date
    Aug 2007
    Location
    Adelaide, South Australia
    Posts
    206
    In Borland Delphi you had to change the FPU control word during program initialisation with the command:
    Set8087CW($133F);
    With any luck their C++ compiler uses the same command, with 0x133F for the hexadecimal value
    Last edited by Simon Arbon; 02-03-2013 at 05:16 PM.

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Quote Originally Posted by Simon Arbon View Post
    In Borland Delphi you had to change the FPU control word during program initialisation with the command:
    Set8087CW($133F);
    With any luck their C++ compiler uses the same command, with 0x133F for the hexadecimal value
    Thanks for the reply.
    In reality, the program is in VB6, GL 1.1. It has been working fine on various hardware (nvidia, AMD, intel). Recently, I discovered that on AMD HD 5450 and another one (6xxx), with Catalyst 13.1 (the current one), it flags division by 0 on functions like glScalef.
    WTF? I had disabled FPU error reported in VB6. I wonder if the AMD driver is enabling it.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  4. #4
    Junior Member Regular Contributor
    Join Date
    Aug 2007
    Location
    Adelaide, South Australia
    Posts
    206
    Here is the actual assembler code it uses if thats any help.

    Code :
    procedure Set8087CW(NewCW: Word);
    begin
      Default8087CW := NewCW;
      asm
            FNCLEX  // don't raise pending exceptions enabled by the new flags
    {$IFDEF PIC}
            MOV     EAX,[EBX].OFFSET Default8087CW
            FLDCW   [EAX]
    {$ELSE}
            FLDCW   Default8087CW
    {$ENDIF}
      end;
    end;

  5. #5
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,170
    I had similar issues with odd releases of AMD drivers too!
    Using the Set8087CW($133F); trick worked for me when I initialied the OpenGL context.

  6. #6
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Quote Originally Posted by BionicBytes View Post
    I had similar issues with odd releases of AMD drivers too!
    Using the Set8087CW($133F); trick worked for me when I initialied the OpenGL context.
    Yes, it is good when you can do it with your programming language.

    A SOLUTION IS FOUND.
    In VB6, go to project properties, click on compile tab.
    Press the Advanced Optimizations button.
    Click on Remove floating point exceptions check.

    I had already done this in my project but for some reason, my partner's VB6 did not have that checked.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •