• Selbo (unregistered)

    So many of you are wrong. Celsius and Centigrade are not exactly the same. To convert Celsius to Kelvin, you subtract 273. To convert Centigrade to Kelvin, you subtract 273.15. (Centigrade is obsolete.)

  • Selbo (unregistered) in reply to Selbo

    Argh, make that add, not subtract!

  • nex (unregistered) in reply to DeLos

    Well to give the Excel-guy the benefit of the doubt: he might just have used that nifty "pull down to increment"-feature instead of typing each value manually. My guess is that is why he did it that way...

  • Anon Barbarzyńca (unregistered) in reply to Lakom
    Lakom:
    Crap! Fixed it:

    "ID";"XML" 1;<kelvin_m273>0</kelvin_m273> 2;<kelvin_m274>1</kelvin_m274> 3;<kelvin_m275>2</kelvin_m275> ...

    Actually, I liked the first one better :)

  • Tei (unregistered) in reply to webrunner
    KattMan:
    TopicSlayer:
    Carra:
    Christian:
    Whoops:
    This reminds me of a very funny joke:

    /* world's last mistake in C */ if(code = CODE_RED) { launch_missles(); }

    const int CODE_RED = 0; /* saved the world */

    That will just put code to 0 and fire them anyway.

    slaps head Grrrrrrrr.... How is it that such simple constructs elude people?

    And now, so I'm not the "asshole" that just criticizes your ignorance without explanation:

    The = operator returns to the left-hand-side the value on the right-hand-side. This behavior allows such statements as a = b = c to set a equal to b equal to c as would be expected. Therefore, returned to the if statement (the left-hand-side) in the above example would be, without surprise, the value zero. This would, as noted, effectively "save the world."

    It seems that some people think that if(x=y) returns the value of if the assignment was successful or not. I don't know how that idea came about, but it seems to be the logic flaw people are following. i.e. The assignment worked, return True! If the assignment didn't work, it would throw an exception instead of false. Like I said, no idea how that got started.

    BTW, HELP DESK GIRL FOREVER! She even has a tattoo!

    There's sort of an idea that there are two kinds of functions:

    a) Functions which return stuff

    b) Functions which do stuff

    In C "by default" everything return a value. Is what make C.. C. And what "Think in C" is all about. Pascal has procedures and functions, but C only have functions, and functions defined "void", so if theres return values, are random undefined values from AX. Pascal != C.

  • b.baer.b (unregistered) in reply to DeLos

    No you would have to convert the delta with a C2K function.

  • trikki (unregistered)

    The reason the programmer had used Excel is it's "Fill series" -feature. He had not typed all values by hand, but typed the first value and then dragged the rest with mouse. How clever of him!

  • kstengfufl (unregistered)

    Being a C++ fanboy, I just have to post a templated version of this WTF:

    template< int N > struct K2C_factory { static int K2C( int T ) { if( T == N ) return T-273; else return K2C_factory< N-1 >::K2C( T ); } };

    template<> struct K2C_factory< 273 > { static int K2C( int T ) { if( T<273 ) printf( "Temp out of range!\n" ); return 0; } };

    int K2C( int T ) { return K2C_factory< 303 >::K2C( T ); }

    The actual code that is produced by this construct is just as WTF'ed as the original...

  • kstengfufl (unregistered)

    Correction: f( T == N ) return T-273; should read: f( T == N ) return N-273;

  • (cs) in reply to KattMan
    KattMan:
    It seems that some people think that if(x=y) returns the value of if the assignment was successful or not. I don't know how that idea came about, but it seems to be the logic flaw people are following. i.e. The assignment worked, return True! If the assignment didn't work, it would throw an exception instead of false. Like I said, no idea how that got started.

    Because that's how it works in Perl (and pressumably other languages too): The lvalue of an expression is its successful completion. So if the assignment succeeded, then its lvalue would be "true". The fact that a failure to assign would generate an exception and fail the program does not change anything; it just means that, in practical terms, assignments would always return "true".

    However, in C, the lvalue of an expression is the inherent value of the expression itself.

    Anyway, that's how it got started.

    -dZ.
    
  • Bergerac (unregistered)

    Actually that doesn't look strange at all to me. In my experience, high performance embedded code often has sequences of if..then..else, or lookup tables rather than arithmetic operations, because "if x=y, then a=b" is quicker than a subtract operation. (Although admittedly this depends on the processor).

    And the Excel thing - he won't have typed things in manually, he will typed in one line of code and then dragged the row downwards whereupon excel auto-fills the other rows. I do it a lot!

    As for the redundant use of the converstion routine -perhaps he found the code ran quicker when subtracting 8-bit integers. If the operation was done in Kelvin, he's dealing with two numbers that don't fit into an 8-bit int. If the processor is an 8-bit one, this may be the case.

  • LM (unregistered) in reply to DeLos

    no, a C2K. I think it was in excel so they could automagically populate the numbers.

  • Gilles (unregistered)

    Isn't the real WTF the fact that he's using "=" as a comparison operator instead of "==" ? O_o

  • (cs) in reply to K2C

    They may be more efficient, but as we learned a few days ago they are also very unstable ;)

  • Omega (unregistered)

    well, the excel file isn't necessarily typed by hand - you could just type one of those lines, then select it and drag down: excel automatically increases both numbers on every line (I just tested in oocalc, I assume excel's not braindead). but still...

    (also, it should probably be 'return Ktemp-273;', not 'return Ktemp-270;')

  • Hundenapf (unregistered)
    if(Ktemp= 273 ){return 0 } else if(Ktemp= 274 ){return 1 } else if(Ktemp= 275 ){return 2 } else if(Ktemp= 276 ){return 3 } else if(Ktemp= 277 ){return 4 }

    Hmmm...

    1. They should really have used switch() here.
    2. Ktemp= 273? I can't shake the feeling that something important is missing...
  • NeoMojo (unregistered)

    I think I know why the programmer used a spread sheet! I think I've got it! I haven't bothered to read the rest of the comments because I'm fairly sure I'm the only person in the whole world who could have realised this, so no one will have posted this before me.

    He used excel becaMASSIVE FAIL

  • SomeGuy (unregistered)

    BTW, it's "return Ktemp-273;" not "return Ktemp-270;"

    =)

  • Kallahan (unregistered) in reply to DeLos

    Looks like someone need to upgrade their retro encabulators.

  • Anders (unregistered) in reply to K2C

    Clearly, the real WTF here is why, why, WHY did he not use a case-switch statement here, instead of else-if?

  • ch. (unregistered)

    I wonder if anyone realized that already but he probably didn't type all that manually, he just used the mouse drag / auto fill feature in excel.

    But anyway it wouldn't work because he used buttignment operator ( = ) instead of a comparison operator ( == )

  • slaphead (unregistered) in reply to Lakom
    Lakom:
    Crap! Fixed it:

    "ID";"XML" 1;<kelvin_m273>0</kelvin_m273> 2;<kelvin_m274>1</kelvin_m274> 3;<kelvin_m275>2</kelvin_m275> ...

    You should've created an Excel spreadsheet to generate your XML file ;-)

  • Anonymous (unregistered) in reply to ch.
    SomeCoder:
    Wow, I really hope yet another person tells us that the user probably used the Excel Auto fill function.
    And since...
    In Excel, you can easily enumerate cells starting from a value without having to enter a formula.
    You think way too complicated. He typed in 2 rows, dragged down the selection, and there you have 30 numbers...
    I was really surprised how many people overlooked that little point. There's really no other reason to put it in to excel except for the auto generating capabilities.
    The real WTF is the author not knowing you can just select two numbers in Excel and drag a corner to make continue a series started by said numbers without having to type a formula.
    Just because the cells were not formulas does not mean everything was typed in by hand. Ever used Ctrl-D (copy-down) in excel, or dragged down from the corner?
    I will agree that the Excel stuff was probably done with Excel's autoincrement capability rather than manually typed.
    Well to give the Excel-guy the benefit of the doubt: he might just have used that nifty "pull down to increment"-feature instead of typing each value manually. My guess is that is why he did it that way...
    The reason the programmer had used Excel is it's "Fill series" -feature.
    And the Excel thing - he won't have typed things in manually, he will typed in one line of code and then dragged the row downwards whereupon excel auto-fills the other rows. I do it a lot!
    no, a C2K. I think it was in excel so they could automagically populate the numbers.
    well, the excel file isn't necessarily typed by hand - you could just type one of those lines, then select it and drag down: excel automatically increases both numbers on every line
    I wonder if anyone realized that already but he probably didn't type all that manually, he just used the mouse drag / auto fill feature in excel.

    So, could we simply send out tactical mini vans to anyone mentioning Excel's auto-fill feature from this point on?

  • Brad (unregistered)

    That should be "capacitive duractance", not "capacitive directance".

  • Henry Miller (unregistered) in reply to Spoe
    Spoe:
    For example, if you're trying to maintain a temperature above the freezing point of water this conversion will convert a temperature slightly below freezing (273 Kelvin) into freezing (0 Celsius or 273.15 Kelvin). And depending on what other operations might be done on the converted temperatures, this error can snowball.

    Or maybe I just spent too much time in the physics program before switching to CS.

    I don't know, if you had really spent too much time in physics you would know that water freezes at 0 Celsius only when it has an exact amount of impurities, and is at an exact pressure.

    Pure water can be "supercooled" to well below the freezing point. Getting pure water is left as an exercise for the reader (it is almost impossible).

    Salt is the best known impurity that changes the freezing point of water. There are plenty of others.

  • Daniel Lowe (unregistered) in reply to K2C

    The real wtf is that the code will always return 0 and he didn't notice. Or he typed it in wrong.

  • Jared (unregistered)

    Interestingly I found excel great for generating large blocks of C code when developing poker machine games. Especially when all the math and symbol data already exists in excel.

  • SteveOC (unregistered)

    Coming soon - K2C floating point edition

    The professional edition of K2C(f) will correctly convert Kelvin to Celcius with 4 decimal points of accuracy.

    The enterprise edition of K2C(f) will work up to 8 decimal points.

    Mega !!!

  • RK (unregistered) in reply to DeLos

    Oh how I wish I could vote on comments! :-)

  • iNFiNiTyLoOp (unregistered)
    int K2C(Ktemp int) {
    	/* MUST use the Microsoft preprocessor!! */
    	#include "tempconv.xls"
    }
    
  • Thank you (unregistered)

    Hum, if that fragment is C, it won't compile of course; with minor modifications it would always return 0 for all inputs. :)

  • tehdely (unregistered)

    I get what happened here.

    The reason that stuff's in the excel spreadsheet is the guy made a few rows and then used "fill down" to continue the pattern. That's what smart developers do.

    Why do the subtraction in code when you can have Excel do all the smart work for you and generate a handy table! And then you can copy and paste it INTO the code! Look, he even filled in the "return" statements. I bet this guy felt so smart.

  • tehdely (unregistered) in reply to tehdely

    Note that the previous 23742374 comments didn't show up before I posted that one; I SWEAR

  • test (unregistered)

    Uhm I also suppose they want to compare the temparature, not assign to it ?

  • (cs) in reply to Anonymous
    Anonymous:
    So, could we simply send out tactical mini vans to anyone mentioning Excel's auto-fill feature from this point on?

    No, no, no! You didn't get the true purpose of this thread. The minivans should go to all the other people who fail to mention the excel feature and the =/== typo in their posts!

  • Kelvin (unregistered) in reply to DeLos
    DeLos:
    but then the delta is the difference in Celsius! surely you need a K2C function to handle that! //see comment.xls

    wouldn't that be C2K?

  • Ian (unregistered)

    "Someone had apparently typed each Kelvin and degree Celsius value in by hand" Or typed 2, then clicked and dragged.

  • lvj (unregistered) in reply to DeLos

    he/she/it used excel to generate n+1 by typing 1[enter]2[enter] highlighting and dragging square handler :)

    anyway interesting way to generate C code;)

  • tom (unregistered) in reply to DeLos

    Oh coarse they didn't type all the numbers out in excel, they used excels auto range function 1,2 click+drag, simple and efficient (well compared to typing it all out by hand. Still pointless mind ;-)

  • Roger (unregistered)

    Umm, sure you don't need K2C at all if all you ever want to do is calculate the difference.

    But, did anyone else notice that K2C always returns 0?

  • Roger (unregistered) in reply to Roger

    Hmmm, there weren't 4 pages of comments showing when I originally wrote this comment, only two comments. Go figure.

    feeling foolish.

  • MickB (unregistered) in reply to DeLos

    (Prays that that was sarcasm.)

  • The Doctor (unregistered) in reply to K2C

    a database fronted, of course by a web service found by doing a UDDI lookup from a delegate fronted by an adapter found by a factory. THAT might be enterprisey enough.

  • Jay (unregistered)
    K2C:
    fist.. and why didn't he just use a database? everyone knows databases are more efficient then excel...

    Ah, I see the right solution now! Yes, a database would be a much more elegant solution. Something like:

    select
    case
    when %1=273 then (select c from k2c where c=0)
    when %1=272 then (select c from k2c where c=1)
    when %1=271 then (select c from k2c where c=2)
    ... snip ...
    else null
    end as c
    from dual; 
    
  • A Concerned Reader (unregistered)

    Huh? Unless there's something going on with macros, that doesn't even look like valid C code: http://codepad.org/3g1fefQj. Even if you fix that one, those are assignments in the "if" conditions: http://codepad.org/cu1tv3EA.

  • Pete (unregistered)

    I've got to say something. I'm starting to think the WTF stories are being made up. anyone else think so?

  • Excel Hexel (unregistered) in reply to K2C

    But have you never used Excel before? You can quickly copy blocks of text for repeating, and you can also put a number in a box, drag the cross-hair down a number of cells, and Excel just increments as you go. Very useful. But it would have been better to think about why you can avoid K2C all along.

  • D (unregistered)

    Ktemp-273 not 270

  • JR (unregistered)

    Yeah, the "=" instead of "==" does not have anything to do with wrong function of that procedure.

  • JuicyBrain (unregistered) in reply to IV

    Simply returning the input - 273 would not give an out of range error. Obviously that would not be a correct solution. the programmer knew what (s)he was doing.

    You forgot your <sarcasm> tags !

Leave a comment on “K2C”

Log In or post as a guest

Replying to comment #:

« Return to Article