Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
Thread Tools | Search this Thread | Display Modes |
4th February 2022, 00:08 | #1 | Link |
Registered User
Join Date: Mar 2012
Location: Texas
Posts: 1,666
|
Newbie questions regarding warnings and errors when compiling x64 plugins.
Hello all,
I'm creating this thread in hopes of asking some newbie questions when compiling existing plugins in x64. There's still some plugins that are x86 only (and not written in assembly). I'm hoping to compile what I can and put it up on the wiki so that they're available to everyone. I've compiled a few plugins already for personal use, and they all work but sometimes I get some warnings and/or errors that I do not know how to fix. For example ChannelMixer, it compiles and works but it shows 19 warnings in MSVC 2019. warning C4244: '=': conversion from 'double' to 'int', possible loss of data (9 WARNINGS) Code:
// Build look-up tables for(i = 0; i < 256; i++) { RR[i] = 0.01 * inRR * (float)i; RG[i] = 0.01 * inRG * (float)i; RB[i] = 0.01 * inRB * (float)i; GR[i] = 0.01 * inGR * (float)i; GG[i] = 0.01 * inGG * (float)i; GB[i] = 0.01 * inGB * (float)i; BR[i] = 0.01 * inBR * (float)i; BG[i] = 0.01 * inBG * (float)i; BB[i] = 0.01 * inBB * (float)i; Code:
int i, tmp; Code:
// Calls the constructor with the arguments provied. return new ChannelMixer(args[0].AsClip(), args[1].AsFloat(), args[2].AsFloat(), args[3].AsFloat(), args[4].AsFloat(), args[5].AsFloat(), args[6].AsFloat(), args[7].AsFloat(), args[8].AsFloat(), args[9].AsFloat(), env); Last edited by Reel.Deel; 4th February 2022 at 08:26. Reason: wrong warning in 1st example |
4th February 2022, 01:35 | #2 | Link | |||
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
Quote:
If any of the variables involved are double, then the whole result gets "upgraded" to a double. In this case, the literal "0.01" is treated as a double. You can force it to a float with an f suffix: Code:
RR[i] = 0.01f * inRR * (float)i; Code:
RR[i] = (float)(0.01 * inRR * i); Generally speaking though, this warning is safe to ignore. Quote:
Quote:
|
|||
4th February 2022, 07:59 | #3 | Link |
Registered User
Join Date: Mar 2012
Location: Texas
Posts: 1,666
|
Thanks for the information wonkey_monkey. Removing tmp and changing AsFloat() to AsFloatf() took care of those warnings.
I messed up and copied the wrong warning for the first example, my bad. The warning is warning C4244: '=': conversion from 'double' to 'int', possible loss of data instead of what I wrote in the 1st post. I tried both of your suggestions and I still get the same warning. |
4th February 2022, 08:37 | #4 | Link |
Registered User
Join Date: Jul 2018
Posts: 1,075
|
It looks the computation
0.01 * inRR * (float)i; is in double because 0.01 is defined as double and compiler raises precision to highest used component in formula. And RR[i] possibly int. So compiler warn - conversion of double formula calculation result to int output memory value. So to fix warning - make explicit conversion of computation result to int: RR[i] = (int)(0.01f * inRR * (float)i); Also use 0.01 as float32 that may make computing faster. I hope float32 is enough in that use case. |
|
|