d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Addition Isnt Really Addition
Add Reply New Topic New Poll
Member
Posts: 3,401
Joined: Feb 7 2011
Gold: 8,195.00
Jan 8 2019 08:56am
addition for any finite data types isnt closed because it overflows

so addition in code always ends up being addition mod n

and on top of that division isnt closed on integers so they just truncate it

thats why i love programming because it has that hacky polymorphic nature that says fuck you to high school algebra and says hello to the creativity of modern algebra

nothing from high school survives
Member
Posts: 12,703
Joined: May 17 2013
Gold: 12,935.00
Jan 8 2019 09:02am
Python says otherwise.

(just in case you think I'm not serious - python has arbitrary precision on integers, meaning operations don't over/underflow)

This post was edited by Klexmoo on Jan 8 2019 09:03am
Member
Posts: 3,401
Joined: Feb 7 2011
Gold: 8,195.00
Jan 8 2019 09:23am
Quote (Klexmoo @ Jan 8 2019 09:02am)
Python says otherwise.

(just in case you think I'm not serious - python has arbitrary precision on integers, meaning operations don't over/underflow)


this is fascinating, thank you for bringing this to my attention.

i found this page that goes in to depth on the subject (in a super clean and informative way too)
https://mortada.net/can-integer-operations-overflow-in-python.html

but i still standby my initial statement, because arbitrary precision doesnt fit in the category of "finite data types" it instead ends up being more like a string that can go up in size. really cool though.
Member
Posts: 12,703
Joined: May 17 2013
Gold: 12,935.00
Jan 8 2019 09:25am
Quote (otay @ 8 Jan 2019 16:23)
this is fascinating, thank you for bringing this to my attention.

i found this page that goes in to depth on the subject (in a super clean and informative way too)
https://mortada.net/can-integer-operations-overflow-in-python.html

but i still standby my initial statement, because arbitrary precision doesnt fit in the category of "finite data types" it instead ends up being more like a string that can go up in size. really cool though.


Yeah it's a bit hacky (in the sense that it's not really treated as a number) but cool :)
Member
Posts: 3,401
Joined: Feb 7 2011
Gold: 8,195.00
Jan 8 2019 09:31am
welp i guess the standard addition operation does survive through pythons arbitrary precision, dang i really wanted high school to be dead :D
Member
Posts: 12,703
Joined: May 17 2013
Gold: 12,935.00
Jan 8 2019 09:38am
Quote (otay @ 8 Jan 2019 16:31)
welp i guess the standard addition operation does survive through pythons arbitrary precision, dang i really wanted high school to be dead :D


It's hardly something used for performance reasons though. It uses up a lot of memory and is super slow compared to operations on 64 bit C integers like numpy uses.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll