Calc can, but my code can't
-
After a user click, I am pulling a value from a control, converting this into a decimal value and relaying it to another control. The theory is correct, but I just cannot get my code to produce the correct value. This is the formula:
double dZoomFactor = 1 / ( 1 << ( 16 - dwId ) );
where dwId is an integer value between 1 and 16; In theory:dZoomFactor = 1 / ( 1 << ( 16 - 1 ) ); dZoomFactor = 1 / ( 1 << 15 ); dZoomFactor = 1 / 32768; dZoomFactor = 0.000030517578125;
But, the output is always a flat '0.0'. What am I missing?Waldermort
-
After a user click, I am pulling a value from a control, converting this into a decimal value and relaying it to another control. The theory is correct, but I just cannot get my code to produce the correct value. This is the formula:
double dZoomFactor = 1 / ( 1 << ( 16 - dwId ) );
where dwId is an integer value between 1 and 16; In theory:dZoomFactor = 1 / ( 1 << ( 16 - 1 ) ); dZoomFactor = 1 / ( 1 << 15 ); dZoomFactor = 1 / 32768; dZoomFactor = 0.000030517578125;
But, the output is always a flat '0.0'. What am I missing?Waldermort
-
That comes out as
3.0517578125000000e-005
. Wish I payed more attention to maths back in school. Right now I'm trying to find out what thate-005
means.Waldermort
-
That comes out as
3.0517578125000000e-005
. Wish I payed more attention to maths back in school. Right now I'm trying to find out what thate-005
means.Waldermort
WalderMight now I'm trying to find out what that e-005 means.
It means
10^-5
, i.e.3.0517578125000000e-005 = 0.000030517578125000000
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
WalderMight now I'm trying to find out what that e-005 means.
It means
10^-5
, i.e.3.0517578125000000e-005 = 0.000030517578125000000
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeThankyou thankyou thankyou. I have been on google for the last hour trying to find the meaning of that, but every page seems to think it's a universally understood system, kinda makes me feel stupid :sigh: Anyway, my code is now working. Thanks for the help guys :-D
Waldermort
-
After a user click, I am pulling a value from a control, converting this into a decimal value and relaying it to another control. The theory is correct, but I just cannot get my code to produce the correct value. This is the formula:
double dZoomFactor = 1 / ( 1 << ( 16 - dwId ) );
where dwId is an integer value between 1 and 16; In theory:dZoomFactor = 1 / ( 1 << ( 16 - 1 ) ); dZoomFactor = 1 / ( 1 << 15 ); dZoomFactor = 1 / 32768; dZoomFactor = 0.000030517578125;
But, the output is always a flat '0.0'. What am I missing?Waldermort
WalderMouble wrote:
dZoomFactor = 1 / ( 1 << ( 16 - dwId ) ); dZoomFactor = 1 / ( 1 << ( 16 - 1 ) ); dZoomFactor = 1 / ( 1 << 15 ); dZoomFactor = 1 / 32768; dZoomFactor = 0.000030517578125;
You should probably be using double constants (e.g.,
1.0
,16.0
), so that the math library is properly initialized. BTW, your name wreaks havoc in the Quote Selected Text feature. It inserts a malformed </b> tag."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
That comes out as
3.0517578125000000e-005
. Wish I payed more attention to maths back in school. Right now I'm trying to find out what thate-005
means.Waldermort
-
WalderMouble wrote:
dZoomFactor = 1 / ( 1 << ( 16 - dwId ) ); dZoomFactor = 1 / ( 1 << ( 16 - 1 ) ); dZoomFactor = 1 / ( 1 << 15 ); dZoomFactor = 1 / 32768; dZoomFactor = 0.000030517578125;
You should probably be using double constants (e.g.,
1.0
,16.0
), so that the math library is properly initialized. BTW, your name wreaks havoc in the Quote Selected Text feature. It inserts a malformed </b> tag."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
That's exactly what I was doing wrong, but that exponent was giving me a real headache, I thought the wrong values were coming out. I hate floating point maths!
Waldermort
-
Thanks for the link, but the 'great firewall of china' prevents me from accessing wikipedia :((
Waldermort