Live data from Hacker News

Pretty.c

github.com

11–20 of 227 posts

Re: Pretty.c

#11
post #8

`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?

Is What Every Computer Scientist Should Know About Floating-Point Arithmetic wrong ??!!

addendum: why are obviously rhetorical questions are taken so literally here?

Re: Pretty.c

#12
> Deprecate Lua, Python, JavaScript, Ruby and a dozen other languages, because Pretty C is the ultimate scripting language, but lightning-fast and strongly typed!

Umm… that’s quite the goal.

I’ll stick with deprecated Python.

Re: Pretty.c

#13
Type names are nice; Perfect choice for the in-built func macros (like min); Len -- love it. Named boolean operators -- might be a bit much but go for it; Ternaries are illegible so you can only improve them; Not completely sold on all your loop definitions but some make sense to me; Resource tracking is impressive; The for... look a bit ugly -- could probably call it something else.

All in all: quite a solid attempt. I'll give you 8/10 for the design of this. The way you sketched this out in C using macros is really elegant. This actually looks like good code. Would I use it? It's a new language and I like C already. It could help people learn C and think about language design. Since the way you've done this is very clear.

Re: Pretty.c

#14
post #10

I'm reminded of the guy who did #define BEGIN { #define END } and a whole bunch of other macro-larkey just to make C look more like Pascal. Only then would he deign to code in it.

https://en.wikipedia.org/wiki/Stephen_R._Bourne

https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh

Re: Pretty.c

#15
post #8

`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?

it uses absolute difference epsilon equality ('close enough to be considered equal'):

    static int pretty_float_equal (float a, float b) { return fabsf(a - b) 

Re: Pretty.c

#16
post #8

`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?

static int pretty_float_equal (float a, float b) { return fabsf(a - b) < FLT_EPSILON; }

Re: Pretty.c

#18
post #15
post #8

`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?

it uses absolute difference epsilon equality ('close enough to be considered equal'): static int pretty_float_equal (float a, float b) { return fabsf(a - b)

This is wrong code. It only works somewhat correctly when a and b around 1.

Re: Pretty.c

#19
post #11
post #8

`equal(0.3, 0.2 + 0.1); // true` how is this wizardry possible?

Is What Every Computer Scientist Should Know About Floating-Point Arithmetic wrong ??!! addendum: why are obviously rhetorical questions are taken so literally here?

Because text doesn't convey sarcastic voice tonality, so the intent is far from obvious.

Re: Pretty.c

#20
post #15

Earlier quoted context omitted.

it uses absolute difference epsilon equality ('close enough to be considered equal'): static int pretty_float_equal (float a, float b) { return fabsf(a - b)

This is wrong code. It only works somewhat correctly when a and b around 1.

Yeah, should be scaled like |x - y| <= ε * max(|x|, |y|)
Post reply on HN