bug?: Abs(use '+' here)

Just starting out? Need help? Post your questions and find answers here.
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

bug?: Abs(use '+' here)

Post by gurj »

Code: Select all

; bug?: Abs(use '+' here)
; Syntax
; Result.f = Abs(Number.f)

a.q=-9223372036854775807
b.q=a+1
tem.q=Abs(b)
Debug tem;ok,9223372036854775806
tem.q=Abs(a+1)
Debug tem;wrong,-9223372036854775808
;i hope Abs(a+1)=Abs(b)
my pb for chinese:
http://ataorj.ys168.com
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: bug?: Abs(use '+' here)

Post by netmaestro »

Nothing to do with the +. Illegal usage of Abs(). Argument must be .f or .d and the precision doesn't hold for the full max value of a quad due to the internal representation of a .d variable requiring room for the decimal location. The function works fine if not overloaded:

Code: Select all

a.d=-922337203685477
b.d=a+1
tem1.q=Abs(b)
Debug tem1
tem2.q=Abs(a+1)
Debug tem2
Debug "Equality: "+Bool(tem1=tem2)
BERESHEIT
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: bug?: Abs(use '+' here)

Post by gurj »

thanks!
now,not use abs(),if a<0,a=-a
my pb for chinese:
http://ataorj.ys168.com
Post Reply