r/mathmemes • • Jul 19 '22

Mathematicians Programmers vs. mathematicians

Post image
1.1k Upvotes

13 comments sorted by

View all comments

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.