|
Bruegels Fuckbooks posted:It's explicitly defined in the c standard section defining for loops. But why?
|
# ? Jul 18, 2017 13:44 |
|
|
# ? Jun 7, 2024 17:25 |
Shinku ABOOKEN posted:But why? The Cavern of COBOL > Coding Horrors: But why?
|
|
# ? Jul 18, 2017 17:15 |
|
Because they happened to implement it that way in the 70s.
|
# ? Jul 18, 2017 19:56 |
|
Having to put a 1 in there would be a pain in the rear end.
|
# ? Jul 18, 2017 19:58 |
|
sarehu posted:Having to put a 1 in there would be a pain in the rear end. And if there's one thing that absolutely will not be tolerated in The C Programming Language, it's annoying and error-prone corner cases.
|
# ? Jul 18, 2017 20:20 |
|
Shinku ABOOKEN posted:But why? Someone has to try stuff so we can find out it was a bad idea.
|
# ? Jul 18, 2017 20:53 |
|
Shinku ABOOKEN posted:But why? cause they let you do it in C
|
# ? Jul 18, 2017 21:57 |
|
TheBlackVegetable posted:Of course, but it looks nicer in F# Sounds like java vs scala
|
# ? Jul 18, 2017 23:02 |
|
Shinku ABOOKEN posted:But why? If I were to venture a guess it would be to allow for trivial initialization and iteration semantics while allowing for nontrivial ways of exiting the loop.
|
# ? Jul 19, 2017 01:19 |
|
I think it just looks better.
|
# ? Jul 19, 2017 02:11 |
|
Choosing the empty statement as false would mean C code:
C code:
|
# ? Jul 19, 2017 03:27 |
|
The idea behind allowing it to be omitted was probably symmetry, since it's frequently useful to omit either or both of the other two clauses.
|
# ? Jul 19, 2017 05:56 |
|
rjmccall posted:The idea behind allowing it to be omitted was probably symmetry, since it's frequently useful to omit either or both of the other two clauses. Coder! Coder! Typing bright! On the keyboard of the night! What immortal hand or eye/ Could parse thy fearful symmetry?
|
# ? Jul 19, 2017 05:59 |
|
NihilCredo posted:And if there's one thing that absolutely will not be tolerated in The C Programming Language, it's annoying and error-prone corner cases.
|
# ? Jul 19, 2017 06:02 |
|
Absurd Alhazred posted:Coder! Coder! Typing bright! Lovely. Air kisses all round.
|
# ? Jul 19, 2017 08:53 |
|
This thread seems like it would appreciate a review of Solidity, the programming language that Ethereum uses for its "smart contracts" and the technical capabilities of which presumably gives the cryptocurrency its $20B market cap (I lied, it's all based on speculation). From yosposquote:Solidity has far worse problems than not being an advanced research language. Just being a sanely designed normal language would be a big step up. Solidity is so riddled with bizarre design errors it makes PHP 4 look like a work of genius. Not having a floating point type actually seems reasonable for a financial transaction engine but it's not like it has a BCD type, either. The compiler just randomly corrupting your data though seems awesome
|
# ? Jul 20, 2017 07:28 |
|
You need floating point to multiply percentages etc. though.
|
# ? Jul 20, 2017 08:57 |
|
Fixed point can handle percentages just fine. For currency fixed point is always better because the precision doesn't change with the size of the operands. It's unfortunate that most languages have poor support for fixed point. It really should be a standard type especially in systems programming languages.
|
# ? Jul 20, 2017 11:07 |
|
Spatial posted:Fixed point can handle percentages just fine. For currency fixed point is always better because the precision doesn't change with the size of the operands. What kind of language support do you envision for fixed point? Just use integers and a printing routine based on the unit you want. Fixed point is indeed nice, but it has serious problems for handling intermediate calculations. For example, computing the distance between two points of magnitude O(n) requires an intermediate result of magnitude O(n*n) if you use the usual Pythagoras formula. This means you might get an overflow in the intermediate result, even if the final result would fit nicely. Floating point is useful in exactly such cases.
|
# ? Jul 20, 2017 11:41 |
|
Spatial posted:Fixed point can handle percentages just fine. For currency fixed point is always better because the precision doesn't change with the size of the operands. Except this language doesn't have fixed point, either
|
# ? Jul 20, 2017 12:26 |
|
QuarkJets posted:Except this language doesn't have fixed point, either Then what's the point?
|
# ? Jul 20, 2017 12:37 |
|
john donne posted:Then what's the point? There isn't one.
|
# ? Jul 20, 2017 13:31 |
Athas posted:What kind of language support do you envision for fixed point? Just use integers and a printing routine based on the unit you want. Just something that handles scaling in multiplication and division correctly and implicitly.
|
|
# ? Jul 20, 2017 13:42 |
|
quote:In some situations, the optimizer replaces certain numbers in the code with routines that compute different numbers
|
# ? Jul 20, 2017 14:04 |
|
QuarkJets posted:Except this language doesn't have fixed point, either No ints or bit shifts?
|
# ? Jul 20, 2017 18:09 |
|
Athas posted:What kind of language support do you envision for fixed point? Just use integers and a printing routine based on the unit you want. You answered your own question. It can be tricky to avoid intermediate overflow, so language support would take care of those mechanisms while you write straightforward code.
|
# ? Jul 20, 2017 18:33 |
|
Dylan16807 posted:You answered your own question. It can be tricky to avoid intermediate overflow, so language support would take care of those mechanisms while you write straightforward code. What would that language support do, short of just switching to floating point?
|
# ? Jul 20, 2017 18:48 |
Athas posted:What would that language support do, short of just switching to floating point? I don't know about other archs, but on x86 the integer MUL and DIV instructions respectively store the result in a register pair, and take the numerator as a register pair. Which means that for a 32 x 32 bit multiplication, the result is in fact 64 bit, and you don't have 32 / 32 bit division, but actually 64 / 32 bit division. So if the compiler knows it's working with fixed-point numbers it can generate correct MUL-DIV sequences that have a 64 bit intermediate without any additional cost.
|
|
# ? Jul 20, 2017 19:00 |
Athas posted:What would that language support do, short of just switching to floating point? Well, you could use arbitrary-precision arithmetic internally, I suppose. I can see a case for a financial language that uses bigInts and extreme-precision Decimals as the default types for internal numeric calculations. You could even throw an exception on busting the bounds of your decimal precision, forcing the user to deliberately round or expand the precision. "Solidity" is not it, though. Ed: I answered a question no one asked. I am dumb.
|
|
# ? Jul 20, 2017 19:05 |
|
When I suggested fixed point as a fundamental type, I meant in the context of a language like C. The rules would be the same as for integer arithmetic. If you use fixed point you probably know the limitations plenty well.
|
# ? Jul 20, 2017 20:07 |
|
nielsm posted:I don't know about other archs, but on x86 the integer MUL and DIV instructions respectively store the result in a register pair, and take the numerator as a register pair. Which means that for a 32 x 32 bit multiplication, the result is in fact 64 bit, and you don't have 32 / 32 bit division, but actually 64 / 32 bit division. In this case, the code would be something like: code:
code:
Also, it cannot even be known at compile-time how much precision you need for the intermediate result. Yes, for multiplication you just need to double the number of bits, but what about exponents? The only way to make this scheme work is with arbitrary size numbers (which has its owns problems), which I think you are free to use in most high-level languages. Numerics are not easy, and there is no quick fix. In general, floating point turns out to have the least warts.
|
# ? Jul 20, 2017 21:06 |
I'll try.code:
nielsm fucked around with this message at 21:34 on Jul 20, 2017 |
|
# ? Jul 20, 2017 21:27 |
|
Eela6 posted:I answered a question no one asked. Hey, this is the coding horrors thread, Jack. The enterprise architecture thread is over that-a-way. boo_radley fucked around with this message at 01:53 on Jul 21, 2017 |
# ? Jul 21, 2017 01:44 |
boo_radley posted:Hey, this is the coding horrors thread, Jack. The enterprise architecture thread is over that-a-way.
|
|
# ? Jul 21, 2017 03:09 |
|
nielsm posted:I'll try. This only works for a special case. My argument is that there is no way to do this automatically in a compiler, because the right solution is always algorithm-dependent. Also, there is no guarantee that the sum of the two squares will fit in 64 bits (consider if all of x1,x2,y1,y2 have the maximum size), so your code is not even correct for that case.
|
# ? Jul 21, 2017 06:28 |
If you need arbitrary precision and magnitude, you use an arbitrary precision library. You would have the same problem with plain integer math, and even floating point has a magnitude limit to numbers, after which the result may just clamp to Inf. However if you actually checked, you'd see that (0x7FFFFFFF**2)*2 does not overflow 64 bits, you simply get 0x7FFFFFFE'00000002. I'm not sure what 32 bit signed values you imagined could sub in for x1, x2, y1, y2 to generate a 64 bit overflow. A compiler would also be able to determine if an expression would need a bigger intermediate and automatically extend the data type, so I do believe this code could have been generated without any special casing.
|
|
# ? Jul 21, 2017 07:02 |
|
The guy who invented Solidity also wrote a buggy Ethereum smart contract that got millions of dollars stolen. There's a very nice (and extremely weaselly) article about it. It explains why it's actually *good* that this happened. From a legal perspective you can even argue that nothing was stolen, since due to the programming error the "contract" specified that arbitrary people could take the money. Sagacity fucked around with this message at 07:52 on Jul 21, 2017 |
# ? Jul 21, 2017 07:49 |
|
quote:The developer here was Gavin Wood, one of the co-creators of Ethereum, and the inventor of Solidity, the smart contract programming language. The code was also reviewed by other Parity contributors. This is basically the highest standard of programming that exists in the Ethereum ecosystem. I thought he was supposed to be downplaying the impact of this.
|
# ? Jul 21, 2017 08:37 |
|
nielsm posted:If you need arbitrary precision and magnitude, you use an arbitrary precision library. You would have the same problem with plain integer math, and even floating point has a magnitude limit to numbers, after which the result may just clamp to Inf. You're right that this won't happen in the two-dimensional case (sorry, should have checked), but you do get that it's not actually possible in general for a compiler to determine an appropriate fixed size for intermediaries, right?. Let's consider an arbitrary n-dimensional space (this also requires the compiler to work a little harder): code:
|
# ? Jul 21, 2017 08:47 |
|
|
# ? Jun 7, 2024 17:25 |
|
Athas posted:What kind of language support do you envision for fixed point? Just use integers and a printing routine based on the unit you want. Jesus, what kind of question is this. Full support of course, the same support enjoyed by floating point numbers: printing, parsing, math routines, the whole thing Athas posted:Fixed point is indeed nice, but it has serious problems for handling intermediate calculations. For example, computing the distance between two points of magnitude O(n) requires an intermediate result of magnitude O(n*n) if you use the usual Pythagoras formula. This means you might get an overflow in the intermediate result, even if the final result would fit nicely. Floating point is useful in exactly such cases. Native language support would handle and hide the overflow. It's not like we couldn't multiply 64 bit integers on 32 bit machines, there just wasn't a neat single CPU instruction to do it (there was a neat single built-in function instead)
|
# ? Jul 21, 2017 10:12 |