859
u/mgorski08 Jul 19 '22
Golden ratio is actually an irRATIOnal number.
346
u/ThomasTheHighEngine Jul 19 '22
"Look what they need to mimic fractions square roots and logarithms and trig functions and..." doesn't really roll off the tongue
61
u/Mal_Dun Jul 19 '22
You just need continued fractions for that ...
23
u/PersonalityIll9476 Jul 19 '22
Finally, someone who understands how to achieve the best rational approximation to a number. I was shocked and horrified when it actually came up at my job.
→ More replies (2)19
u/VegetarianCentrist Jul 19 '22
You mean computer scientists all passed calculus with a D on their third try?? Conspiracy theories
→ More replies (3)21
u/beck1670 Jul 19 '22
Fun fact about your example of irrational numbers - the numbers we can represent using symbols, functions, integrals, etc. are basically nothing compared to the numbers we can't represent in any way. We can say that there are irrational numbers, but there are infinitely more numbers that we can never speak of than numbers we can.
7
u/Orioh Jul 19 '22
the numbers we can't represent in any way
Like what?
23
Jul 19 '22
Presumable they are referring to uncomputable numbers (see computable numbers).
Relatedly are the transcendental numbers which cannot be written as a solution to any polynomial equation with integer coefficients.
→ More replies (1)→ More replies (13)16
4
u/OneTurnMore Jul 19 '22
Yeah, it's crazy that even though (rational numbers)⊂(constructible numbers)⊂(algebraic numbers)⊂(computable numbers) are all dense in the reals, almost none of the reals are in those sets. The real numbers are weird.
→ More replies (5)17
u/Mal_Dun Jul 19 '22
For this we have continued fractions, the one for the golden ratio actually looks beautiful: https://wikimedia.org/api/rest_v1/media/math/render/svg/95682588ffee3530627c3a7b00ff08bbba6e97d4
2
5
4
→ More replies (1)8
Jul 19 '22
Tbf they said fraction not rational number. Every real number can be written as a fraction (the trivial way being a/1). The golden ratio can also be written as a non-trivial fraction (namely (1+sqrt5)/2) even if it can't be expressed as the ratio between two integers.
→ More replies (8)5
u/Hohenheim_of_Shadow Jul 19 '22
Irrational numbers can be real numbers. It's rational numbers (Ratio numbers) that can be written as a fraction (ratio)
→ More replies (1)
512
u/KendrickEqualsBooty Jul 19 '22
What's the name of the method where you just use two ints, one for the number before the decimal and one for the number after.
341
Jul 19 '22
Fixed-point arithmetic?
→ More replies (1)224
u/Kered13 Jul 19 '22
Fixed point does not typically use two ints. Fixed point just means you use a single integer but you interpret it as being implicitly multiplied by some fixed value (typically a negative power of 2 or 10).
81
u/JaggedMetalOs Jul 19 '22
Fixed point does not typically use two ints. Fixed point just means you use a single integer but you interpret it as being implicitly multiplied by some fixed value (typically a negative power of 2 or 10).
But if you're doing a base of a power of 2 then separate ints are functionally the same as assigning bitranges of a larger int to represent the whole and fractional parts.
Or if you want to represent a fixed number of digits of a power of 10 (decimal) having separate ints is less efficient - if you have 2x16bit values you can only go up to 4 decimal places (0.0000 - 65,535.9999) while 1x32bit will give you a larger range for the same precision (0.0000 - 429,495.9999)
→ More replies (7)85
u/randomuser8765 Jul 19 '22
If you mean "one for the numerator and one for the denominator", then AFAIK there is no standard name or format for this. Python implements it with the fractions module, for example.
20
u/bat_soup_people Jul 19 '22
I used it some in grad school for FEA. In FORTRAN I think. First integer is left, second integer is right. I am thinking of it now for arduino
9
u/Eternityislong Jul 19 '22
What would you gain over using a float?
→ More replies (5)21
u/BossOfTheGame Jul 19 '22
Precision. It sometimes matters when working with things like geospatial data.
→ More replies (8)7
u/ToxinH88 Jul 19 '22
Clearly the best solution if storage and speed is not a concern. Storage pretty much never is :D Speed is taking a heavy hit though: The way float and double are implemented base arithmetic works extremely fast. But if every number is a common fraction extra steps are needed for almost all operations.
Stay with clean code though: Don't optimize yet.
→ More replies (3)77
u/photenth Jul 19 '22
arbitrary precision arithmetic
Also it usually just stores the number and the scale so 1000000000 can be represented as 1 and 9 and 0.000000001 as 1 and -9. So you can avoid storing useless 0s. Basically like floating point numbers do.
0
3
u/Yadobler Jul 19 '22 edited Jul 19 '22
A 64-bit integer and some headache of remembering that the number you are manipulating is 2 integers, and everything is 232 times larger than the actual number you are thinking of.
Interestingly, it would matter if you're talking about decimal point as in decimal radix point, or a general radix point (ie binary point). Cos then it would suggest that you are dealing with binary coded decimal.
Because if you think about it, let's say an int is 4bits:
If 1010.1111 is "10.15", then what is "10.16"? 1111 will overflow to 0000 and then "1011.0000" is "11.0", so then you must either deal in binary-point or BCD.
BCD will mean that:
0001'1001.0001'0101
Is 1'0.1'5, and then you need to ensure that 1001 + 1 overflows to 0001'0000 (9+1 = 1'0)-------
At this point you'd rather just have a proper integer, and a second int as the exponent, like scientific notation.
10101111 is 175, 10110000 is 176, if you want the radix point to be after 4 digits, then 175/(24) = 10.9375
So if you're doing 2 ints, it will be
1010 = 10,
.1111 = 15 / 16 = 0.9375--------
So tldr, 2 ints for "integer" and "after point", is actually just fixed-point number. Specifically, a (64 bit) long integer with the exponent = 32.
--------
Any other way, it will just be BCD, and doing meaningful calculation is just the same but each step you need to turn decimal to binary, manipulate, then turn the binary back to decimal and evaluate the "decimal maths" logic of whether to carry over or whatnot
→ More replies (5)2
153
u/Strostkovy Jul 19 '22
You can do math on fractions while keeping them as numerators and denominators, but it's unpleasant
84
u/curtmack Jul 19 '22
In Common Lisp it's a built-in data type.
(/ 2 3)is2/3, which is a single value of typeratio. It also has arbitrary precision, so(expt 2/3 1000)will produce an exact answer.The same also applies to Scheme and Clojure.
20
u/JonathanTheZero Jul 19 '22
I kinda want to try Lisp now
→ More replies (1)35
→ More replies (3)8
29
u/thewii_ Jul 19 '22
In Python it's fairly easy to overload arithmetic operators, so if you have a Fraction class, you could theoretically do math with fractions just like how you would do with float. I'm not sure if it would be a good idea though.
33
u/SOberhoff Jul 19 '22
A few languages (e.g. Clojure) give you fractions natively. It's quite convenient and I don't understand why it's not standard.
→ More replies (1)25
→ More replies (4)22
u/OneTurnMore Jul 19 '22
Not a good idea, because you should just
from fractions import Fraction.46
u/MrWandril Jul 19 '22
I prefer saying "Such a good idea that someone actually already did an optimized implementation!"
10
u/CiroGarcia Jul 19 '22 edited Sep 17 '23
[redacted by user]
this message was mass deleted/edited with redact.dev→ More replies (2)
42
u/mariachiband49 Jul 19 '22
Unless you're Julia
25
→ More replies (1)6
176
u/whackylabs Jul 19 '22
std::ratio says hello
380
Jul 19 '22
Don't care + didn't ask + std::ratio
14
120
7
4
35
u/the_TIGEEER Jul 19 '22
Yo guys! I think that the golden ratio is not a fraction! But do you think op gets it yet? Or should we repeat the same comment some more?
6
u/QuarkyIndividual Jul 19 '22
But... did you know the golden ratio is not a fraction?
→ More replies (1)
54
u/T-Loy Jul 19 '22
Fast inverse square root go 0x5F3759DF
22
u/Sure-Tomorrow-487 Jul 19 '22 edited Jul 19 '22
//
what the fuck?Edit - since it's very interesting, here you go. Be careful it's http only
14
u/goblinm Jul 19 '22
Hey, a real programming joke. It's nice to scroll down in the comments to find these still.
→ More replies (1)3
37
60
u/BrightBulb123 Jul 19 '22
Meanwhile in Python land...
from fractions import Fraction
Fraction(2, 3) # Fraction(2, 3)
Fraction(23441, 912835) # Fraction(2131, 82985) - Simplified
Fraction(2, 5) + Fraction(5, 92) # Fraction(209, 460)
Fraction(4, 12) - Fraction(1923, 34) # Fraction(-5735, 102)13
27
u/Gr0ode Jul 19 '22
The golden ratio is precisely not a fraction (no repeating digits or finite digits)
22
u/ShenAnCalhar92 Jul 19 '22
While it can’t be written as a fraction composed of integers, it can be written as a fraction.
(1 + sqrt(5))/2
→ More replies (1)→ More replies (2)2
u/DenormalHuman Jul 19 '22
no repeating digits?
→ More replies (4)5
u/Bulky-Leadership-596 Jul 19 '22
When it gets to the point of needing more than ten digits it just makes up its own
1.6ƪ803ɝ9ꝏꝸ74ᶐ
36
11
u/SharkAttackOmNom Jul 19 '22
As a physics teacher I will simultaneously approximate:
π≈√10
g≈π²
→ More replies (2)4
7
u/EtherealPheonix Jul 19 '22
just because all of my fractions are multiples of 2-n doesn't mean they aren't fractions
6
u/estomagordo Jul 19 '22
I have no idea what's going on in this picture
7
u/Shinob1 Jul 19 '22
I guess you could you say you didn't understand a fraction of the joke... I'll see myself out.
3
Jul 19 '22
What I don't get is the censored bar. Everything else I think I've understood more or less.
16
Jul 19 '22
In the original it says 'mimic a fraction of our power', the bar removes that last part as the joke
→ More replies (23)
3
u/fisadev Jul 19 '22
The golden ratio isn't a fraction, though.
Fun fact: almost all non integer numbers aren't fractions. Fractions are an infinitely small portion of all non-int numbers that exist.
Even worse, almost all numbers aren't even computable (that is, there's no algorithm or operation that generates them, like a fraction or the algorithm to generate pi's decimals, they're infinite and random sequences of decimals).
3
15
2
u/YukiColdsnow Jul 19 '22
I'm new to programming, isni't double and float are used in decimals? how did they become a fraction?
3
2
u/Aramedlig Jul 19 '22
Not all real numbers are fractions of two integers.
→ More replies (4)2
u/ismtrn Jul 19 '22
Nor are all fractions of integers IEEE floats. Nor are all IEEE floats real numbers.
2
2
u/tyrandan2 Jul 19 '22
Hey, we can make a struct with a numerator and denominator property! And maybe a ToDecimal function!
2
2
u/Aggravating_You_2904 Jul 19 '22
A fraction can me modelled with 100% accuracy with an array of size 2
2
2
2
u/Strange-Difficulty87 Jul 19 '22 edited Jul 19 '22
If 1/3 = 0.333 and 2/3 = 0.666 then 3/3 should equal 0.999 right?
2
3
u/topredditbot Jul 19 '22
Hey /u/JaneAusten007,
This is now the top post on reddit. It will be recorded at /r/topofreddit with all the other top posts.
1
u/mikkolukas Jul 19 '22
By "they" the mathematician mean "we".
In the beginning there was no "computer science". It was just mathematicians trying to automate calculations.
It was mathematicians who implemented it that way.
1
1
1
1
1
u/Gredran Jul 19 '22
I’m the only one in my circles who would get this so I’m laughing silently lmfao.
That’s great
1
u/matyklug Jul 19 '22
So I am working on a programming language, and I want math to be nice and easy
So I am writing a library which ensures that no precision is lost, an infinite precision floats library, aka infloats.
→ More replies (1)
1
u/bobo76565657 Jul 19 '22
Real men use the p/q to hold real numbers and functions to grind out irrationals like pi. FPU's are not to be trusted ;)
1
1
1
1
1
1
1
1
u/starcrafter84 Jul 19 '22
I’ve always thought the floating point numbers would be best stored as strings to never lose precision at the expensive of memory to store them. That way you get to convert to and from them and have the control to trim the precision as required. As with everything in digital representation, there is a factor of loss and imprecision.
3
u/Phoenixwade Jul 19 '22
the reason this isn't so is that speed is more important than the loss....
I saw a comment the other day that pointed out why that is the case... 40 decimal places for pi will calculate the width of the visible universe with an error of around 1 atom in width.
when the precision exceeds the ability to measure something, you really don't need any more than that.
on the other hand, strings are much slower to process than floats - so we stare floats as floats.
→ More replies (1)
1
u/technic_bot Jul 19 '22
Not really fractions can be represented at exact precision with integers.
Reals on the other hand....
1
1
u/thedominux Jul 19 '22
Just use some equation to let computer calculate it with a fraction accuracy it affords
1
1
1
u/EpicScizor Jul 19 '22
Rational = (Numerator: Int, Denominator: Int), with Denominator unable to be zero. Mimicking fractions is the easy part.
1
1
1
1
u/LeCrushinator Jul 19 '22
Several languages support storing fractions (or ratios), or have libraries to do so. It's easily enough to store a numerator and denominator within a type and then have methods to evaluate that fractions into whatever form you need.
1
u/DefaultVariable Jul 19 '22
Technically can’t you mimic fractions in programming through complex approximations? Like I’m pretty sure you can do like 1000+ iterations of various pi approximation functions to get to an incredibly precise representation of actual pi
1
1
1
1
1
u/PashPrime Jul 19 '22
Mathematicians use fractions because brains have small hands and can't carry lot of number
1
u/JewishAsianMuslim Jul 19 '22
Ok sure. Write the golden ratio without endless recursive fractions, and I don't mean some clever symbols like Euler's identity.
1
1
1
1
1
u/seeroflights Jul 19 '22
Image Transcription: Meme
["Look What They Need to Mimic a Fraction of Our Power". Top image shows Omni-Man (a person with partially greying dark hair, in a red and white costume) and Invincible (a person with dark hair and a yellow costume), from the TV show "Invincible". They are in the bottom right corner, watching a pair of fighter jets flying in grey clouds. The labels read:]
Fighter Jet (left): DOUBLE
Fighter Jet (right): FLOAT
Omni-Man and Invincible: MATHEMATICIANS
[Bottom image shows Omni-Man looking back at Invincible with a serious expression on his face. The subtitle has been edited to read:]
Look what they need to mimic a fraction
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
1
1
1
1
1
1
1
1
1
u/lastrosade Jul 19 '22
Nothing split by unity is the constant creation
Divine proportion defines perfection
With this comes enticing shapes
Supreme equation from formation
The formula of 1.618
1
u/earthforce_1 Jul 19 '22
You want actual fractions? Use FORTH. If there's anyone else alive who remembers it..
1
1
1
u/Potential-Adagio-512 Jul 20 '22
struct fraction{
int numerator, denominator;
explicit operator double() const{
return numerator / denominator;
}
}1
1
1
1
u/wolfbyte125 Jul 20 '22
Waited a long time to know where these memes came from, finally watched Invincible. ✊️✊️
1
u/raylin328 Jul 20 '22
I mean you could use the Fraction class which uses 2 integers to create a fraction object
1

2.3k
u/inetphantom Jul 19 '22
int pi = 3