HNHacker News
TopNewBestAskShowJobs

SloopJon

2,602 karma · joined November 15, 2013

submissionscomments
SloopJon··on A Special Kind of Hell: intmax_t in C and C++
Yeah, min() returns the most negative int, so it seems like it should do the same for float. Then the float with the least magnitude could have been, say, smallest().
SloopJon··on A Special Kind of Hell: intmax_t in C and C++
I used intmax_t just yesterday in an ODBC type conversion test. I wrote a template for use in a Google Test typed test to find the highest and lowest values supported by the client and server type. Something like:

  max(
    static_cast<intmax_t>(
      numeric_limits<T>::lowest()),
    static_cast<intmax_t>(
      numeric_limits<U>::lowest()))
I tried std::common_type first, but it didn't quite do the trick.
SloopJon··on Std::visit is everything wrong with modern C++ (2017)
> > Long ago "modern" C++ crossed into a territory that I will never understand or use.

> Do you know where the line is? C++11? Later versions?

It's funny to read this, because I purposely avoided C++ for the better part of twenty years after dabbling with it in college--not worth it to deal with so much complexity. I've started using it in the last couple of years for work, and the modern part is what makes it bearable.

C++ is a big beast, so there is a cost to each new standard simply by virtue of adding features. However, the types of things I want to use in C++14 are pretty simple and worthwhile; e.g., better constexpr functions, and the _t aliases (like std::enable_if_t<>, rather than typename std::enable_if<>::type). Similarly, C++17 has a few new templates, like std::optional and yes, std::variant, along with ergonomic improvements like the _v aliases (like std::is_floating_point_v<>, rather than std::is_floating_point<>::value).

Now that the glacial pace of standardization has been replaced with a three-year cycle, I almost want something like LTS releases. I use C++11, and a bit of C++14, but when is it safe to use C++17 or C++20?

SloopJon··on How To Safely Store A Password (2010)
Do I understand correctly that you cracked about half of the 12,000-iteration PBKDF2 hashes using a first-gen ThreadRipper and a GTX 1060, and would have cracked more except for a formatting problem in the hashes? That's eye opening.

Is Word Machine publicly available, or is it the sort of thing that has an audience of one?

SloopJon··on M1 Macs: Truth and Truthiness
I read Gruber frequently even though he annoys me (he's sort of like John Dvorak that way), and this piece is kind of emblematic of why he does. To be clear, the ARM Macs are way more exciting than I expected, and I'll probably buy one at some point. I also do not think Moorhead's Fortune article was perfect, but Gruber's righteous indignation is grating.

These statements are pitted against each other, even though they are both very much true:

> emulating or translating apps ... is necessarily going to be ... somewhat incompatible at best ... But Apple’s Rosetta 2 ... is a technical marvel.

He's upset about this quote from Moorhead's review:

> there were some very positive things about the new laptop. The new M1 processor is impressive, but far from perfect — it has many warts

Moorhead perhaps punctuated this poorly, but I think it's reasonable to assume that the warts refer to "the new laptop" in general, not just "the new M1 processor" in particular. Yes, his problems are generally software related (although he cited fan noise as a complaint), but that's a huge part of the product. Lots of people would love to use an M1 Mac without macOS, including one particular Finn.

Gruber can say, "There is no 'Well, here’s the downside' with regard to the state of Apple Silicon," but that remains to be seen. How much of the M1's advantage is due to a trillion dollar company buying up every last bit of TSMC's 5nm production capacity? Can they scale the unified memory architecture much beyond 16 GB? If they can, great; they've truly lapped the field.

> There is no balance, if by balance, you’re looking for a story that says any PC hardware, ARM or x86, is competitive in any way with the M1 Macs for low-energy computing.

This review wasn't about "low-energy computing." It was about using a new Mac as a replacement for an old Mac. This is a real, shipping product, not a beta. You can snicker at Moorhead's Microsoft-centric workflow and choice of apps., but that's his perspective.

SloopJon··on John Carmack on Inlined Code (2014)
It's hard to discuss in the abstract, especially with bad names like MinorFunction1() and MinorFunction2(). In style C, you may have to scan over lower levels of abstraction than you care about:

  MajorFunction() {
    // fast inverse square root
    float x2 = number * 0.5F;
    float y = number;
    // several more lines of code

    // find decimal point
    char *c = input;
    while (*c && *c != '.')
      ++c;
  }
A goal of style A or B is for the names of the minor functions to make the shape more obvious, ideally self documenting:

  MajorFunction() {
    y = Q_rsqrt(number);

    char *c = strchr(input, '.');
  }
This is the kind of advice you'll find in, say, Code Complete. Although I generally accept the premise, there is a readability cost to indirection. The bigger and more complex MinorFunction() is, the more likely I'm going to have to jump into it and remind myself what it does.

There are two concepts that underlie DRY: coupling and cohesion. There are good expositions on this in old writings on structured programming and design (e.g., Yourdon and Constantine). If MinorFunction() is cohesive, and MajorFunction() is appropriately coupled to MinorFunction(), then style A/B is likely to be superior to style C. One of Carmack's points is that "very little of our real code" ends up that way.

SloopJon··on Write your own arbitrary-precision JavaScript math library
I've been noodling with Hans Boehm's constructive reals package since the "Toward an API for the Real Numbers" post:

https://news.ycombinator.com/item?id=24700705

The Android calculator app. got some nice usability improvements by using a combination of rationals, as described in this story, and recursive (aka constructive or computable) reals.

A previous post on Microsoft's calculator brought my attention to an old package it uses called Ratpack (aka ratpak), another implementation of rationals:

https://news.ycombinator.com/item?id=19321217

It has some nice properties for use in a calculator, but it can be quite slow.

When I come across a library with, shall we say, an exotic numeric representation, it's nice to have a library of mathematical functions included. I see that python-cf indeed includes a solid batch.

SloopJon··on Write your own arbitrary-precision JavaScript math library
In Python 2, int and long were separate types, where int was either a 32- or 64-bit signed integer, and long was arbitrary precision. Python 3 unified the types under the name int:

https://www.python.org/dev/peps/pep-0237/

This was a nice enhancement with very few drawbacks, but I can see how it wouldn't necessarily be appropriate in Go.

SloopJon··on Why is day of the month 1-indexed but the month is 0-indexed in C?
Although the source for the fourth edition is not available, the man page for the ctime(3) library function is:

https://minnie.tuhs.org/cgi-bin/utree.pl?file=V4/man/man3/ct...

It confirms that the day of the month element was one based. This function is different in earlier editions:

https://minnie.tuhs.org/cgi-bin/utree.pl?file=V3/man/man3/ct...

https://minnie.tuhs.org/cgi-bin/utree.pl?file=V1/man/man3/ct...

SloopJon··on Apple MacBook Pro 13” M1 Review- Why You Might Want to Pass
> Apple did not promise anything wrt. 3rd party apps

Of course they did: "With the introduction of Rosetta 2, M1 and macOS Big Sur seamlessly run apps that haven't yet transitioned to Universal versions. So without updating, you can keep working on Fusion360 projects or reach the next level in your favorite game."

Rosetta 2 (and Rosetta before it) may be an amazing technical accomplishment, but it's entirely fair for a reviewer to say it doesn't cut it for him. As funny as some of his choices are (Edge on a Mac, on purpose?), he's not reaching; this is what he uses everyday. It's also fair to point out that if your favorite game doesn't happen to be Rise of the Tomb Raider, your mileage may vary.

I think the reviewer is a little unfair in his emphasis on "Apple-chosen" reviewers, but this frankly is the kind of thing I look for. Five-star reviews are rarely as useful to me as three-star reviews.

SloopJon··on Leveraging ML Compute for Accelerated Training on Mac
For those who read the comments before the article, the initial batch of comments are burying the lede:

> The new tensorflow_macos fork of TensorFlow 2.4 leverages ML Compute to enable machine learning libraries to take full advantage of not only the CPU, but also the GPU in both M1- and Intel-powered Macs for dramatically faster training performance.

This isn't about being locked in to some Apple framework. TensorFlow for Mac is accelerated again. (As Gruber likes to say: finally!)

SloopJon··on Emojis paved the way for UTF-8 everywhere
Surrogates are technically a UTF-16 only thing. Realizing that sometimes they nevertheless escape out into the wild, WTF-8 defines a superset of UTF-8 that encodes them:

https://simonsapin.github.io/wtf-8/

To be clear, this is not an official Unicode spec. It's a hack (albeit a pretty natural and obvious one) to deal with systems that don't do Unicode quite right.

I recently came across some old code that narrows wchar_t to UCS-2 by zeroing out the high-order bytes. Even though my test was careful not to generate any surrogates in the input, they showed up in the output when a randomly generated code point like U+1DF7C was mangled into U+DF7C.

A corrupted value like that is not necessarily a great example of something you want to preserve, but it's the sort of thing that late 90s code assumed about Unicode.

SloopJon··on My Priceless Summer on a Maine Lobster Boat
Indeed, the author writes of the captain she worked for:

> Originally from Connecticut, she worked one summer on a whale-watching boat in Bar Harbor, saw the lobstermen, and thought: I want to do that, that looks real.

SloopJon··on macOS Big Sur
One of my round tuit projects is to set up a Snow Leopard VM to run PowerPC apps. with Rosetta, and a Mojave VM to run 32-bit Intel apps.
SloopJon··on .NET 5.0
Note that .NET 5.0 is not an LTS release:

> .NET 5.0 is a current release. That means that it will be supported for three months after .NET 6.0 is released. As a result, we expect to support .NET 5.0 through the middle of February 2022. .NET 6.0 will be an LTS release and will be supported for three years, just like .NET Core 3.1.

SloopJon··on AMD/aocl-libm-ose: AMD libm
Here's a page to download Linux binaries:

https://developer.amd.com/amd-aocl/amd-math-library-libm/

The license there looks much less friendly than the 3-clause BSD on Github.

I was unable to build this on macOS 10.13, because "aliases are not supported on darwin".

I'm curious to see the tests, which have not been checked in yet. There was a story a month ago about the Android calculator's library, and how it is used to test java.lang.Math:

https://news.ycombinator.com/item?id=24700705

I wonder what this library's accuracy tests look like.

I'm also curious, of course, to see what kind of performance difference there is. An old post by Agner Fog shows an 85% reduction in run time relative to glibc on AMD hardware:

https://www.agner.org/optimize/blog/read.php?i=209

SloopJon··on HP Instant Ink is “ink as a service”
That actually wasn't true when I bought a Canon MG6000-something. When the price of the printer went below the price of ink, I bought a second one and stuck it in the attic, which came in handy when the first one died. Both printers came with standard ink cartridges.

The HP laser printer I bought recently, on the other hand, did come with starter cartridges with a smaller amount of toner. My impression is that starter cartridges are more common with toner than ink.

SloopJon··on Rendering floating numbers: advances in problems you didn’t know you had (2011)
If I understand correctly, it's a printf-style function for which the %g format code outputs the shortest decimal string that round trips. This implies that it would output no more than seventeen significant figures, regardless of the requested precision.

The first thing I notice is this comment in a later changelog:

> I believe we have a very fast numerical conversion that appears to be reliably generating about 15 to 16 digits out output [last digit may be off by 1 or 2 in typical case].

If the last digit of a fifteen- to sixteen-digit output is off by one or two, are we sure it round trips?

Second, the test coverage for this feature in tests/format.cpp looks pretty sparse, and it's not obvious to me how the output is verified.

Interesting find. I may play around with this later.

Edit: I tried the test cases from here:

https://www.exploringbinary.com/the-shortest-decimal-string-...

Here's the result:

format="%.30g" output="0.1"

format="%.30g" output="50388143.06823721984"

format="%.30g" output="54167628.18"

format="%.30g" output="9161196241250.051072"

The first and third cases output the correct string. The second case outputs nineteen digits, instead of seventeen, and does not round trip (i.e., it rounded incorrectly). The last case outputs nineteen digits instead of fifteen, but does round trip.

SloopJon··on Rendering floating numbers: advances in problems you didn’t know you had (2011)
I think Python was the first to bring this into my consciousness. See this enhancement request, which changed the float-to-string conversion from seventeen significant figures to shortest:

https://bugs.python.org/issue1580

After they did that, I learned that Scheme specifies similar behavior. In fact, I think it was added to R4RS after the Steele and White paper. As the article says, this behavior spread across languages, so that it's weird to see something different now.

If you want to nerd out on this, here are a few other posts that explore the topic:

https://www.exploringbinary.com/the-shortest-decimal-string-...

https://www.exploringbinary.com/the-shortest-decimal-string-...

https://www.exploringbinary.com/java-doesnt-print-the-shorte...

SloopJon··on Consumer Reports: Cadillac's Super Cruise Outperforms Tesla's Autopilot
I'm in the market for a new car with decent driver assistance, so a round up like this is just what I've been looking for. One of the first things that stands out is what Mazda told Consumer Reports about its Lane Departure Warning System with Lane-keep Assist:

> Mazda responded that its system was not designed or intended to center the vehicle in a lane and that the automaker doesn’t believe its vehicles are equipped with technology that meets the criteria CR is using in its evaluation.

Not necessarily something I would have understood from its website or brochure. This probably takes the CX-5 off of my short list.

Incidentally, the submitted title casts this as Cadillac vs. Tesla, but the actual title is "Cadillac's Super Cruise Outperforms Other Driving Assistance Systems." In fairness, their 2018 article did have a similar title: "Cadillac Tops Tesla in Consumer Reports' First Ranking of Automated Driving Systems."

SloopJon··on 1Password for Linux beta
I definitely have some password manager anxiety. I'm not too concerned about hacks or losing my password database. For me, it's more about the sense of independence, and being able to log in to my accounts using just my noggin. I might be able to remember one or two strong passwords, but not dozens, which is kind of the selling point of a password manager.

I use KeePassXC with a password and key file. I sync the database, but not the file, using Syncthing. On the whole a satisfied customer, although the browser integration isn't perfect.

SloopJon··on Firefox 82
> Restoring a session is 17% quicker, meaning you can more quickly pick up where you left off

I actually wouldn't mind if they throttled this a bit. I keep a tab or two (dozen) open to Hacker News posts I haven't gotten around to reading yet. I dread restarting the browser, as several tabs inevitably end up displaying the "Sorry, we're not able to serve your requests this quickly" page.

SloopJon··on A Family of Better Random Number Generators
> If the results are reliant on your RNG method I would not settle for less than crypto strength

Whenever a post on PRNGs comes up, I'm reminded of this post from a while back about Chrome:

https://medium.com/@betable/tifu-by-using-math-random-f1c308...

Near the end is a Monte Carlo estimate of Pi using 10^10 iterations:

  Chrome  3.1418697000 0.0002770464 1301.903s
  Firefox 3.1416998084 0.0001071548  249.595s
  Safari  3.1416692728 0.0000766192 7172.207s
The first observation is that the error was significantly higher for Chrome. The second is that Safari, which apparently did use a CSPRNG, was an order of magnitude slower. If you let Firefox run that long, I imagine that it would have performed many more iterations, resulting in much lower error.
SloopJon··on Visidata 2.0
I looked at the dizzying list of install options, then noticed pip at the top. After installing into a virtual environment, I found a tutorial that said to run the vd command. I wasn't sure if pip would install a command in my path, and it didn't. I tried to run it as python -m visidata, and got a ModuleNotFoundError for _curses.

Is it possible to get this thing running on Windows, or do I need to do it under WSL (or another computer)? Google turned up a package called UniCurses "with syntax close to that of the original NCurses."

Edit: I found Windows wheels for curses here:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses

And there is a visidata.exe in the virtual environment, which I presume is equivalent to the vd command.

SloopJon··on Custom Allocators Demystified
> No, just use address sanitizer

In fairness, the next sentence in the post is:

> Techniques like this can be a nice complement to external tools like Valgrind or AddressSanitizer.

SloopJon··on Google’s Supreme Court faceoff with Oracle was a disaster for Google
I saw one question from Gorsuch quoted in reports about the arguments that bothered me: "What do we do about the fact that the other competitors, Apple, Microsoft ... have, in fact, been able to come up with phones that work just fine without engaging in this kind of copying?"

macOS and iOS (and indeed Apple itself) would not exist as we know them today, if at all, without very liberal cross pollination of APIs. In a parallel universe where APIs are copyrighted to the extent that Oracle wants, GNU would not exist. Konqueror and Safari could not use Microsoft's XMLHttpRequest(). The list goes on and on.

SloopJon··on Toward an API for the Real Numbers
I haven't read the paper yet, but if I understand the post correctly, this interface represents numbers as the product of a rational and a recursive real, where the latter may be 1.
SloopJon··on Boa: an experimental Javascript lexer, parser and compiler written in Rust
I guess technically, the title should be "Boa release v0.10." Better?

Rather than curse the darkness, I'll quote the first sentence from the page: "Boa is an experimental Javascript lexer, parser and compiler written in Rust." What's so great about this particular release? "v0.10 has been the biggest release to date, with 138 issues closed!" Also, there's a test suite: 38,706 tests, of which 6,895 passed and 5,748 were ignored, for a conformance rate of 17.81%.

SloopJon··on RTX3090 TensorFlow, NAMD and HPCG Performance on Linux
Enroot sounds interesting:

https://github.com/NVIDIA/enroot

It basically returns containers to their chroot origins, promising "no performance overhead." I'm looking forward to more posts on that.

SloopJon··on Split Keyboard for Professionals
> I rebound the left space bar to the Command Key

My left space bar is backspace. I sometimes get confused when I switch to a different keyboard, though.

← PreviousPage 10 of 26Next →