From murdoch at stats.uwo.ca  Tue Dec 19 22:24:42 2006
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Tue, 19 Dec 2006 16:24:42 -0500
Subject: [Rd] precision when calling a C function;
 presence of Fortran call
In-Reply-To: <458856C1.3080600@stat.purdue.edu>
References: <4588363A.5050305@stat.purdue.edu> <45883BB5.5050806@stats.uwo.ca>
	<458856C1.3080600@stat.purdue.edu>
Message-ID: <4588589A.8020102@stats.uwo.ca>

On 12/19/2006 4:16 PM, Benjamin Tyner wrote:
> Thanks; I'm on 32-bit linux, but it's good to know the behavior on 
> Windows. Do you know a way to force "floor" to use this reduced precision?

Force the value to be stored to a "double" and it will get the reduced 
precision.  You can do this by assigning it to a numeric variable in R 
and then passing it back; you can presumably do it by some trickery in 
your compiler, but watch out for optimizations that leave it in an 80 
bit register the whole time.

Duncan Murdoch


> 
> Ben
> 
> Duncan Murdoch wrote:
>> On Windows, it's fairly common for runtime libraries to switch the 
>> precision from 80 bit to 64 bit.  R on Windows tries to guard against 
>> this, and on your test package, I get
>>
>> when f computed by R, C says 40 by itself
>> when f computed by R, C says 40, Fortran says 40
>> when f computed by C, C says 40 by itself
>> when f computed by C, C says 40, Fortran says 40
>>
>> It's possible that the floating point change is happening on your 
>> platform, or happened before you even got to this call.
>>
>> Here's code that works in Windows to detect such a change across a 
>> LoadLibrary call:
>>
>>     rcw = _controlfp(0,0) & ~_MCW_IC;  /* Infinity control is ignored */
>>     _clearfp();
>>     tdlh = LoadLibrary(path);
>>     dllcw = _controlfp(0,0) & ~_MCW_IC;
>>
>> No idea if _controlfp() exists on your system.
>>
>> Duncan Murdoch



[Rd] precision when calling a C function; presence of Fortran call
Duncan Murdoch