Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

The Geniuses' Thread

Options
13468930

Comments

  • Moderators Posts: 8,678 ✭✭✭D4RK ONION


    Well, someone turned an 8 on it's side, I think that's about it really!


  • Registered Users Posts: 2,632 ✭✭✭SligoBrewer


    syncosised wrote: »
    zVT7D.gif

    Discuss.

    I could go on about it forever tbh.


  • Registered Users Posts: 806 ✭✭✭Niall09


    zVT7D.gif

    I'm in a happy mood tonight :)


  • Registered Users Posts: 4,586 ✭✭✭sock puppet


    syncosised wrote: »
    zVT7D.gif

    Discuss.

    After consulting my computer it turns out it's equal to 2^31-1.


  • Registered Users Posts: 4,944 ✭✭✭Jay P


    [latex]{e}^{pi \times i} = -1[/latex]

    Relevant? I think not, but it's a cool fact.


  • Advertisement
  • Closed Accounts Posts: 5,082 ✭✭✭Pygmalion


    After consulting my computer it turns out it's equal to 2^31-1.

    Someone who understands powers of 2, can you explain to me why the following:
    1 #include <iostream>
      2 
      3 using namespace std;
      4 
      5 int main()
      6 {
      7     unsigned long a;
      8     a = (1 << 31);
      9     cout << a << endl;
     10     cout << (a+1) << endl;
     11 }
    
    prints:
    18446744071562067968
    18446744071562067969
    

    and not
    2147483648
    2147483649
    
    as it should.

    Also compiler won't let me shift it more than 32-bits without setting a = 0, even though it's clearly a 64-bit int as the above shows...


  • Registered Users Posts: 708 ✭✭✭syncosised


    After consulting my computer it turns out it's equal to 2^31-1.
    Wouldn't it be 2^32 - 1? Infinity is so much bigger for those with 64-bit processors!
    Jay P wrote: »
    infinity isn't a number. It's not exactly definable.

    But yeah, dividing by zero isn't defined. It leads to all sorts of irregularities such as: don't know how the latex thingy works)
    2/0 = 3/0
    (Cancel zeros)]
    2 = 3

    I'm pretty sure I've proved myself wrong there...
    You know, I just thought, you could say infinity in itself is undefined, so we could all be right! Or wrong. :pac:


  • Closed Accounts Posts: 5,082 ✭✭✭Pygmalion


    syncosised wrote: »
    Wouldn't it be 2^32 - 1? Infinity is so much bigger for those with 64-bit processors!

    For a signed int 2^32-1, unsigned 2^31-1 (with a lower bound of -2^31 making the difference)


  • Registered Users Posts: 7,962 ✭✭✭jumpguy


    Jay P wrote: »
    [latex]{e}^{pi \times i} = 0[/latex]

    Relevant? I think not, but it's a cool fact.
    What constant is i? :confused:

    /pussy LC maths


  • Closed Accounts Posts: 5,082 ✭✭✭Pygmalion


    jumpguy wrote: »
    What constant is i? :confused:

    /pussy LC maths

    Square root of minus one (zOMG IMAGINARY NUMBERS), it's on LC syllabus but I think it was 6th year before I did it.


  • Advertisement
  • Registered Users Posts: 708 ✭✭✭syncosised


    Ah yes, good point! Your code is giving you 2^64, so you must be on a 64-bit processor. My C isn't terribly good though, so I'm not sure what's going on there, but if you want to pseudocode it up for me, I'd like to take a look!


  • Registered Users Posts: 7,962 ✭✭✭jumpguy


    Pygmalion wrote: »
    Square root of minus one (zOMG IMAGINARY NUMBERS), it's on LC syllabus but I think it was 6th year before I did it.
    Square root of...minus one?

    *rocks back and forth murmuring "no...no...no..."*


  • Closed Accounts Posts: 5,082 ✭✭✭Pygmalion


    syncosised wrote: »
    Ah yes, good point! Your code is giving you 2^64, so you must be on a 64-bit processor. My C isn't terribly good, so I'm not sure what's going on there, but if you want to pseudocode it up for me, I'd like to take a look!

    I am indeed on a 64-bit processor
    Well 1 << 31 means "shift left 31 times", AKA "multiply by 2^31 but way faster".

    Python gives the correct values:
    >>> 1 << 31
    2147483648
    >>> (1 << 31) + 1
    2147483649
    

    Incidentally the value it gives appears to be exactly equal to (1<<64 - 1<<31), which may indicate something but I'm not sure what.
    And all the values before 31 give the right answer, values higher give 0.


  • Registered Users Posts: 4,586 ✭✭✭sock puppet


    Pygmalion wrote: »
    Someone who understands powers of 2, can you explain to me why the following:
    1 #include <iostream>
      2 
      3 using namespace std;
      4 
      5 int main()
      6 {
      7     unsigned long a;
      8     a = (1 << 31);
      9     cout << a << endl;
     10     cout << (a+1) << endl;
     11 }
    
    prints:
    18446744071562067968
    18446744071562067969
    

    and not
    2147483648
    2147483649
    
    as it should.

    Also compiler won't let me shift it more than 32-bits without setting a = 0, even though it's clearly a 64-bit int as the above shows...

    I've no idea. We only do java and I've spent the last few minutes googling what the statements in your code do. Learning C is on my to-do list over the Summer.


  • Registered Users Posts: 4,944 ✭✭✭Jay P


    jumpguy wrote: »
    Square root of...minus one?

    *rocks back and forth murmuring "no...no...no..."*

    Tis a complex number, so it doesn't exist on the real number plane.

    i is generally defined as [latex]{i}^2 = -1[/latex], so the square root of minus on is equal to i.

    I remember it was easy enough when we did it in school.


  • Closed Accounts Posts: 5,082 ✭✭✭Pygmalion


    I've no idea. We only do java and I've spent the few minutes googling what the statements in your code do. Learning C is on my to-do list over the Summer.

    Well only important bits are a = (1 << 31) and the answer it prints (Which is wrong as it's almost 1 << 64), rest is just declaring variables and printing it.


  • Registered Users Posts: 708 ✭✭✭syncosised


    Maybe it's to do with the fact that you're using a long, not an int ...


  • Registered Users Posts: 4,944 ✭✭✭Jay P


    Pygmalion wrote: »
    I am indeed on a 64-bit processor
    Well 1 << 31 means "shift left 31 times", AKA "multiply by 2^31 but way faster".

    I know absolutely nothing about programming, so forgive if it sounds stupid, but is that something to do with binary or something?


  • Registered Users Posts: 708 ✭✭✭syncosised


    It certainly is! The shift left 31 times moves everything 31 places to the left and puts in 31 zeroes. In decimal it's like multiplying by 10^31, but in binary as you only have two possible digits, it's by 2^31.


  • Registered Users Posts: 1,269 ✭✭✭cocoa


    Pygmalion wrote: »
    Incidentally the value it gives appears to be exactly equal to (1<<64 - 1<<31), which may indicate something but I'm not sure what.
    And all the values before 31 give the right answer, values higher give 0.

    Just out of curiosity, how did you work that out? If you look at it in binary (which I suspect you did to figure that out...) you'll notice it's done it right for the first 32 bits, but it's set all of the other 32 bits. It's more than likely a compiler problem, or something to do with how long integers are handled by C (or is that C++), which is poorly. Have you tried just, shifting by 25, and then by a further 6?


  • Advertisement
  • Registered Users Posts: 4,586 ✭✭✭sock puppet


    Pygmalion wrote: »
    Well only important bits are a = (1 << 31) and the answer it prints (Which is wrong as it's almost 1 << 64), rest is just declaring variables and printing it.

    Ah I missed your later post. I've only really ever had to deal with ints so once I go beyond that I'm kind of lost.
    syncosised wrote: »
    Maybe it's to do with the fact that you're using a long, not an int ...

    But if he used an int, he wouldn't know if the answer was greater than the max value wouldn't he?

    edit: explained that poorly. I meant that it wouldn't solve his problem if he used ints would it not?


  • Registered Users Posts: 708 ✭✭✭syncosised


    On a 64-bit processor, the max int would be 2^64. Changing it probably wouldn't make a difference, I was just throwing out whatever I could think of.

    I think the problem is that a is never initialised. I'm going to say that C initialises it to 2^32 (all 1s), while Python initialises it to 0 (all 0s). So when you shift left in C, you get 64 1s, whereas in Python you get 32 0s followed by 32 1s. Or something like that.


  • Registered Users Posts: 7,962 ✭✭✭jumpguy


    Jay P wrote: »
    Tis a complex number, so it doesn't exist on the real number plane.

    i is generally defined as [latex]{i}^2 = -1[/latex], so the square root of minus on is equal to i.

    I remember it was easy enough when we did it in school.
    It's confusing cause I'm indoctined to believe any number squared is positive.

    I can't wait for my maths teacher to explain THIS one then! :P


  • Registered Users Posts: 4,586 ✭✭✭sock puppet


    syncosised wrote: »
    On a 64-bit processor, the max int would be 2^64. Changing it probably wouldn't make a difference, I was just throwing out whatever I could think of.

    Oh I didn't know that. Curse my outdated 32 bit system.


  • Registered Users Posts: 4,944 ✭✭✭Jay P


    jumpguy wrote: »
    It's confusing cause I'm indoctined to believe any number squared is positive.

    Yeah, that's exactly why it doesn't exist on the real number line. When we did it, we eased into it. Then when you start applying it to problems it begins to make sense.
    For example, the equation:
    [latex]{x}^2 + x + 1 = 0[/latex]
    doesn't have real roots. The roots of the equation are:
    x = -0.5 - 0.866025 i, x = -0.5 + 0.866025 i

    I'm turning into a teacher now so I'll leave it there.

    Test next week.


  • Closed Accounts Posts: 5,082 ✭✭✭Pygmalion


    I had a few replies typed out, but then I think I figured out why it happens.

    a is a 64-bit int (unsigned), but when it sees (1 << 31) it treats that as an int (signed), and assigns it the value -2147483648 (which is right for signed 32-bit integers).

    It THEN considers that a is an unsigned 64-bit int and assigns the 32-bit negative number to a positive 64-bit number, which is equal to taking it from 2^64.

    That really confused me for quite a while :P
    unsigned long a;
    a = 1;
    a <<= 31;
    
    works as expected :P.


  • Registered Users Posts: 708 ✭✭✭syncosised


    Hm, I guess that makes sense, sort of! :pac:


  • Closed Accounts Posts: 1,882 ✭✭✭phlegms


    I did pass maths for the leaving. Spent my days listening to my ipod and doing crosswords in class. It was awesome :pac:


  • Registered Users Posts: 4,944 ✭✭✭Jay P


    I'm doing doing my math modelling assignment, and it's really interesting. It's all about the predator-prey cycle between phage and bacteria. A few years ago some guy realised that the system didn't properly fit with the classical Lokta-Volterra system, so he made some changes and poof, it's there.

    Mathematical Modelling is actually really cool, it actually directly relates to real life, which makes it a bazillion time better than boring old calculus or linear algebra.



    Fúck me but maths is seriously awesome.


  • Advertisement
  • Closed Accounts Posts: 1,882 ✭✭✭phlegms


    Maths is ghey. History is where its at.

    The following video is immensely interesting. Basically, this guy was the last surviving veteran of one of the most horrific conflicts in modern history; The Boer War. If any of ye' have a few minutes, give the video a watch. Unfortunately because of the way History is taught in Ireland at the moment, if it isn't Fenians or Nazis you don't get to learn about it. Tis a crying shame because people like this will have their story all but forgotten about because of the Dept. of Education's choice to not give kids a decent understanding of Global History.



Advertisement