Invert Value or however you want call it...

Share your advanced PureBasic knowledge/code with the community.
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Invert Value or however you want call it...

Post by va!n »

Code updated for 5.20+

i was asked how to set a positive value to a negative and backward... here is my small idea...

Code: Select all

Procedure InvertValue(val)
  ProcedureReturn val - (val+val)
EndProcedure

Debug InvertValue(24)      ; returns  -24
Debug InvertValue(-318)   ; returns   318
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

It works well but it is just 5 or 6 times slower than a = -a
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

fweil wrote:It works well but it is just 5 or 6 times slower than a = -a
ok, thanks :wink:
it was made in a real hurry for a friend...
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Va!n,
Sorry; With all my respects; i think these kind of tricks are too simple.
I'd add 'Beginners' word before the title of the thread, or a way to say the skill degree of the trick (tip) or something.
Just only my opinion :?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

@Psychophanta,

Stop criticising and start contributing!

:P :D
@}--`--,-- A rose by any other name ..
Fred
Administrator
Administrator
Posts: 18252
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Psychophanta wrote:Va!n,
Sorry; With all my respects; i think these kind of tricks are too simple.
I'd add 'Beginners' word before the title of the thread, or a way to say the skill degree of the trick (tip) or something.
Just only my opinion :?
+1 :)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

If you want to write really obfuscated code you can use this:

Code: Select all

a-a-a
:wink:
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

Dare2 wrote:@Psychophanta,

Stop criticising and start contributing!

:P :D
*thumb up*

YES !
Tranquil
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Psychopanta, you are forgetting an important point. Adding the word "beginner" to the post means one more word for the browser to process and that eats up valuable CPU time! :lol:
BERESHEIT
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

@netmaestro,

You mean that laziness means better CPU performances ?

I should beat 128bits CPUs planned for the next decade ...
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

:lol:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

I ever thought that clever people are lazy.

Just because lower eneergy comsuption means higher skills ...

Maybe you will notice that the shortest a philosophical sentence is, the largest signification it may have. It may, just ... pay if you want to know more. I am lazy, but if you pay I will explain you more.

Blue Screen !
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

fweil wrote:I ever thought that clever people are lazy.
Yes.
But that doesn't mean that lazy people are clever :D :P
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Psychophanta wrote:
fweil wrote:I ever thought that clever people are lazy.
Yes.
But that doesn't mean that lazy people are clever :D :P
Oh that's sad I was in heaven for a minute. :roll: :wink:
Lebostein
Addict
Addict
Posts: 830
Joined: Fri Jun 11, 2004 7:07 am

Post by Lebostein »

Code: Select all

result.l = val - (val+val)
result.l = val - val - val
result.l = 0 - val
result.l = -val
:roll:
Post Reply