Invert Value or however you want call it...

Share your advanced PureBasic knowledge/code with the community.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

42
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Lebostein wrote:

Code: Select all

result.l = val - (val+val)
result.l = val - val - val
result.l = 0 - val
result.l = -val
:roll:
Those are all you can think of? :lol: How about this?

Code: Select all

result.l = 4294967296 - num.l
result.l = num + 4294967296
horst
Enthusiast
Enthusiast
Posts: 197
Joined: Wed May 28, 2003 6:57 am
Location: Munich
Contact:

Post by horst »

Code: Select all

NEG val
Horst.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Code: Select all

NOT num
num + 1
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

horst wrote:

Code: Select all

NEG val
@horst:
thanks really cool to use direct ASM! I know there was such a command for 680x0 but i didnt remember its name nor how its named on x86! Thanks for sharing! 10points :wink:
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

Dare2 wrote:@Psychophanta,

Stop criticising and start contributing!

:P :D
Hehe... I kind off agree... :lol: but [thinking] then I have to contribute too... Well, I'll come up with something! :D
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

LOL
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Criticism is also a way to contribute :wink:
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 »

techjunkie wrote:.. but [thinking] then I have to contribute too... Well, I'll come up with something! :D
Shhhhhhh! Or I'll have to stop criticising and start contributing. :D

@Psychophanta:

I am really disappointed. Usually you respond with all guns blazing! :)
@}--`--,-- A rose by any other name ..
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Dare2 wrote:@Psychophanta:
I am really disappointed. Usually you respond with all guns blazing! :)
Bahh!, that's only a possible point of view, but you can be sure it's in any case, a susceptible and wrong point of view :)
My wish is guns to dissappear forever :wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Code: Select all

#ECSTATIC		=	$8000000
#PLASTIC		=	$4000000
#FANTASTIC	=	$2000000
#SURE				=	$0000333
#NOTSURE		=	$0666000

;***

Procedure.l lInvert_Value(lval.l, lflags.l)

	Protected FVAL_TO_CONVERT.f, FTEMP_RESULT.f, LFINAL_RESULT.l

	FVAL_TO_CONVERT.f=lval

	If lflags&#ECSTATIC=#ECSTATIC
		FTEMP_RESULT=-FVAL_TO_CONVERT
	EndIf

	If lflags&#PLASTIC=#PLASTIC
		FTEMP_RESULT=Sin(3.1416/2)*Cos(3.1416)*Sqr(1)*FVAL_TO_CONVERT
	EndIf

	If lflags&#FANTASTIC=#FANTASTIC
		;TOFIX : need to be rewritten by a senior programmer coz I had some bogz
		FTEMP_RESULT=ValF("-"+StrF(FVAL_TO_CONVERT+0.00000)+"0000")
	EndIf

	LFINAL_RESULT=FTEMP_RESULT

	If lflags&#NOTSURE=#NOTSURE
		ProcedureReturn LFINAL_RESULT*0
	EndIf

	If lflags&#NOTSURE=#SURE
		ProcedureReturn LFINAL_RESULT*0
	EndIf

	If lflags&#SURE=#NOTSURE
		ProcedureReturn LFINAL_RESULT*0
	EndIf

	If lflags&#SURE=#SURE
		ProcedureReturn LFINAL_RESULT
	EndIf

EndProcedure

;***

Debug lInvert_Value(24,#ECSTATIC|#SURE)			; returns	-24
Debug lInvert_Value(-318,#PLASTIC|#SURE)		; returns	318 
Debug lInvert_Value(-0,#FANTASTIC|#NOTSURE)	; returns		0 
End
:D



sad that tabs aren't supported by this forum :wink:
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

asm output code (/commented) :shock:

Code: Select all

; a = -a
  MOV    ebx,dword [v_a]
  NEG    ebx
  MOV    dword [v_a],ebx
working "inlined" asm code :!:

Code: Select all

a = 1
!NEG [v_a]
Debug a
I think "NEG a" is faster than using ebx but maybe i'm wrong... It may be optimized as "a + 1" becomes "INC a".

Dri :idea:
Fred
Administrator
Administrator
Posts: 18252
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

True, it can be easily optimized, i put it on the todo list
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

Fred wrote:True, it can be easily optimized, i put it on the todo list
:)
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

Fred wrote:True, it can be easily optimized, i put it on the todo list
:D

Dri ^^
Post Reply