gil icon indicating copy to clipboard operation
gil copied to clipboard

generate_gaussian_kernel and warning C4244: conversion from double to float

Open mloskot opened this issue 6 years ago • 2 comments

@simmplecoder Would it be possible to get rid of these warnings?

image_processing\numeric.hpp(104): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
image_processing\numeric.hpp(104): warning C4244: 'initializing': conversion from 'double' to 'const float', possible loss of data

Environment

  • Compiler version: _MSC_VER=1922

mloskot avatar Jul 31 '19 22:07 mloskot

I was thinking about making the argument a template, after adding boost::gil::gray64f_view_t and tests. Casting after making a template might suppress warnings that would otherwise be useful. Do other Boost libraries handle such issues?

simmplecoder avatar Aug 01 '19 03:08 simmplecoder

The questions are related to the issue #204 raised by @sdebionne


/cc @stefanseefeld

I think there are two choices at least:

  1. Use double as common type for results of arithmetic operations, then explicitly cast to expected result type. Preferably, with sprinkle of assertions checking the intermediate and final values are in expected range.

  2. Select most precise type at compile time. This approach is used in Boost.Geometry, see geometry::select_most_precise metafunction and how it is used in value_operation executor which is called like this:

    detail::value_operation<typename coordinate_type<Point>::type, std::divides>(value);
    

    I imagine, we could employ similar approach.

If we consider 2. to be a compelling idea, then we can leave this issue open and the current code (as reminder) until we have PR ready with gil::select_most_precise added and applied to channel and pixel arithmetic.

mloskot avatar Aug 01 '19 09:08 mloskot