<HTML>
<style> BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }</style>If I may add a possible solution, would code akin to the following fix the problems? (Pray that the mail list formatting doesn't mess it all up!)<br>
<br>
----<br>
<br>
{$WARN 7121 off : Check size of memory operand "$1: memory-operand-size is $2 bits, but expected [$3 bits]"}<br>
{$ASMMODE Intel}<br>
<br>
const<br>
MAX_DOUBLE_WITH_FRAC: Double = 4503599627370496;<br>
SIGN_MASK: QWord = $7FFFFFFFFFFFFFFF;<br>
<br>
function SafeFrac(X: ValReal): ValReal; assembler; nostackframe;<br>
asm<br>
MOVSD XMM5, [RIP+SIGN_MASK]<br>
MOVSD XMM4, XMM0<br>
ANDPD XMM4, XMM5 { Remove sign bit }<br>
COMISD XMM4, [RIP+MAX_DOUBLE_WITH_FRAC] { If less than, then ZF = 0, PF = 0 and CF = 1}<br>
JNC @IsZero { If carry flag is clear, the absolute value is too<br>
large to contain a fractional component (and<br>
potentially too large to fit into RAX) }<br>
CVTTSD2SI RAX, XMM0<br>
CVTSI2SD XMM4, RAX<br>
SUBPD XMM0, XMM4<br>
RET<br>
@IsZero:<br>
XORPD XMM0, XMM0<br>
end;<br>
<br>
----<br>
<br>
The first MOVSD could be removed and simply be merged with ANDPD to save on a register, but I wrote it this way to take advantage of instruction prefetching and offer a slight speed boost.<br>
<br>
There is one minor functional change though... when testing this function, I discovered that if you try to pass infinity or minus infinity, the result is zero, whereas currently with Frac, it triggers SIGFPE.<br>
<br>
Gareth aka. Kit<br>
</HTML>