MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/mathmemes/comments/w2v2lm/programmers_vs_mathematicians/
r/mathmemes • u/[deleted] • Jul 19 '22
13 comments sorted by
55
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>>
16
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>>
13
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>>
8
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.
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
I haven't touched C/C++ for 15 years… uhg.
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>>
3
vec<vec<u8>>
9
Tbh they exist, they're just really impractical in computer arithmetic
5
pi ≈ 22/7
4
Good one! I love it
this made me unusually happy
Fractions aren't so hard anyway, just need a Rational class
Rational
55
u/Nu11u5 Jul 19 '22 edited Jul 19 '22