Alban_T
#1
Hi,

I am writing a piece of code to convert RGB colours to HSL

Can anyone explain to my why the code below gives me 2 different results?

float _H;

float temp;

temp = 1/6 * (((_R - _G)/Delta) + 4);

_H = 0.1666667 * (((_R - _G)/Delta) + 4);

somehow the 1/6 is the problem... temp always returns 0. while _H returns the correct value :s

Arrch
#2
Alban:

Hi,

I am writing a piece of code to convert RGB colours to HSL

Can anyone explain to my why the code below gives me 2 different results?

float _H;

float temp;

temp = 1/6 * (((_R - _G)/Delta) + 4);

_H = 0.1666667 * (((_R - _G)/Delta) + 4);

somehow the 1/6 is the problemâ€¦ temp always returns 0. while _H returns the correct value :s

1/6 is 0 according to integer math.

Youâ€™re looking for 1.0/6.0

system
#3
```
temp = 1/6 * (((_R - _G)/Delta) + 4);
```

What result do you get when you divide 1 by 6? 0 with a remainder. The remainder is thrown away.

1.0/6.0 is a different story.