[vtk-developers] vtkMath::Ceil() and vtkMath::Floor()

Philippe Pébay pppebay at sandia.gov
Thu Jun 2 17:25:39 EDT 2011


Hello David,

Thanks for the prompt answer.

I still don't understand the double truncation for Floor() and Ceil(): why cast the readings to int first, and then to 
double again? I am not sure I understand what "exact results" mean in this contest, as the cast itself changes the 
nature of the representation, and a double cast does not, as far as I know at least, amount to an identity operation.

Or does it? Are you saying that static_cast<double>( static_cast<int>( x ) ) has always the exact same FP representation 
than x?

Thanks
Philippe

On 06/02/2011 02:20 PM, David Gobbi wrote:
> Hi Philippe,
>
> I wrote the Floor() and Ceil() functions a few months ago.  They are
> written specifically for speed.  For double values that are within the
> int range, they give exact results.
>
> The vtkMath::Round() is fast, too, but the operation that it performs
> does not conform to any of the IEEE 754 standard rounding modes.
>
>   - David
>
> On Thu, Jun 2, 2011 at 3:09 PM, Philippe Pébay<pppebay at sandia.gov>  wrote:
>> ... a clarification of what I asked earlier...
>>
>> By "different intent" I was referring to the fact that vtkMath's Floor() and
>> Ceil() perform something which I find a little intriguing, namely, casting a
>> double to an int, and then re-casting the latter to a double to perform a
>> double-double equality comparison, which, I would venture to say, should be
>> avoided whenever possible.
>>
>> On the other hand, Round() does not do this double casting but directly
>> performs double-double inequality comparison, and a single cast to an int at
>> the end. This seems much better to me.
>>
>> Thanks
>> Philippe
>>
>> On 06/02/2011 02:04 PM, Philippe Pébay wrote:
>>>
>>> Hello,
>>>
>>> I was contemplating using vtkMath::Ceil() and vtkMath::Floor() in some
>>> of my code, instead of the standard ceil() and floor(). However they
>>> appear to be written with a slightly different intent than
>>> vtkMath::Round(). Can someone comment on that?
>>>
>>> Thanks
>>> Philippe
>>
>>
>> --
>> Philippe Pébay
>> Sandia National Laboratories
>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtk-developers
>>
>>
>


-- 
Philippe Pébay
Sandia National Laboratories





More information about the vtk-developers mailing list