lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Unit test for C99 round()


From: Greg Chicares
Subject: Re: [lmi] Unit test for C99 round()
Date: Thu, 05 Jun 2008 03:35:57 +0000
User-agent: Thunderbird 2.0.0.14 (Windows/20080421)

On 2008-06-04 19:30Z, Vadim Zeitlin wrote:
> On Wed, 04 Jun 2008 15:22:33 +0000 Greg Chicares <address@hidden> wrote:
[...]
> GC> If you change that thus:
> GC> -        return detail::perform_rint;
> GC> +        // EXPERIMENTALLY SKIPPED return detail::perform_rint;
> GC> to suppress that early exit (which should be a mere speed
> GC> optimization), then does everything work?
> 
>  Yes, indeed, thanks for localizing the problem!
> 
>  However I still don't really know what's going on: the function code looks
> to be correct:

[snip asm]

> however it returns "-0" instead of the expected "-1e-15" when rounding
> "-5.00000002e-16" to 15 decimals downwards (this is the first error).
> 
>  Does this give you any useful information or should I try to look into
> this closer myself?

The problem goes away if the 'detail::perform_rint' part is
suppressed, so either that function is misbehaving, or the
conditions under which it's called aren't as expected. Your
asm snippet suggests that that function does what it's
supposed to, so let's consider the other explanation.

Restoring some previous context, I had written:

| AIUI (but you shouldn't rely completely on my recollection),
| rint() or equivalent is called when the floating-point style
| is already set to the style desired: then it should just do
| the right thing, without incurring the overhead of changing
| the floating-point control word. It's hard to say more from
| here about what's happening on your machine, but we could
| instrument it more elaborately--for instance, to print out
| the actual and hoped-for control words.

Can you try that? Here's some copied (and trivially modified)
code to show the whole control word, if you want to use print
statements as your "debugger":

    std::ostringstream oss;
    oss
        << "The floating-point control word was '"
        << std::hex << std::internal << std::showbase << std::setfill('0')
#if defined LMI_X86
        << std::setw(6) << x87_control_word()
#else  // Unknown compiler or platform.
#   error Unknown compiler or platform.
#endif // Unknown compiler or platform.
        << "'."
        << "\n"
        ;

Or, with gdb, it's 'info float' IIRC.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]