Live data from Hacker News

Pretty.c

github.com

191–200 of 227 posts

Re: Pretty.c

#191
post #189

Earlier quoted context omitted.

what // FLT_EPSILON == 0.01 equal(4.999, 5); // true 4.999 == 5; // false am i missing?

FLT_EPSILON is not 0.01, it's 0.00000011920929. But it's impossible to have a number that's 0.00000011920929 less than 5.0, or 0.00000011920929 more than 5.0, because the floats with enough magnitude to represent 5 are spaced further apart than that. Only numbers with magnitude In other words, the only 32-bit float that's within ±0.00000011920929 of 5.0 is 5.0 itself.

Oh you're right, thanks for the explanation!

Gotta research now where the 0.00000011920929 number comes from...

Re: Pretty.c

#192
post #189

Earlier quoted context omitted.

FLT_EPSILON is not 0.01, it's 0.00000011920929. But it's impossible to have a number that's 0.00000011920929 less than 5.0, or 0.00000011920929 more than 5.0, because the floats with enough magnitude to represent 5 are spaced further apart than that. Only numbers with magnitude In other words, the only 32-bit float that's within ±0.00000011920929 of 5.0 is 5.0 itself.

Oh you're right, thanks for the explanation! Gotta research now where the 0.00000011920929 number comes from...

It's the distance between 1.0 and the next representable float.

Re: Pretty.c

#193
post #179
post #119

Earlier quoted context omitted.

#include "pretty.h" void print_int(int value){ println(value); } int main (int argc, string argv[]) { long value = 23849234723748234; print_int(value); } How is this strongly typed? $ cc test.c -o test && ./test -1411401334 And to be clear, weak vs strong isn't a boolean property but a spectrum, but would be hard to argue with a straight face than C is a strongly typed language.

C is likely the only example of a programming language that is clearly statically typed while at the same time being weakly typed. For a reason: as your example shows, it's a really bad idea (but understandable for a language from the 60's).

C is from the 1970s.

Java is weakly typed in its generics, despite being statically typed. I’m sure there are more examples.

Re: Pretty.c

#195
post #87
post #59

Earlier quoted context omitted.

"indefinitely" might be a better name. (But I think loop is indeed a better name.)

Added in commit ef510ca!

I hope you also add a “definitely”, for symmetry.

Re: Pretty.c

#197

Earlier quoted context omitted.

Oh you're right, thanks for the explanation! Gotta research now where the 0.00000011920929 number comes from...

It's the distance between 1.0 and the next representable float.

I got that but I am curious how to derive that number.

Is it representable as a non-trivial ratio of integers?

Re: Pretty.c

#198

Earlier quoted context omitted.

It's the distance between 1.0 and the next representable float.

I got that but I am curious how to derive that number. Is it representable as a non-trivial ratio of integers?

Good question! It's 1/(2**23), because 32 bit floats have 23 bits after the decimal point

Re: Pretty.c

#199
post #69

It claims to be a scripting language but you still have to compile the programs. Boo! Add CINT ( https://root.cern.ch/root/html534/guides/users-guide/CINT.ht... ) and you can have instantaneous execution and even a REPL!

Given the idea behind this repo is to cause pain, why not add a shebang to your file [0] to make it executable. I saw a blog post a long time ago that went into the details of how ./foo worked, and how it executed an elf file. You could register `.c` programs in the same way to be compiled and run? [0] https://gist.github.com/jdarpinian/1952a58b823222627cc1a8b83...

Now I have a very evil idea: what about registering a binfmt handler for the header bytes “#include”? Sure, it doesn’t handle all C/C++ programs (notably any program that dares to start with a comment), but it would not require modifying any source code!

(For even more insanity I guess you could also trigger on // and /*, although there’s some risk of false positives then!)

Post reply on HN