Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Excel is messing with the math coprocessor

I have just noticed that Excel is changing the floating
point round off handling in the math coprocessor for my
C++ and Fortran DLL. Has anyone run into this ? I am
getting ready to try venturing into _Control87 calls
when my DLL is called from Excel.

I have verified this problem in both Excel 2003 and 2010.

Thanks,
Lynn
  #2   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Excel is messing with the math coprocessor

Lynn McGuire was thinking very hard :
I have just noticed that Excel is changing the floating
point round off handling in the math coprocessor for my
C++ and Fortran DLL. Has anyone run into this ? I am
getting ready to try venturing into _Control87 calls
when my DLL is called from Excel.

I have verified this problem in both Excel 2003 and 2010.

Thanks,
Lynn


Excel has its own method of handling floating point rounding and so
expect it to be different compared to another methodology.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default Excel is messing with the math coprocessor

On 15/03/2012 16:16, Lynn McGuire wrote:
I have just noticed that Excel is changing the floating
point round off handling in the math coprocessor for my
C++ and Fortran DLL. Has anyone run into this ? I am


A long time ago and not specifically with Excel. It isn't safe to assume
inside a DLL that you will be handed the FPU in the state that your
compiler expects to find it. If your computation is sensitive to
rounding then you can get systematic errors introduced.

This sort of thing usually stems from rounding values for display. I
suspect Excel is setting the coprocessor to the state it requires and
that setting is not what Fortran and C++ compilers expect.

getting ready to try venturing into _Control87 calls
when my DLL is called from Excel.

I have verified this problem in both Excel 2003 and 2010.

Thanks,
Lynn


--
Regards,
Martin Brown
  #4   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 829
Default Excel is messing with the math coprocessor

"Lynn McGuire" wrote:
I have just noticed that Excel is changing the floating
point round off handling in the math coprocessor for my
C++ and Fortran DLL. Has anyone run into this ?


I do not use C++ or Fortran, but what you describe does not surprise me,
speaking as a computer and software architect.

The floating-point unit is a global resource. I would not expect any
application to save and restore the FPU's previous state before making
application-specific changes.

Instead, I would expect each application to set the FPU state as it requires
before using it.

So the fault is not Excel's.

Instead, I would expect C++ and Fortran to configure the FPU as each
language requires it, especially the floating-point rounding option.

Alternatively, perhaps your application should configure the FPU as you
require it.

  #5   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Excel is messing with the math coprocessor

On 3/15/2012 11:34 AM, joeu2004 wrote:
"Lynn McGuire" wrote:
I have just noticed that Excel is changing the floating
point round off handling in the math coprocessor for my
C++ and Fortran DLL. Has anyone run into this ?


I do not use C++ or Fortran, but what you describe does not surprise me, speaking as a computer and software architect.

The floating-point unit is a global resource. I would not expect any application to save and restore the FPU's previous state before
making application-specific changes.

Instead, I would expect each application to set the FPU state as it requires before using it.

So the fault is not Excel's.

Instead, I would expect C++ and Fortran to configure the FPU as each language requires it, especially the floating-point rounding
option.

Alternatively, perhaps your application should configure the FPU as you require it.


It looks like that I need to save the current state
of the FPU, reconfigure the FPU and set the FPU back
to the saved state at each entry point in my DLL.

Lynn




  #6   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 829
Default Excel is messing with the math coprocessor

"Lynn McGuire" wrote:
It looks like that I need to save the current state
of the FPU, reconfigure the FPU and set the FPU back
to the saved state at each entry point in my DLL.


I would think you only need to configure the FPU the way that you require
it, not save and restore the previous state.

As I said, I would expect each application to set up the FPU as it requires.
It really cannot assume that the FPU is in some "default" state, AFAIK.

(However, it is true that the FPU is in some well-known state at power-on.)

In any case, I would think you only need to program this once, then call the
procedure from each entry point -- at worst.

Alternatively, perhaps you can put the code into a single procedure that is
called when the DLL is loaded. I am not familiar with Windows DLLs. But it
is common practice in other architectures.

  #7   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Excel is messing with the math coprocessor

On 3/15/2012 7:23 PM, joeu2004 wrote:
"Lynn McGuire" wrote:
It looks like that I need to save the current state
of the FPU, reconfigure the FPU and set the FPU back
to the saved state at each entry point in my DLL.


I would think you only need to configure the FPU the way that you require it, not save and restore the previous state.

As I said, I would expect each application to set up the FPU as it requires. It really cannot assume that the FPU is in some
"default" state, AFAIK.

(However, it is true that the FPU is in some well-known state at power-on.)

In any case, I would think you only need to program this once, then call the procedure from each entry point -- at worst.

Alternatively, perhaps you can put the code into a single procedure that is called when the DLL is loaded. I am not familiar with
Windows DLLs. But it is common practice in other architectures.


The FPU is is the state 0x4000 every time my DLL
is called from Excel. I believe that 0x4000
means round up on the SSE2.

I am using the following code to reset the FPU in
my DLL:

unsigned checkMathCoprocessorStatus ()
{
unsigned old87Status = 0;
unsigned new87ControlWord = 0;
unsigned new87ControlMask = 0;
unsigned new87result = 0;

old87Status = _status87 ();
if (old87Status != 0)
{
char msg [4096];
sprintf (msg, "\nThe Math Coprocessor status is 0x%x, resetting to zero\n\n", old87Status);
writeLineToScreen (msg);
new87result = _control87 (new87ControlWord, new87ControlMask);
}

return old87Status;
}

Lynn
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using "Data - Group" Function in Excel Form w/o Messing Up Checkbo JOBrien77 Excel Discussion (Misc queries) 0 June 26th 09 09:32 PM
Excel spreadsheets messing up my decimal point Lobster Excel Discussion (Misc queries) 2 November 10th 07 08:14 AM
Messing Up on AutoFit John Quinn Excel Programming 6 July 8th 07 02:24 PM
Excel Vista Problem messing up how Excel Displays? [email protected] Excel Discussion (Misc queries) 4 April 4th 07 07:13 PM
Limit to number of named ranges before Excel starts messing things up? S Davis Excel Worksheet Functions 3 September 12th 06 08:07 PM


All times are GMT +1. The time now is 04:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"