开发者

big negative number - postive giving postivie only

I have temp2 value -52340.0 and hslColor.Lum开发者_Python百科inosity is 240.0

When Dim temp1 As Double = (hslColor.Luminosity - temp2). It shoud give -ve number but I am getting always positive number.

results should nbe -52100, but I am getting +52100. How to handle this?


240 - (-52340) = 52580

Do you remember what happens if you subtract a negative?


This is what you are doing:

Dim temp1 as Double = (240 - -52340.0)

You are subtracting a negative.


results should nbe -52100, but I am getting +52100.

That's a lie. You should be getting 52580, not 52100.

If you substitute the values in like this:

240 - -52340

You're subtracting a negative, so it's the same as adding a positive:

240 + 52340

Which equals 52580.


How to handle this?

To get the intended result of -52100, either use this if temp2 is always negative:

Dim temp1 As Double = (hslColor.Luminosity + temp2)

or use this, if you need to subtract the absolute value of temp2, whether it can be negative or positive:

Dim temp1 As Double = (hslColor.Luminosity - Math.Abs(temp2))


 Dim temp1 As Double = (240 - -52340)

the answer will be 52580

Dim temp1 As Double = (240 - 52340)

the answer will be -52100

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜