|
There is no way &1 even compiles (right?) so I don't understand what this entire fiasco is about. The logical operator "AND" requires two ampersands, not one. I'm surprised none of your IDEs warned you about this. It's just a segfault waiting to happen. Just use modulus and move on.
|
# ? Jan 7, 2009 15:18 |
|
|
# ? Apr 24, 2024 20:48 |
|
geetee posted:There is no way &1 even compiles (right?) so I don't understand what this entire fiasco is about. The logical operator "AND" requires two ampersands, not one. I'm surprised none of your IDEs warned you about this. It's just a segfault waiting to happen. Just use modulus and move on. Hrm good sir I think you are wrong, allow me a moment to write a two-page refutation of this complete with references (with exact page numbers) to the C99 standard, the C++98 standard, the ANSI C standard and the C++0x draft.
|
# ? Jan 7, 2009 15:52 |
|
Painless posted:Hrm good sir I think you are wrong, allow me a moment to write a two-page refutation of this complete with references (with exact page numbers) to the C99 standard, the C++98 standard, the ANSI C standard and the C++0x draft. One can find everything in the C++0x draft, so that may not help your case. It's "Programming with Everything but the Kitchen Sink, but We Threw One In Anyways" in one document.
|
# ? Jan 7, 2009 15:59 |
|
geetee posted:There is no way &1 even compiles (right?) so I don't understand what this entire fiasco is about. The logical operator "AND" requires two ampersands, not one. I'm surprised none of your IDEs warned you about this. It's just a segfault waiting to happen. Just use modulus and move on. There's more than one kind of 'AND'...
|
# ? Jan 7, 2009 16:09 |
|
Steampunk Mario posted:There's more than one kind of 'AND'... *whoooosh* edit: or "look at you, look how stupid you are" I guess
|
# ? Jan 7, 2009 16:19 |
|
heeen posted:Hahaha better yet, how do you define modulus for float numbers? Ever heard of fmod?
|
# ? Jan 7, 2009 17:02 |
|
I did get pretty carried away with the retarded examples, but it's still loving stupid to rely on the representation of something to do something mathy when you have a perfectly good/obvious/understood/optimizable way of doing it, as in this case.
|
# ? Jan 7, 2009 17:03 |
|
code:
|
# ? Jan 7, 2009 17:19 |
|
minato posted:
That's not a horror, that's an extreme optimisation for an operation done a lot in many renderers. Low accuracy bitwise hack combined with one Newton-Raphson iteration.
|
# ? Jan 7, 2009 17:26 |
|
minato posted:
That's pretty likely to go boom on GCC FYI
|
# ? Jan 7, 2009 17:33 |
|
Painless posted:That's pretty likely to go boom on GCC FYI Builds and runs without incident on 4.0.1 with -Wall and -pedantic.
|
# ? Jan 7, 2009 17:37 |
|
minato posted:
Isn't that the Quake inverse square root function?
|
# ? Jan 7, 2009 17:48 |
|
Painless posted:That's pretty likely to go boom on GCC FYI
|
# ? Jan 7, 2009 17:49 |
|
dancavallaro posted:Isn't that the Quake inverse square root function? Yup.
|
# ? Jan 7, 2009 17:51 |
|
I may be a bit late posting this, but it looks like everything at work is escaped with mysql_escape_string(). I know it's deprecated and all, but I'm unable to find info on the real world security implications, or even why escaping ' isn't enough. Any examples I've ever seen rely on an unescaped '. Perhaps if I have enough evidence of what might happen, it can be changed. And no, I'm not going to rewrite it all to use whatever the gently caress it's called where you bind variables. I don't even know if mysqli is available.
|
# ? Jan 7, 2009 18:28 |
|
Zakalwe posted:That's not a horror, that's an extreme optimisation for an operation done a lot in many renderers. Low accuracy bitwise hack combined with one Newton-Raphson iteration. It's a coding horror for any x86 (post-1999) or PowerPC based computer.
|
# ? Jan 7, 2009 18:58 |
|
ehnus posted:It's a coding horror for any x86 (post-1999) or PowerPC based computer. In the context in which it was originally written it's not a coding horror which is what counts. Today of course I would (and do) use SSE for such things.
|
# ? Jan 7, 2009 19:12 |
|
Zakalwe posted:In the context in which it was originally written it's not a coding horror which is what counts. Today of course I would (and do) use SSE for such things. Can you elaborate on the why and how you do things nowadays?
|
# ? Jan 7, 2009 19:26 |
|
Sartak posted:Yup. That's an interesting read, and so is this paper http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf for the more mathy people here.
|
# ? Jan 7, 2009 19:36 |
|
heeen posted:Can you elaborate on the why and how you do things nowadays? My research is on RTRT (real-time ray-tracing). Packet tracing (Google Keywords: Ingo Wald ICRT Packet Tracing) at its simplest involves tracing 4 rays at a time in SSE. Other related techniques such as MLRTA, frustum culling etc. all benefit from using SSE. Here's a reciprocal SSE sqrt from my code. code:
|
# ? Jan 7, 2009 19:43 |
|
Zakalwe posted:That's not a horror, that's a savage optimisation for an operation done a lot in many renderers. Low accuracy bitwise hack combined with one Newton-Raphson iteration. Fixed the quote. I do wish the code had some more spaces in it though
|
# ? Jan 7, 2009 19:44 |
|
btw, here's something I found out recently. Here's that line from the above code to access the bits in a float. code:
code:
|
# ? Jan 7, 2009 19:55 |
|
Zakalwe posted:Perhaps a bit off-topic for a coding horrors thread. Nope I'd say you're in the right place. edit: vvvvv just funnin', man Filburt Shellbach fucked around with this message at 20:16 on Jan 7, 2009 |
# ? Jan 7, 2009 19:56 |
|
Sartak posted:Nope I'd say you're in the right place. Optimisation when relevant is not a coding horror.
|
# ? Jan 7, 2009 19:59 |
|
Zakalwe posted:btw, here's something I found out recently. Can you explain why this is faster than doing int i = (int)x
|
# ? Jan 7, 2009 20:01 |
|
Presto posted:Should be fine, although it may bitch about violating strict aliasing rules. It won't "bitch", but it's quite possible that it will randomly fail! Just use unions drat it. Jeet chirst this is making me so angry. What nubbery..
|
# ? Jan 7, 2009 20:01 |
|
hexadecimal posted:Can you explain why this is faster than doing int i = (int)x Uhh because what you posted doesn't work?
|
# ? Jan 7, 2009 20:02 |
|
zergstain posted:I may be a bit late posting this, but it looks like everything at work is escaped with mysql_escape_string(). I know it's deprecated and all, but I'm unable to find info on the real world security implications, or even why escaping ' isn't enough. Any examples I've ever seen rely on an unescaped '. Perhaps if I have enough evidence of what might happen, it can be changed. And no, I'm not going to rewrite it all to use whatever the gently caress it's called where you bind variables. I don't even know if mysqli is available. The difference between escape and real_escape is only a problem if you're not using latin1. If you can somehow magically escape all the ' characters assuredly, then in most cases you're safe, yes. But this is the problem with what you're saying -- the "real" coding horror: quote:I'm unable to find info on the real world security implications, or even why escaping ' isn't enough. You don't know. You don't know whether or not an attack is possible. You do, however, know the best way to code it so that this entire class of attack is NOT possible. The flaw is in your thought process. "Well, I don't know of any attacks that this doesn't prevent against, so this level of security is okay, I'll just use that." Why would you even want to think about that? Just code it the way that's not vulnerable to that class of attack AT ALL and go about your day.
|
# ? Jan 7, 2009 20:03 |
|
hexadecimal posted:Can you explain why this is faster than doing int i = (int)x I'm not a big C guy, so I'm kind of guessing here, but just doing (int)x will cast x to an integer, and chop off anything after the decimal. But (int&)x or *(int*)&x preserves all of the bits of the float, but as an integer. This is what you need, because the point is to be able to do bit operations on the bits of the float. edit: In other words, the point is not to cast x to an integer, but to allow the bits of the float to be considered an integer. Or something like that.
|
# ? Jan 7, 2009 20:07 |
|
dancavallaro posted:I'm not a big C guy, so I'm kind of guessing here, but just doing (int)x will cast x to an integer, and chop off anything after the decimal. But (int&)x or *(int*)&x preserves all of the bits of the float, but as an integer. This is what you need, because the point is to be able to do bit operations on the bits of the float. correct
|
# ? Jan 7, 2009 20:08 |
|
Painless posted:It won't "bitch", but it's quite possible that it will randomly fail! Just use unions drat it. Where in the C standard does it specify that unioned elements will occupy the same space in memory?
|
# ? Jan 7, 2009 20:09 |
|
Zakalwe posted:Uhh because what you posted doesn't work? I just tried it and it did. x is a float and you are casting it to int i? dancavallaro posted:I'm not a big C guy, so I'm kind of guessing here, but just doing (int)x will cast x to an integer, and chop off anything after the decimal. But (int&)x or *(int*)&x preserves all of the bits of the float, but as an integer. This is what you need, because the point is to be able to do bit operations on the bits of the float. Oh I see. Thanks. Learn something new everyday! I actually wondered before how to do this in C++ (I did it in java to switch endianess). hexadecimal fucked around with this message at 20:19 on Jan 7, 2009 |
# ? Jan 7, 2009 20:09 |
|
edit: too late edit2: this thread is moving way too fast. Everyone go take 5.
|
# ? Jan 7, 2009 20:09 |
|
hexadecimal posted:I just tried it and it did It compiles, but it doesn't do what we want to do (access the bits in a float). Taking 5 to get some food sounds like a good idea.
|
# ? Jan 7, 2009 20:12 |
|
hexadecimal.txt all up in this page e: i kid, i kid
|
# ? Jan 7, 2009 20:26 |
|
Mikey-San posted:hexadecimal.txt all up in this page Fixed that for you.
|
# ? Jan 7, 2009 20:39 |
|
Ugg boots posted:Where in the C standard does it specify that unioned elements will occupy the same space in memory? Wait, don't unions by definition start at the same point in memory. If the types have the same length they completely overlap each other. Am I missing something here? Edit: Wagammama's ramen is delicious.
|
# ? Jan 7, 2009 20:41 |
|
Ugg boots posted:Where in the C standard does it specify that unioned elements will occupy the same space in memory? Structure and union specifiers have the same form. [ . . . ] The size of a union is sufficient to contain the largest of its members. The value of at most one of the members can be stored in a union object at any time. A pointer to a union object, suitably converted, points to each of its members (or if a member is a bit-field, then to the unit in which it resides), and vice versa. —ANSI/ISO 9899:1990 (the ANSI C standard) Section 6.5.2.1
|
# ? Jan 7, 2009 20:50 |
|
Edit: Thanks.
|
# ? Jan 7, 2009 20:51 |
|
|
# ? Apr 24, 2024 20:48 |
|
Ryouga Inverse posted:The difference between escape and real_escape is only a problem if you're not using latin1. I do use real_escape when I write my own code, I just wanted to know if there was some real world examples of someone getting owned for using escape that I could use to argue the case of switching over, which should be real fast since everything is supposed to go though a quote function which does poo poo like undo magic quotes. I confirmed just now that mysqli isn't available in our php, so prepared statements (I remembered what they were called) are impossible, even if it were somehow possible for me to make a case to go rewrite thousands of lines of code.
|
# ? Jan 7, 2009 21:09 |