Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Division Algorithm

Name: Anonymous 2018-10-21 13:04

How does one divide a by b, given there is not division operation (i.e. C64 or NES)?

So far I got the following algorithm:
def div(a,b):
if a < b: return 0
if b == 0: raise Exception('Division by zero.')
q = 1
t = a
while t>>1 >= b:
t >>= 1
q <<= 1
return q + div(a-q*b,b)


guess it is O(n), where n is the number of bits in a. But NES also has no multiplication opcode, so q*b will require O(log2(n)) additions. How does one implement it properly? How CPUs implement division?

Name: Anonymous 2018-10-21 13:33

Are we talking floating point division or floor division?

Name: Anonymous 2018-10-21 13:34

>>2
NES has FPU?

Name: Anonymous 2018-10-21 13:42

>>3
What's with the self-imposed hardware limitation?

Name: Anonymous 2018-10-21 13:47

C64 or NES
it's almost 2019 gramps

Name: Anonymous 2018-10-21 14:23

Name: Anonymous 2018-10-21 14:29

remember when ``divide by zero'' was a popular maymay on le imagereddits?

Name: Anonymous 2018-10-21 15:10

>>7
I’d rather not.

Name: Cudder !cXCudderUE 2018-10-21 18:44

Shift-and-subtract.

Name: Anonymous 2018-10-21 20:04

>>7
There is no way to sensibly define division by zero:
https://www.youtube.com/watch?v=J2z5uzqxJNU

Name: Anonymous 2018-10-22 1:21

use a lookup table

Name: Anonymous 2018-10-22 2:18

Just a tip: non-constant time division algorithms are trash.

if b == 0: raise Exception('Division by zero.')
Should have used dependent types instead.

Name: Anonymous 2018-10-22 2:39

>>12
Ok, legit, I want to know how you would program a dependent type on the MOS 6502.
You have full /prog/'s attention.

Name: Anonymous 2018-10-22 2:54

>>13
Dependent types are about type checking, you do not need any runtime support.

Name: Anonymous 2018-10-22 6:10

>>14
type check the division operation in MOS 6502 assembly, you autist.

Name: Anonymous 2018-10-22 6:24

haskal for NES

Name: Anonymous 2018-10-22 7:22

>>12
Addition, division, and multiplication are by their nature non-constant time. You can't produce N digits in O(1) time. The best known algorithm is still much slower than O(n):
https://en.wikipedia.org/wiki/Sch%C3%B6nhage%E2%80%93Strassen_algorithm

Name: Anonymous 2018-10-22 9:13

>>17
stop being a pedantic anus. addition, division and multiplication for n-bit integers can be constant time. they can't be for general-case bignums, but that's not what he was referring to and you know it

Name: Anonymous 2018-10-22 18:31

Name: Anonymous 2018-10-22 18:34

>>18
Aren't general-case bignums just n-bit integers?

Name: Anonymous 2018-10-22 19:06

some NES games had extra chips in the cartridges that could do multiplication

Name: Anonymous 2018-10-22 19:08

Name: Anonymous 2018-10-22 19:31

>>20
Only if they're are less than n-bits.

Name: Anonymous 2018-10-22 21:59

>>23
Integers (and rationals) are finite, so they are always less than n-bit (for a big enough n given n : nat).

Name: Anonymous 2018-10-22 22:14

>>24
Integers (and rationals) are finite
šŸ¤”

Name: Anonymous 2018-10-22 22:18

>>25
The set of integers (and rationals) is countably infinite, meaning that every element in them is finite. Unlike the set of real numbers which is uncountably infinite, meaning that some elements are of infinite length.

Name: Anonymous 2018-10-22 22:44

babby's first set theory

Name: Anonymous 2018-10-23 6:47

>>26
that's not what countable and uncountable infinity means, anus

Name: Anonymous 2018-10-23 6:54

>>28
huh?

Name: Anonymous 2018-10-23 7:05

>>29
what does 'infinite length' even mean? does it mean irrational numbers? if so, you can trivially construct a finite or countably infinite set of irrationals - e.g. a set which consists of integers multiplied by pi. that's still countable. or maybe you mean that its elements are sets of infinite length? that makes even less sense, and you can still trivially construct a countably infinite set of infinite sets - e.g. a set which contains sets of { { 1... āˆž }, {2 ... āˆž }, ... , { n ... āˆž }}

countably infinite sets don't have finite elements, they have finite continuous subsets (not even all subsets - a set of even integers is a subset of set of integers and it's still infinite). in other words, a countably infinite set will have a finite number of elements between two arbitrarily chosen elements - e.g. 'integers larger than 1 and smaller than 10'. in uncountably infinite sets, those subsets can be infinite - e.g. 'real numbers larger than 1 and smaller than 10'. an intuitive way of looking at that would be: if you pick a number from countably infinite set, you can easily point to next/previous number. in an uncountably infinite set, you can't because there's still infinite number of elements between 'current' and 'next'

Name: Anonymous 2018-10-23 10:26

>>28
infinity
Shalom!

Name: Anonymous 2018-10-23 18:15

>>30
That actually makes sense.

Name: Anonymous 2018-10-24 2:36

divide my dubs

Name: Anonymous 2018-10-24 6:29

>>32
it's really just basic set theory. go study it, it's one of the most fun things in math

Don't change these.
Name: Email:
Entire Thread Thread List