RGBConverter icon indicating copy to clipboard operation
RGBConverter copied to clipboard

Integer division rounding to zero in hue2rgb

Open bosquet opened this issue 9 years ago • 4 comments

Hi, I needed an HSL to RGB converter and was really excited to find this. However, when I started to use your library in my arduino project I kept getting grey values, as if my saturation was zero. After some digging I realized the cause of the issue was in the hue2rgb function in the cpp file - it would always fail the if statements with fractions and return p. This is because the integer division was rounding to zero. If you change the fractions from 1/2 to 1/2.0 this problem goes away and the converter works as it should!

bosquet avatar Mar 21 '15 22:03 bosquet

True, that is why I recommend to always add a "." after each number when you are working with floating point numbers so that stuff like this doesn't happen.

aleksandaratanasov avatar Sep 09 '15 20:09 aleksandaratanasov

Has this issue been resolved? I see https://github.com/ratkins/RGBConverter/blob/master/RGBConverter.cpp#L166 has a 1/2.0 instead of 1/2 so this fix has been incorporated?

Can this issue be closed?

abetusk avatar Jun 20 '19 17:06 abetusk

As noted in the main README I consider this abandoned. Feel free to fork your own and fix it there.

ratkins avatar Jun 20 '19 19:06 ratkins

OK, will do, thanks.

abetusk avatar Jun 20 '19 20:06 abetusk