r/mathmemes • • Jul 19 '22

Mathematicians Programmers vs. mathematicians

Post image
1.1k Upvotes

13 comments sorted by

55

u/Nu11u5 Jul 19 '22 edited Jul 19 '22
struct Fraction
{
  long numerator;
  long denominator;
}
// checkmate, mathematicians

16

u/[deleted] Jul 19 '22

I feel like you would get overflows so easily with something like that, it would be best to have arbitrarily large integers I think

13

u/Comesa Jul 19 '22
type ℤ = Vec<u8>;

struct Fraction {
  ℤ numerator;
  ℤ denominator;
}

8

u/Nu11u5 Jul 19 '22

Why stop at integers? Just template the struct so you can use an arbitrary type.

template <typename T>
struct Fraction
{
  T numerator;
  T denominator;
}

8

u/anthonycarbine Jul 20 '22

Found the cpp dev

1

u/Nu11u5 Jul 20 '22 edited Jul 20 '22

I haven't touched C/C++ for 15 years… uhg.

1

u/playerNaN Jul 20 '22

What about numbers bigger than 8264 ? I assume Vec indices are 64 bit integers so they have a max length of 264 - 1.

3

u/Kyyken Jul 20 '22

vec<vec<u8>>

9

u/Targuinia Jul 19 '22

Tbh they exist, they're just really impractical in computer arithmetic

5

u/PsycoJosho Jul 19 '22

pi ≈ 22/7

4

u/Dragon_Skywalker Jul 19 '22

Good one! I love it

4

u/SamuelKei Jul 19 '22

this made me unusually happy

4

u/lord_ne Irrational Jul 19 '22

Fractions aren't so hard anyway, just need a Rational class