Email or username:

Password:

Forgot your password?
Devine Lu Linvega

There's this funny thing with fractions where, if you divide 2 by 3, getting 2/3, you can flip the numbers to get the reciprocal 3/2.

Now, while a division takes two whole numbers and gives you a fraction, there's no way to get back to two whole numbers again. It's destructive in a way, so I've added this little operator that is basically the opposite of a division, but that is also not a multiplication, taking the fraction 2/3, and giving you 2 and 3.

18 comments
eris

@neauoire i wonder if theres a fancy maths name for this ?

Devine Lu Linvega

@eris I've tried looking it up and I didn't find a name for it, in the docs I call it "yet unnamed operator", in the program I call it VID(mirror of DIV). I'd love to find the proper name for it, lemme know if you ever hear of one.

wiki.xxiivv.com/site/cccc.html

TsRoe

@neauoire @eris Maybe I don't understand the operator correctly, but doesn't it just basically return the reduction of the given fraction?
4/6 would return 2 3 too, right?

Devine Lu Linvega

@TsRoe @eris the reduction of 4/6 is 2/3 yes, the special operator gives you the two whole numbers.

TsRoe

@neauoire @eris Right, I guess what I'm trying to say is, that if someone where to define reduction as a mathematical function, they would have to define it like your operator. Meaning it would need something like this signature: Q -> (N, N) and not this one: Q -> Q. Because if they would choose the latter and define it such that reduce(4/6) = 2/3, they would just define the identity function, because 4/6 = 2/3.

Csepp 🌢

@neauoire What number representation is used here? It looks like the display format is integer part plus fraction. Are the individual component regular machine words or bignums?

Devine Lu Linvega

@csepp A mixed fraction is a whole number and a portion less than 1 together, like 2 3/4.

Csepp 🌢

@neauoire So that's what they are called. But what's the whole number in memory? Like, what's the biggest number it can represent, and what happens in case of an overflow?

Devine Lu Linvega

@csepp fractions are made of two shorts, it'll overflow after 65k

Csepp 🌢

@neauoire Thanks! Well, not ideal but I guess fine for a toy. UwU

Devine Lu Linvega

@csepp it's really rare that I noodling around with numbers higher than 60 thousands, but I might add a warning or something at some point if that starts bothering me.

nakst

@neauoire A few years ago I came up with a neat algorithm for this for a floating-point number, including support for expressions with square roots and multiples of pi. It works by trying to deduce a repeated fraction for the number (similar to how the golden ratio is constructed). The code is here: gist.github.com/nakst/f8a70fd6 I looked around the internet for a while to see if anyone had described this algorithm, but I couldn't find anything :(

R. L. Dane :debian: :openbsd:

@neauoire
I love how your UI design is coming along. It's starting to look really user-friendly. Kind of like an alternate reality where the first Mac had less RAM and two more colors. 😄
(And a much lighter OS)

Devine Lu Linvega

@RL_Dane I'm slowly walking through the eras of the past as I learn how to draw things more efficiently!

R. L. Dane :debian: :openbsd:

@neauoire
I wonder if anyone ever did a write-up of Bill Atkinson's LisaGraf/QuickDraw algorithms. Probably not... Proprietary, yay 😔

They were *incredibly* innovative.
He was the first to figure out how to redraw only the visible portion of a window, and his circle/oval/curve* algorithm was crazy efficient. I think he only needed to compute one eighth of the actual oval, and repeated the rest. Probably even more efficient for circles.

*QuickDraw curves were oval arcs, only.

@neauoire
I wonder if anyone ever did a write-up of Bill Atkinson's LisaGraf/QuickDraw algorithms. Probably not... Proprietary, yay 😔

They were *incredibly* innovative.
He was the first to figure out how to redraw only the visible portion of a window, and his circle/oval/curve* algorithm was crazy efficient. I think he only needed to compute one eighth of the actual oval, and repeated the rest. Probably even more efficient for circles.

Devine Lu Linvega

@RL_Dane I've implemented the oval bresenham-type algorithm in uxntal a little while ago :) It's pretty clever.

Go Up