Is there any reason to have 1.0f/3.0f etc in resize.c?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Is there any reason to have 1.0f/3.0f etc in resize.c?

Post by NicolasRobidoux »

... when it goes into a MagickRealType?

Wouldn't it just be better to not have floats, but simply doubles (0.0 instead of 0.0f, 1.0 instead of 1.0f, 1.0/3.0 instead of 1.0f/3.0f etc)?
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Is there any reason to have 1.0f/3.0f etc in resize.c?

Post by NicolasRobidoux »

Actually, you don't find 1.0f/3.0f, you find 1.f/3.f.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Is there any reason to have 1.0f/3.0f etc in resize.c?

Post by NicolasRobidoux »

(Hopefully I understood what the code does: I am recovered FORTRAN programmer, so my structs ...)
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Is there any reason to have 1.0f/3.0f etc in resize.c?

Post by NicolasRobidoux »

More generally: Is there any reason to use floats in MagickRealType assignments?

E.g. value=1.0f in the Lagrange code.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Is there any reason to have 1.0f/3.0f etc in resize.c?

Post by magick »

We typically default to doubles unless its part of an array where we can save space with single precision rather than double.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Is there any reason to have 1.0f/3.0f etc in resize.c?

Post by anthony »

It is just the way I write it. The decimal point is the more important part, and the definition is in doubles. I suppose the 'f' is redundant. I will remove it.

The use of 1./3. is to implement the B,C value that is needed for make the CubicBC function
produce a Mitchell filter.

The only other unusual fractions is for Bessel, with the two numbers defining the support for a 3 lobed Bessel, and the size of the first lobe to use if you want to use Bessel as a windowing function,
specifically to generate a Bessel windowed Bessel or a cylindrical Lanczos

Basically that table maps filter names to actual function calls (weighted or window) defining the attributes of that function as a weighting function (support), windowing function (range to use for windowing purposes, typically 1.0), and the secondary arguments needed by some functions (B,C values for CubicBC).

That last however could be expanded to also provide other variables to functions, such as the pre-calculation of constants specific to that function definition.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply