integers

Blitz3D Forums/Blitz3D Programming/integers

Yue(Posted 2012) [#1]
You can convert a positive integer to a negative number?

Greetings.


Yasha(Posted 2012) [#2]
Can you give an example of the operation you want? A positive number isn't a negative number, more or less by definition...


Yue(Posted 2012) [#3]
I'm using the command TextureLodBias FASTEXT Draw3D2 and a slider, however this desilizador only use positive numbers and FASTEXT command receives positive and negative numbers, a positive value caliad degrades the image and a negative improvement, something like detail in distance.

TextureLodBias GetSelectSGG(Slider%)


Last edited 2012


Yasha(Posted 2012) [#4]
Subtract half of the maximum range of possible values?


Yue(Posted 2012) [#5]
Ok!
TextureLodBias GetSelectSGG(Slider%)-128.0


The problem I have is that I need a smaller range to manipulate and not how to implement it, putting the slider in position 128, I can go up to 128 and down to -128 in the negative, and I work ranges are -1 and 1 positive. and can not find the way to do it as the default desilizador has 255 in width for the data.

Last edited 2012


Kryzon(Posted 2012) [#6]
Use divisions.
TextureLodBias( (GetSelectSGG(Slider%)-128.0) / 127.0 )
This will transform the range [255 ~ 0] to [1.0 ~ -1.0].


Yue(Posted 2012) [#7]
@Kryzon Yasha Tnaks

Slider_LodBias% = AddingSGG(GUI_Graphics%,SGGSLIDER%,5,-80,"Detalle Distancia",1,45,128) ; 128 Start position Slider
TextureLodBias( (GetSelectSGG(Slider_LodBias%)-128.0) / 127.0 )


Definitely there is a solution for all.

Now the problem, and I think that is not such a problem, is that the image is degraded to the right of the slider, I think it should be the opposite, ie improve image when the slider is moved to the right and the move breaks down to the left, but I have this backwards. You can do something about it.?


steve_ancell(Posted 2012) [#8]
You do realise that if you want to quite literally flip the slider% variable on its head you can simply do it like this!.

slider = -slider

And the same statement will turn a negative number into a positive one. ;)

Last edited 2012


GfK(Posted 2012) [#9]
You do realise that if you want to quite literally flip the slider% variable on its head you can simply do it like this!.

slider = -slider
...which can be expanded to:
slider = 0 - slider

Programming is all about logic. I'll always maintain that if you don't have a naturally logical mind then programming isn't for you. But that's for another topic.


steve_ancell(Posted 2012) [#10]
I had a feeling you were going to step in Dave. ;)


steve_ancell(Posted 2012) [#11]
Isn't there also some way of doing it with bit shifting?. :-/

Or am I thinking of XOR?.

Last edited 2012


steve_ancell(Posted 2012) [#12]
I notice that -255 in binary is a lot different to 255. :-/

Last edited 2012


GfK(Posted 2012) [#13]
A 32-bit signed integer can hold values from -2,147,483,648 to 2,147,483,647 but it's important to note that 2147483647 + 1 will result in -2147483648, then -2147483647, and so on.

Whether it's possible to solve the original problem with bitshifting, I don't know. But even if you can, it's probably not worth the hassle and I doubt it would be any better than subtracting the original absolute value from zero.

Last edited 2012


Yasha(Posted 2012) [#14]
While it probably gets compiled to the same thing (not going to check), in op terms there is technically a difference between subtracting something from zero and the unary negation operator. Actually for my part I think using the operator by itself is more logical, but that may be a matter of taste.

As for using bit operations... "-x" is the same as "~x + 1". Why you would want to do this given that negation is a hardware instruction anyway, I don't know, but that's how.