Log in

View Full Version : c++ math problem i don't understand


E-Male
15th July 2004, 13:17
i'm working on my first denoiser which turned out more difficult than i thought

after some strange errors i got down to this:

dstpY[x] = (srcpY[x] + srcpY[x])/2;
IMO that should output the input without changes
BUT it does not
sample pic (http://e-rels.dyndns.org/downloads/error.png)
code (http://e-rels.dyndns.org/downloads/error.cpp)

i hope one of the experienced programmers can show me the mistake i can't find myself

THX
E-Male

sh0dan
15th July 2004, 15:29
Since you are referring them as int64's, you get an overflow, when adding them. Consider this as bytes:

byte b1 = 200
byte final = (b1+b1)/2

b1+b1 will give you 400, which is bigger than the maximum value of a byte (which is 255), so the result will be wrong. The same happends with your int64's.

btw, you shouldn't use int64's in C, as it is very slow on 32bit computers.

E-Male
15th July 2004, 15:41
i just edited example plug-ins, so i thought the basic code structure would be fine and i just have to edit the parameters and the loops

i'll look into it