Author Topic: Small hiccup in ABS  (Read 5372 times)

0 Members and 1 Guest are viewing this topic.

FellippeHeitor

  • Guest
Re: Small hiccup in ABS
« Reply #15 on: January 04, 2022, 07:35:28 pm »
We're settled then ❤️

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Small hiccup in ABS
« Reply #16 on: January 04, 2022, 08:38:03 pm »
I would like to reiterate the points made above:
 - ABS's return type is the same as its argument, so you can't expect to get back a value that can't be represented in that width
 - The QB4.5 interpreter correctly gives an overflow error

And also note:
 - If you compile the program with Q4.5 and run the resulting binary you'll get the same behaviour experienced here (printing the most negative value), since compiled binaries don't have overflow checking.

With that all in mind I'm deeming this slightly surprising but not buggy behaviour.

so why does it not show the same behavior with integer64? the negative sign is removed in that case?
Granted after becoming radioactive I only have a half-life!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Small hiccup in ABS
« Reply #17 on: January 04, 2022, 08:40:04 pm »
We're settled then ❤️

not really, cause if that is expected behavior then ABS with INTEGER64 is broken.
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Small hiccup in ABS
« Reply #18 on: January 04, 2022, 09:10:19 pm »
I stand with Luke on that technicality.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Small hiccup in ABS
« Reply #19 on: January 04, 2022, 09:29:08 pm »
So be it.

The wiki has been updated to NOTE this limitation of ABS to save future users the headache.

You may double check my wording to make sure I have it correct.
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Small hiccup in ABS
« Reply #20 on: January 04, 2022, 10:02:12 pm »
Thanks for the wiki edit, it seems proper.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Small hiccup in ABS
« Reply #21 on: January 04, 2022, 11:19:13 pm »
Since we're bugward compatible, an easy user-function for this is:

FUNCTION Absolute## (x AS _FLOAT)
  Absolute## = SGN(x) * x
END FUNCTION
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Small hiccup in ABS
« Reply #22 on: January 05, 2022, 05:34:37 am »
Thanks everybody for clearing that up.

To the inveterate idiots of the community, it would not have occurred that ABS(-128) would ever be anything except 128, but now that you've explained that ABS() retains the variable type, we see that for a byte 128 -> -128.

You really shouldn't let technology loose on the unthinking!