Conquer Club

Comics

\\OFF-TOPIC// conversations about everything that has nothing to do with Conquer Club.

Moderator: Community Team

Forum rules
Please read the Community Guidelines before posting.

Re: Comics

Postby Haggis_McMutton on Fri Jul 27, 2012 2:07 pm

wiki wrote:Unique values with unexplained meaning or multiple occurrences which could (preferably) be replaced with named constants

That's what I meant.

Anyway, the magic number mentioned in the comic (0x5f375a86) refers to this: http://en.wikipedia.org/wiki/Fast_inverse_square_root

tl;dr version:
Computers can't do square root very fast. In fact it can be hundreds of times slower than addition/subtraction/multiplication.
Computer games need a shitload of square root calculations for physics simulation, and they need them FAST. Approximate methods are usually used.
At some point, years after the game was published, someone made public the inverse square root calculation method in Quake III Arena. The interesting bit is this: (also it has the original comments)
Code: Select all
i  = * ( long * ) &y;                       // evil floating point bit level hacking
i  = 0x5f3759df - ( i >> 1 );               // what the f*ck?
y  = * ( float * ) &i;

I can't really explain what's going on there, but besides the magic number poping out of nowhere, nothing really makes sense in those 3 lines. If you saw it without context you'd think it's some guy who just picked up a "Learn C in 20 days" book and is writing out gibberish.
However this method turns out to have been faster than any other method known at the time(maybe it still is, I dunno). Also no one knows exactly where the code originates. Judging from the comments it's pretty clear the Quake guys didn't write it themselves.

tl;dr tl;dr
0x5f3759df is magic yo. Aliens probably did it.
Highest score: 3063; Highest position: 67;
Winner of {World War II tournament, -team 2010 Skilled Diversity, [FuN||Chewy]-[XII] USA};
8-3-7
User avatar
Major Haggis_McMutton
 
Posts: 403
Joined: Sun Mar 26, 2006 11:32 am

Re: Comics

Postby BigBallinStalin on Fri Jul 27, 2012 3:02 pm

Cool. Thanks! That makes a lot more sense, but I still suspect that aliens were involved.
User avatar
Major BigBallinStalin
 
Posts: 5151
Joined: Sun Oct 26, 2008 10:23 pm
Location: crying into the dregs of an empty bottle of own-brand scotch on the toilet having a dump in Dagenham

Re: Comics

Postby Haggis_McMutton on Fri Jul 27, 2012 3:18 pm

Image
Image

Edit:
Actually, I was just wondering how one comes up with realistic looking math nonsense for the blackboard and started looking at the equations.
First one is totally based on Bayes Theorem (probably). BOOYAH +1 to nerd cred.
Highest score: 3063; Highest position: 67;
Winner of {World War II tournament, -team 2010 Skilled Diversity, [FuN||Chewy]-[XII] USA};
8-3-7
User avatar
Major Haggis_McMutton
 
Posts: 403
Joined: Sun Mar 26, 2006 11:32 am

Re: Comics

Postby natty dread on Fri Jul 27, 2012 5:20 pm

Click image to enlarge.
image
Image
User avatar
Sergeant 1st Class natty dread
 
Posts: 12877
Joined: Fri Feb 08, 2008 8:58 pm
Location: just plain fucked

Re: Comics

Postby MeDeFe on Fri Jul 27, 2012 5:41 pm

natty dread wrote:I like most meats, but I have this crazy aversion towards liver. I just can't stand the stuff.

Haggis_McMutton wrote:Actually I could never stand liver either. I even hate the smell.

Huh. And liver was my favourite meat before I went vegetarian. With lingonberry jam and grated carrots... It would have been heavenly, if there were such a thing.
saxitoxin wrote:Your position is more complex than the federal tax code. As soon as I think I understand it, I find another index of cross-references, exceptions and amendments I have to apply.
Timminz wrote:Yo mama is so classless, she could be a Marxist utopia.
User avatar
Major MeDeFe
 
Posts: 7831
Joined: Thu Apr 06, 2006 2:48 am
Location: Follow the trail of holes in other people's arguments.

Re: Comics

Postby natty dread on Fri Jul 27, 2012 5:49 pm

Haggis_McMutton wrote:I can't really explain what's going on there, but besides the magic number poping out of nowhere, nothing really makes sense in those 3 lines. If you saw it without context you'd think it's some guy who just picked up a "Learn C in 20 days" book and is writing out gibberish.
However this method turns out to have been faster than any other method known at the time(maybe it still is, I dunno). Also no one knows exactly where the code originates. Judging from the comments it's pretty clear the Quake guys didn't write it themselves.

tl;dr tl;dr
0x5f3759df is magic yo. Aliens probably did it.


As far as I can tell (and please take all this with a grain of salt), the floating point number is being "directly" converted into an integer by abusing pointers. Then, some weird binary magic is done on the number, then it's converted back to a float. By directly I mean the bits are simply moved from the floating point number to the integer, no actual "conversion" is really taking place.

In the "binary magic" part, apparently first the faux-integer is shifted to the right by 1 bit. Now, usually this would simply halve the integer, but since the integer is actually a float masquerading as an integer, this apparently does some funky stuff that I don't quite understand - it halves both the exponent and the fraction of the float, assuming it's a positive number, and the exponent is even - if the exponent is odd then the last bit of the exponent is shifted over to the fraction side. Ok...

So then, this resulting number is substracted from the magic number, and the result of this is converted back to float.

I still don't really understand the math behind this, I just (maybe, partially) understand how the programming side works... no idea how this is supposed to give a inverse square root or something. f*ck, I'm not 100% on what an inverse square root even is.
Image
User avatar
Sergeant 1st Class natty dread
 
Posts: 12877
Joined: Fri Feb 08, 2008 8:58 pm
Location: just plain fucked

Re: Comics

Postby ender516 on Sat Jul 28, 2012 3:17 pm

Well, from the reading I did on the matter, the inverse square root is actually what I would call the reciprocal of the square root: 1 divided by the square root, or x to the power of negative one-half. The value obtained by that crazy code is not the correct value, but apparently makes an excellent guess, which is corrected by Newton's approximation method, which basically takes an answer to a problem and runs it through the inverse function to see if it's right and uses the error to construct another guess (which hopefully is closer to the truth). A lot of fancy math in computers use Newton. Some functions converge to the right answer faster than others, but often the key is making a good first guess.
User avatar
Sergeant 1st Class ender516
 
Posts: 4455
Joined: Wed Dec 17, 2008 6:07 pm
Location: Waterloo, Ontario

Re: Comics

Postby Army of GOD on Sat Jul 28, 2012 11:36 pm

I've taken two classes in C++ and I still don't understand why pointers exist. Then again, that's probably because they were introductory classes so I wouldn't have NEEDED them but still.
mrswdk is a ho
User avatar
Lieutenant Army of GOD
 
Posts: 7189
Joined: Tue Feb 24, 2009 4:30 pm

Re: Comics

Postby ender516 on Sun Jul 29, 2012 12:47 am

I'm off to my first official training in C++ starting in just over a week, but my guess is they exist in C++ because they existed in C and no one was sure that they could live without them.
User avatar
Sergeant 1st Class ender516
 
Posts: 4455
Joined: Wed Dec 17, 2008 6:07 pm
Location: Waterloo, Ontario

Re: Comics

Postby Army of GOD on Sun Jul 29, 2012 2:53 am

this is in reference to the cartoon Avater, not the movie:

Image
mrswdk is a ho
User avatar
Lieutenant Army of GOD
 
Posts: 7189
Joined: Tue Feb 24, 2009 4:30 pm

Re: Comics

Postby natty dread on Sun Jul 29, 2012 7:05 am

Army of GOD wrote:I've taken two classes in C++ and I still don't understand why pointers exist. Then again, that's probably because they were introductory classes so I wouldn't have NEEDED them but still.


Pointers point to locations in the memory. You can store variables in memory locations and pointers help you find them afterwards.
Image
User avatar
Sergeant 1st Class natty dread
 
Posts: 12877
Joined: Fri Feb 08, 2008 8:58 pm
Location: just plain fucked

Re: Comics

Postby natty dread on Sun Jul 29, 2012 9:52 am

This might explain things

Click image to enlarge.
image
Image
User avatar
Sergeant 1st Class natty dread
 
Posts: 12877
Joined: Fri Feb 08, 2008 8:58 pm
Location: just plain fucked

Re: Comics

Postby natty dread on Sun Jul 29, 2012 6:29 pm

Click image to enlarge.
image
Image
User avatar
Sergeant 1st Class natty dread
 
Posts: 12877
Joined: Fri Feb 08, 2008 8:58 pm
Location: just plain fucked

Re: Comics

Postby Haggis_McMutton on Sun Jul 29, 2012 6:34 pm

natty dread wrote:As far as I can tell (and please take all this with a grain of salt), the floating point number is being "directly" converted into an integer by abusing pointers. Then, some weird binary magic is done on the number, then it's converted back to a float. By directly I mean the bits are simply moved from the floating point number to the integer, no actual "conversion" is really taking place.

In the "binary magic" part, apparently first the faux-integer is shifted to the right by 1 bit. Now, usually this would simply halve the integer, but since the integer is actually a float masquerading as an integer, this apparently does some funky stuff that I don't quite understand - it halves both the exponent and the fraction of the float, assuming it's a positive number, and the exponent is even - if the exponent is odd then the last bit of the exponent is shifted over to the fraction side. Ok...

So then, this resulting number is substracted from the magic number, and the result of this is converted back to float.

I still don't really understand the math behind this, I just (maybe, partially) understand how the programming side works... no idea how this is supposed to give a inverse square root or something. f*ck, I'm not 100% on what an inverse square root even is.


Hmm, yeah, It's really crazy. It definitely looks like a rookie mistake when you first see it, with the nonsensical casts.
It probably says something about C that it is even possible to do that. I don't think it would be possible in any other major modern language.

Also, I read thjat someone did a brute force search to get the best constant for the magic number, and the one that was used is apparently second best, with the 0x5f375a86 actually mentioned in the comic being better.

Also, today's SMBC:
Click image to enlarge.
image
Highest score: 3063; Highest position: 67;
Winner of {World War II tournament, -team 2010 Skilled Diversity, [FuN||Chewy]-[XII] USA};
8-3-7
User avatar
Major Haggis_McMutton
 
Posts: 403
Joined: Sun Mar 26, 2006 11:32 am

Re: Comics

Postby natty dread on Mon Jul 30, 2012 2:10 am

Click image to enlarge.
image


Click image to enlarge.
image
Last edited by natty dread on Mon Jul 30, 2012 2:51 am, edited 1 time in total.
Image
User avatar
Sergeant 1st Class natty dread
 
Posts: 12877
Joined: Fri Feb 08, 2008 8:58 pm
Location: just plain fucked

Re: Comics

Postby natty dread on Mon Jul 30, 2012 2:23 am

Haggis_McMutton wrote:It probably says something about C that it is even possible to do that. I don't think it would be possible in any other major modern language.


Oh, that's not true. It's quite possible in any low-level programming language (ie. language that compiles directly to machine code), which allows direct manipulation of memory locations - that is, almost any language that allows the use of pointers. Also, any language that allows inline assembler, since everything is obviously possible in assembler.

C++, C#, D, Objective-C should all be able to do it. I'm sure many others can as well.
Image
User avatar
Sergeant 1st Class natty dread
 
Posts: 12877
Joined: Fri Feb 08, 2008 8:58 pm
Location: just plain fucked

Re: Comics

Postby Haggis_McMutton on Mon Jul 30, 2012 9:43 am

natty dread wrote:
Haggis_McMutton wrote:It probably says something about C that it is even possible to do that. I don't think it would be possible in any other major modern language.


Oh, that's not true. It's quite possible in any low-level programming language (ie. language that compiles directly to machine code), which allows direct manipulation of memory locations - that is, almost any language that allows the use of pointers. Also, any language that allows inline assembler, since everything is obviously possible in assembler.

C++, C#, D, Objective-C should all be able to do it. I'm sure many others can as well.


Yeah, sure, but I kind of view those as derivatives of C.

I was thinking more in the lines of python, ruby, scheme, any functional language obviously.
I'm not even sure if it's possible in Java.

Basically you need explicit pointers and lax type safety, I think.
Highest score: 3063; Highest position: 67;
Winner of {World War II tournament, -team 2010 Skilled Diversity, [FuN||Chewy]-[XII] USA};
8-3-7
User avatar
Major Haggis_McMutton
 
Posts: 403
Joined: Sun Mar 26, 2006 11:32 am

Re: Comics

Postby natty dread on Mon Jul 30, 2012 10:17 am

Haggis_McMutton wrote:
natty dread wrote:
Haggis_McMutton wrote:It probably says something about C that it is even possible to do that. I don't think it would be possible in any other major modern language.


Oh, that's not true. It's quite possible in any low-level programming language (ie. language that compiles directly to machine code), which allows direct manipulation of memory locations - that is, almost any language that allows the use of pointers. Also, any language that allows inline assembler, since everything is obviously possible in assembler.

C++, C#, D, Objective-C should all be able to do it. I'm sure many others can as well.


Yeah, sure, but I kind of view those as derivatives of C.

I was thinking more in the lines of python, ruby, scheme, any functional language obviously.
I'm not even sure if it's possible in Java.

Basically you need explicit pointers and lax type safety, I think.


Well, obviously you can't do it in higher-level interpreted languages. Java, Python, Ruby and such are all languages which don't compile into machine code, they instead compile the source into a bytecode which runs in their own language-specific virtual machines. So of course you can't directly manipulate memory locations in those languages, since all data and code are virtualized and the languages don't allow direct access to the system.

This doesn't mean those languages are less useful though, it just means they are designed for a different purpose. Making the code run on a virtual machine makes it easier to code cross-platform implementations, since the programmer doesn't have to worry about the low-level hardware stuff. It also makes the languages more useful for scripting purposes.

However, interpreted languages aren't very suitable for uses that require very efficient usage of system resources, such as graphics engines for games or such.

C# is an "interesting" exception - it's a bit of both, and depending on your point of view, it either has the advantages or the disadvantages of both types... basically, it's an interpreted language, but it doesn't run on a virtual machine, instead the code is compiled at run-time to machine code. It's called "just-in-time compiling". C# allows the use of pointers, but only in code blocks which are explicitly marked as "unsafe".
Image
User avatar
Sergeant 1st Class natty dread
 
Posts: 12877
Joined: Fri Feb 08, 2008 8:58 pm
Location: just plain fucked

Re: Comics

Postby Gillipig on Mon Jul 30, 2012 10:51 am

Sorry if any of these are re posts.

Image

Image

Image
AoG for President of the World!!
I promise he will put George W. Bush to shame!
User avatar
Lieutenant Gillipig
 
Posts: 3565
Joined: Fri Jan 09, 2009 1:24 pm

Re: Comics

Postby Haggis_McMutton on Mon Jul 30, 2012 11:56 am

natty dread wrote:Well, obviously you can't do it in higher-level interpreted languages. Java, Python, Ruby and such are all languages which don't compile into machine code, they instead compile the source into a bytecode which runs in their own language-specific virtual machines. So of course you can't directly manipulate memory locations in those languages, since all data and code are virtualized and the languages don't allow direct access to the system.

This doesn't mean those languages are less useful though, it just means they are designed for a different purpose. Making the code run on a virtual machine makes it easier to code cross-platform implementations, since the programmer doesn't have to worry about the low-level hardware stuff. It also makes the languages more useful for scripting purposes.

However, interpreted languages aren't very suitable for uses that require very efficient usage of system resources, such as graphics engines for games or such.

C# is an "interesting" exception - it's a bit of both, and depending on your point of view, it either has the advantages or the disadvantages of both types... basically, it's an interpreted language, but it doesn't run on a virtual machine, instead the code is compiled at run-time to machine code. It's called "just-in-time compiling". C# allows the use of pointers, but only in code blocks which are explicitly marked as "unsafe".


Turns out you can actually do it in Java, huh: http://stackoverflow.com/questions/11513344/how-to-implement-the-fast-inverse-square-root-in-java

Yeah, I know about the JVM, I wasn't implying C is better because it lets you do that stuff, rather I think it's worse for most applications. Yeah, there are a handfull of applications where you really have to get down to the metal and squeeze every last bit of performance, but it seems to me that the vast majority of stuff written in C/C++ would work just as well in python and would be more readable and more easily maintainable.

Interesting about C#, I didn't know that.

Also:
Image
Image
Highest score: 3063; Highest position: 67;
Winner of {World War II tournament, -team 2010 Skilled Diversity, [FuN||Chewy]-[XII] USA};
8-3-7
User avatar
Major Haggis_McMutton
 
Posts: 403
Joined: Sun Mar 26, 2006 11:32 am

Re: Comics

Postby natty dread on Mon Jul 30, 2012 1:10 pm

Haggis_McMutton wrote:Turns out you can actually do it in Java, huh:


Yes, but not by the same method - instead there are built-in methods in the Java primitives which allow this kind of conversion.

I'm sure you can do it in Python too (it's pretty damn versatile for an interpreted language), but not by directly manipulating memory locations with pointers.

Haggis_McMutton wrote:Yeah, I know about the JVM, I wasn't implying C is better because it lets you do that stuff, rather I think it's worse for most applications. Yeah, there are a handfull of applications where you really have to get down to the metal and squeeze every last bit of performance, but it seems to me that the vast majority of stuff written in C/C++ would work just as well in python and would be more readable and more easily maintainable.


Well, I think the trend these days is to use some combination of a low-level language + high-level language. Often, back-ends are written with a low-level language, whereas high-level languages are used for interfaces and front-ends, also scripting.

However there are plenty of applications where low-level languages are still necessary, and I don't think they're going to go anywhere for a while. Operating systems, compilers, hardware drivers, etc. all require lower-level languages for coding. Maybe in the future we'll have computers with such ridiculous performance that the distinction becomes moot, but so far this isn't the case.
Image
User avatar
Sergeant 1st Class natty dread
 
Posts: 12877
Joined: Fri Feb 08, 2008 8:58 pm
Location: just plain fucked

Re: Comics

Postby Army of GOD on Mon Jul 30, 2012 1:23 pm

Haggis_McMutton wrote:
Click image to enlarge.
image


This comic, like many smbcs, has the same problem of adding extra frames. If they end it during the dog's "NOOOO!" I think it wouldbe a lot more funnier than the actual punchline.
mrswdk is a ho
User avatar
Lieutenant Army of GOD
 
Posts: 7189
Joined: Tue Feb 24, 2009 4:30 pm

Re: Comics

Postby Haggis_McMutton on Mon Jul 30, 2012 2:10 pm

natty dread wrote:I'm sure you can do it in Python too (it's pretty damn versatile for an interpreted language), but not by directly manipulating memory locations with pointers.

I guess you could just embed the C in Python anyway, should be possible, though I've never actually done it.

Haggis_McMutton wrote:Well, I think the trend these days is to use some combination of a low-level language + high-level language. Often, back-ends are written with a low-level language, whereas high-level languages are used for interfaces and front-ends, also scripting.

However there are plenty of applications where low-level languages are still necessary, and I don't think they're going to go anywhere for a while. Operating systems, compilers, hardware drivers, etc. all require lower-level languages for coding. Maybe in the future we'll have computers with such ridiculous performance that the distinction becomes moot, but so far this isn't the case.


Sure yeah, but what percentage of programmers actually work on OS's and compilers? It just seems to me that C and even Java to a lesser extent are too low level nowadays for many of the stuff they're used in. I mean I learned to program first in C and then Java, but now that I've been using a lot of stuff like Python and Haskell it seems like a major pain when I have to work in one of those again.
I guess the standard is changing in the start-up scene now though. Most of the ones I've seen were using higher level stuff.
Highest score: 3063; Highest position: 67;
Winner of {World War II tournament, -team 2010 Skilled Diversity, [FuN||Chewy]-[XII] USA};
8-3-7
User avatar
Major Haggis_McMutton
 
Posts: 403
Joined: Sun Mar 26, 2006 11:32 am

Re: Comics

Postby Haggis_McMutton on Mon Jul 30, 2012 2:11 pm

Also:

Image

Image
Highest score: 3063; Highest position: 67;
Winner of {World War II tournament, -team 2010 Skilled Diversity, [FuN||Chewy]-[XII] USA};
8-3-7
User avatar
Major Haggis_McMutton
 
Posts: 403
Joined: Sun Mar 26, 2006 11:32 am

Re: Comics

Postby natty dread on Mon Jul 30, 2012 2:34 pm

Haggis_McMutton wrote:
natty dread wrote:I'm sure you can do it in Python too (it's pretty damn versatile for an interpreted language), but not by directly manipulating memory locations with pointers.

I guess you could just embed the C in Python anyway, should be possible, though I've never actually done it.


Indeed it's possible - if I recall, python has means for calling C libraries directly. Then there's Cython which compiles python code to C code. And Jython which compiles python to Java. And Vala which compiles C#-like code to C. etc...

Well, I think the trend these days is to use some combination of a low-level language + high-level language. Often, back-ends are written with a low-level language, whereas high-level languages are used for interfaces and front-ends, also scripting.

However there are plenty of applications where low-level languages are still necessary, and I don't think they're going to go anywhere for a while. Operating systems, compilers, hardware drivers, etc. all require lower-level languages for coding. Maybe in the future we'll have computers with such ridiculous performance that the distinction becomes moot, but so far this isn't the case.


Sure yeah, but what percentage of programmers actually work on OS's and compilers? It just seems to me that C and even Java to a lesser extent are too low level nowadays for many of the stuff they're used in. I mean I learned to program first in C and then Java, but now that I've been using a lot of stuff like Python and Haskell it seems like a major pain when I have to work in one of those again.
I guess the standard is changing in the start-up scene now though. Most of the ones I've seen were using higher level stuff.


There are still plenty of applications where lower-level languages are more suitable. Graphics applications, music/recording, games, emulators, virtual boxes, web server software, shared libraries, etc. Lots of things. Besides, a lot of the benefits of using an interpreted language are diminished on open-source software - for example, when the source is freely available, it becomes much easier to port the software to whatever platform you choose, so the cross-platform functionality of interpreted languages becomes less of an advantage.

Maybe someday we'll get to the point where low-level languages become redundant for everything except the system kernel. On the other hand, it could be that we'll just come up with more resource-hungry applications that still require coding with lower-level languages - the phenomenon is best seen in computer games: no matter how powerful a new gaming hardware is, someone is going to come up with ways to utilize all of its potential...
Image
User avatar
Sergeant 1st Class natty dread
 
Posts: 12877
Joined: Fri Feb 08, 2008 8:58 pm
Location: just plain fucked

PreviousNext

Return to Out, out, brief candle!

Who is online

Users browsing this forum: No registered users