|
sex offendin Link posted:There is no generalized way to byte-swap IEEE 754 numbers anywhere, they are for all intents and purposes non-portable.
|
# ? Jul 8, 2009 03:32 |
|
|
# ? May 16, 2024 07:57 |
|
sex offendin Link posted:There is no generalized way to byte-swap IEEE 754 numbers anywhere, they are for all intents and purposes non-portable.
|
# ? Jul 8, 2009 03:46 |
|
gibbed posted:This is nitpicking and platform specific, although the cerr thing is stupid, yes. I'm not sure about Painless's point about "creating a T instance makes the byteswap a lot less generic." The function is already too generic because it accepts things like struct foo { int i; float f; };, std::complex<float>, int a[10], ... Normally yes you might want to avoid using a default constructor unless necessary because there's no reason to enforce the type has a default constructor if you don't need to. But in this case I don't think ByteSwap() should work at all on non-integral types, which are all default-constructible (obviously). Printing an error message is unacceptable as well. There's code that attempts to call ByteSwap() on long doubles, which can exceed (and usually do) 8 bytes in size. It's evident from the history of this file that it's intended to be the end-all to byteswaping for a wide swath of our codebase. That it's intended to "just work" on floating point types. It does not. As for the runtime switching, I re-coded it as a compile-time switch by just using templates and am seeing a 4x to 16x speed improvement. There are other issues, namely: Nitpicky, but: "ByteSwap() - CamelCase" vs "swap_data() - lowercase_underscore"; just pick one. Why should a for loop calling ByteSwap() be slower than a single call to swap_data()? It shouldn't, and it doesn't have to be. Testing has shown that swap_data() is up to 10x faster than a loop over calls to ByteSwap(). The code is loving lazy. As I already said, the code is too generic. I actually had the guy who wrote the code in my office the other day and he was saying things like, "well it's a template so you can't construct what types it accepts at all! A template accepts everything, you know, that's why it's called a template." A simple application of traits types and the error message isn't necessary and ByteSwap() only compiles when it's being used correctly. Another thing, did you notice the signature of swap_data()? void swap_data(T* data, int n). What isn't immediately obvious is that n here is supposed to be the size of T * number of Ts. Why not avoid the issue entirely with a better signature? Or at least make the parameter size_t size or something for fucks sake. code:
sex offendin Link posted:There is no generalized way to byte-swap IEEE 754 numbers anywhere, they are for all intents and purposes non-portable. I'm honestly asking, wouldn't this work? Lexical Unit fucked around with this message at 04:06 on Jul 8, 2009 |
# ? Jul 8, 2009 04:03 |
|
Lexical Unit posted:What about putting them in a union with an unsigned integer type, byteswapping the integer and returning the integer? The integer can go over whatever I/O it needs to and be byteswapped back into a floating point type on the other end. Accessing a value stored in a union from a type other than the one that it was stored with is a violation of strict-aliasing (with the exception of accessing via char*). Furthermore, y'all need to shut up about the original code being unsafe since it casts to a char* and that's guaranteed to be safe by the ISO standard. EDIT: Since I don't want to write an essay on this, I will defer to a good source: http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html Avenging Dentist fucked around with this message at 04:21 on Jul 8, 2009 |
# ? Jul 8, 2009 04:06 |
|
So if you leveraged char* to do the swapping rather than a union hack, and for floating point types you returned an accommodating integer type rather than storing a byteswapped floating point value back into a floating point type, would you be reasonably safe then? Probably due to lovely websites found through google: quote:the compiler very probably will return the double return value in an FPU register, and if not then, at some point the value may be loaded into an FPU register. This means the swapped result is loaded into an FP register, which then means the FP unit will take a look at the number, and then the fun begins. Lexical Unit fucked around with this message at 04:29 on Jul 8, 2009 |
# ? Jul 8, 2009 04:20 |
|
There is literally nothing in the C99/C++03 standards* that says you can't manipulate a floating point value from casting/type-punning to a char*. I don't see why people are obsessing about this for. * Probably the same for other versions of C and C++, but I don't have access to the specs.
|
# ? Jul 8, 2009 04:24 |
|
Lexical Unit posted:Probably due to lovely websites found through google: Then yeah keep the swapped data in a char buffer. (Also note that I didn't say anything about manipulating the value of a floating-point number in a predictable way. ) (Also also you should really be using type traits to disable that if it's not a primitive type). Avenging Dentist fucked around with this message at 04:57 on Jul 8, 2009 |
# ? Jul 8, 2009 04:45 |
|
Nevermind. I really need some sleep. What you say makes perfect sense.
Lexical Unit fucked around with this message at 05:50 on Jul 8, 2009 |
# ? Jul 8, 2009 05:38 |
|
Lexical Unit posted:Edit: Wait, I think I misread that. Did you mean should or souldn't? I already mentioned that I used type traits to clamp that poo poo down. I said primitive, not integral. (There's also no reason that byteswapped data needs to be returned with the same type as the original; in fact it would be more sensible to return it as a char buffer, since you really shouldn't be manipulating byteswapped data as though it were of the original type, floating-point or not. What I am saying here is "make it work with integral and floating point values and nothing else".)
|
# ? Jul 8, 2009 05:46 |
|
hello world in prolog code:
|
# ? Jul 8, 2009 15:06 |
|
tef posted:hello world in prolog Looks reasonable to me, where's the horror?
|
# ? Jul 8, 2009 16:21 |
|
Zombywuf posted:where's the horror? It's prolog.
|
# ? Jul 8, 2009 21:42 |
|
Sartak posted:It's prolog.
|
# ? Jul 8, 2009 21:44 |
|
So did the guy who came up with Prolog think that assembly language wasn't ugly enough or something? Because for a moment I thought that was extremely macro-heavy assembly.
|
# ? Jul 8, 2009 21:48 |
|
http://alain.colmerauer.free.fr/ArchivesPublications/HistoireProlog/19november92.pdf it turns out you don't need to re-implement natural numbers or lists, or a stack machine to write hello world in prolog. hint: hello world in prolog is actually :- writef("%w",["Hello, world!"]). or something.
|
# ? Jul 8, 2009 21:50 |
|
So i saw this today from ERDAS's software SDK...code:
I was curious because they prototype their functions like: <type> <function name> __((<parameter list>))
|
# ? Jul 8, 2009 23:45 |
|
I'm reimplementing a tool that fills space. I don't have source for the original tool, but that's what Reflector is for!...code:
ed: I think my favorite part of this is that he knows to use regexes, but seems unaware of how exactly he should be using them. Dessert Rose fucked around with this message at 23:59 on Jul 8, 2009 |
# ? Jul 8, 2009 23:54 |
|
UberJumper posted:So i saw this today from ERDAS's software SDK... It is so they can change it to #define __(a) () to support C compilers that do not implement function prototypes, I suspect.
|
# ? Jul 9, 2009 01:59 |
|
Vanadium posted:It is so they can change it to #define __(a) () to support C compilers that do not implement function prototypes, I suspect. what C compiler doesn't support function prototypes, and how would that macro help? Do you mean so they can change it to a function pointer?
|
# ? Jul 9, 2009 05:17 |
|
RussianManiac posted:what C compiler doesn't support function prototypes, and how would that macro help? Do you mean so they can change it to a function pointer? code:
|
# ? Jul 9, 2009 06:55 |
|
BigRedDot posted:Old, old, old pre-ansi "K&R" compilers. And no it doesn't change it to a function pointer. The macro would be redefined as I must be missing something. If you do #define __(a) ( ) then all you are doing is just getting rid of arguments to a function prototype, right, but the return type and name should still be there assuming that it looks like <type> <function name> __((<parameter list>)) vvvvvvvvvvvvvvvvvvv I am confused. Isn't a prototype just a function declaration without its implementation? RussianManiac fucked around with this message at 07:50 on Jul 9, 2009 |
# ? Jul 9, 2009 07:43 |
|
RussianManiac posted:I must be missing something. If you do #define __(a) ( ) then all you are doing is just getting rid of arguments to a function prototype, right, but the return type and name should still be there assuming that it looks like Yes, hence K&R syntax. (Except that functions don't have prototypes in K&R C.)
|
# ? Jul 9, 2009 07:45 |
|
Sartak posted:It's prolog. This would explain the response I got to this childish job advert. I wrote them an email berating them for using popular languages like erlang and haskell and so sent them a prolog response to elicit the following reply: quote:FAIL: We were trying to figure out why this is a fail.
|
# ? Jul 9, 2009 10:56 |
|
tef posted:This would explain the response I got to this childish job advert. What the hell kind of job advertisement is that!?
|
# ? Jul 9, 2009 11:29 |
|
tef posted:This would explain the response I got to this childish job advert. code:
|
# ? Jul 9, 2009 12:14 |
|
The best part is that they're a PHP shop, according to an email response posted on Reddit.
|
# ? Jul 9, 2009 12:16 |
|
TSDK posted:
code:
|
# ? Jul 9, 2009 12:26 |
|
RussianManiac posted:I am confused. Isn't a prototype just a function declaration without its implementation? It is, basically. But in C before prototypes, you would not give the parameter list when declaring functions.
|
# ? Jul 9, 2009 12:29 |
|
Haha, I love their "fail" page. Someone submitted a GA program that evolves hello world.
|
# ? Jul 9, 2009 18:37 |
|
Ryouga Inverse posted:Haha, I love their "fail" page. Someone submitted a GA program that evolves hello world. Clearly not 1337 enough for these badass renegades of code
|
# ? Jul 9, 2009 18:58 |
|
the dd and sed one is the only amusing "win" on that page; all the others are just spamming anonymous functions.
|
# ? Jul 9, 2009 19:15 |
|
Once you see someone use "fail" as a noun you can pretty much ignore everything else they say since they are human scum.
|
# ? Jul 9, 2009 19:17 |
|
Avenging Dentist posted:Once you see someone use "fail" as a noun you can pretty much ignore everything else they say since they are human scum. I bet they have lolcat posters on the wall at their office.
|
# ? Jul 9, 2009 19:21 |
|
Avenging Dentist posted:Once you see someone use "fail" as a noun you can pretty much ignore everything else they say since they are human scum. http://www.askoxford.com/concise_oed/fail?view=uk
|
# ? Jul 9, 2009 19:37 |
|
Zombywuf posted:http://www.askoxford.com/concise_oed/fail?view=uk Believe it or not, the OED doesn't tell you which words are stupid.
|
# ? Jul 9, 2009 19:41 |
|
I'm thinking it's not an actual job posting, just an elaborate troll. How could anyone take themselves seriously after asking for all that?
|
# ? Jul 9, 2009 19:50 |
|
Avenging Dentist posted:Believe it or not, the OED doesn't tell you which words are stupid. However you have just called dictionary corner human scum. This is tantamount to a declaration of war on the UK.
|
# ? Jul 9, 2009 19:55 |
|
I was looking through some of those "fail"s and couldn't figure out how one of them was getting this text it operates on:code:
Anyway at least I learned a neat trick: in python, "import this" prints the Zen of Python
|
# ? Jul 9, 2009 20:18 |
|
Zombywuf posted:However you have just called dictionary corner human scum. This is tantamount to a declaration of war on the UK. Um yeah, I'm an American, we have a habit of fighting the UK.
|
# ? Jul 9, 2009 20:39 |
|
|
# ? May 16, 2024 07:57 |
|
Didn't the Oxford dictionary catch a lot of poo poo for adding internet slang to their most recent edition?
|
# ? Jul 9, 2009 20:40 |