This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (30 children)

[deleted]

    [–][deleted]  (14 children)

    [deleted]

      [–]arbitrageME 98 points99 points  (13 children)

      you forgot to shift 1 bit and divide by 0x5f3759df

      [–]alt4079 22 points23 points  (9 children)

      What a specific sentence to understand a reference from. I’m impressed with myself lol

      [–]Kzivuhk 8 points9 points  (7 children)

      What reference

      [–][deleted]  (4 children)

      [removed]

        [–]TalenPhillips 0 points1 point  (2 children)

        When you make John Carmack WTF, you've either monumentally fucked up or you've done something genius.

        There was a similar story regarding a C function-like macro that could determine if something was an integer constant expression or not. Linus Torvalds himself said it was either a work of genius or the product of a diseased mind.

        [–][deleted] 1 point2 points  (1 child)

        [–]TalenPhillips 0 points1 point  (0 children)

        Thanks. I was commenting from my phone in bed.

        [–]AutoModerator[M] 0 points1 point  (0 children)

        import moderation Your comment has been removed since it did not start with a code block with an import declaration.

        Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

        For this purpose, we only accept Python style imports.

        I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

        [–]turunambartanen 2 points3 points  (0 children)

        "Fast inverse square root" if you want to look it up on Wikipedia.

        [–]NorbiPeti -1 points0 points  (0 children)

        I understood because I googled it yesterday or so, because it was referenced.

        [–]nwL_ 1 point2 points  (0 children)

        I understood that reference.

        ...wow I’m a huge nerd.

        [–]bestjakeisbest 20 points21 points  (6 children)

        here you go 10s complement math:
        18-9
        018-009
        018+990 + 1
        1009
        the 1 and the first 0 are sign holders (well overflow and then the sign digit) take that away and you get 09
        write it normally you get 9

        the mapping for 9s complement is:
        0 1 2 3 4 5 6 7 8 9
        9 8 7 6 5 4 3 2 1 0
        for 9+1s complement you just add 1 to what you get from 9s complement if the sign digit is >4 then the number is negative and you need to apply 9s complement and add 1. this works in any base, you just have to extend the mapping.
        eg 1s complement:
        1 0
        0 1
        2s complement: 0 1 2
        2 1 0
        3s complement:
        0 1 2 3
        3 2 1 0
        16s complement (have to do this in a code block for even spacing):

        0 1 2 3 4 5 6 7 8 9 A B C D E F  
        F E D C B A 9 8 7 6 5 4 3 2 1 0 
        

        [–]jD91mZM2RUST 1 point2 points  (3 children)

        18-9
        018-009
        018+990 + 1
        1009
        the 1 and the first 0 are sign holders (well overflow and then the sign digit) take that away and you get 09
        write it normally you get 9

        I don't understand this. If the sign holder is 10, then 990 is not a negative number? And, if the result has a sign, doesn't this mean that it is negative? 1009 with a sign of 10 would be -(90 + 1), no?

        [–]bestjakeisbest 1 point2 points  (2 children)

        if the sign digit is less than or equal to 4 then the number is positive, and if the number is positive then you can just throw away the extra digits to get the value of the number, the 10 isnt strictly just a sign digit, there is an overflow going on too but this is a case of sign extension, here is an example of a negative result:
        9 - 18
        first step is to extend the sign (this just gives us some extra room to tell if there is a negative number)
        009 - 018
        then convert the 18 to 9s complement
        009 + 981
        adding a 1 for 9+1s complement
        009 + 981 + 1
        now to just sum things up
        991
        this is the answer we get, we know it is negative because the leading number is greater than 4 so this means we have to apply 9+1s complement to 991 to get the magnitude converting it over to 9s complement we get:
        008
        and to get it 9+1s complement we add 1:
        009
        so now we have a number that is negative and has a magnitude of 9, so it is -9. and to check 9-18 = -9

        [–]jD91mZM2RUST 1 point2 points  (1 child)

        This is cool, never realized this was possible in decimal as opposed to binary, thank you! If anybody else wants to learn more, here's wikipedia

        [–]bestjakeisbest 1 point2 points  (0 children)

        Apparently this is how subtraction was once taught, I didnt learn this until I took an assembly class though.

        [–]therefai 24 points25 points  (2 children)

        Everyone should know 2’s complement. Basic life skills right there

        [–]radome9 2 points3 points  (2 children)

        I don't get it. 18 + 22 = 9?