#Suggest better ways to deal with division

1 messages · Page 1 of 1 (latest)

hearty wharf
#

Ah actually that code has got a bug in it after all

hearty wharf
#

The bug fixed

hybrid shard
#
.byte = self.byte + @divFloor(self.bit, bitsInByte)
.bit = @mod(self.bit, bitsInByte)

sounds like you want this

hearty wharf
hybrid shard
#

floor rounds to negative infinity, yes

hearty wharf
#

Yeah, seems to be working

#

Thanks

#

So if it's negative, the division will always give me -1, minus what the positive division would give

hybrid shard
#

not necessarily

#

it gives you the most negative quotient

hearty wharf
#

I can't visualize that

hybrid shard
#

-8 / 8 = -1, -1 / 8 = -1, -9 / 8 = -2

#

the identity that matters here is (@divFloor(a, b) * b) + @mod(a, b) == a

hearty wharf
#

So that is an identity

#

I've seen that in the doc

#

But it's not clear that is an identity

#

It's given as example code

hybrid shard
#

it is example code

#

it's an example showing that a certain identity is true, a and b can be any value

hearty wharf
#

Well I'm saying that's not clear at all

#

It doesn't say that's a fact

#

and it doesn't say what a and b can be

#

... -- this is true for any valid a and b