HNHacker News
TopNewBestAskShowJobs

nayuki

6,583 karma · joined May 31, 2011

I am a software developer.

Home page: https://www.nayuki.io/

submissionscomments
nayuki··on When oil prices spike, where does the money go?
> my superannuation fund (401k, ROTH, IRA, hard to know what people call this in other economies)

In Canada, the comparable funds are: Canada Pension Plan (CPP, mandatory contribution for all employees), employer-managed pensions (not all companies have one; policies vary such as defined benefit vs. defined contribution), personal RRSP (you make the contribution and you select the investments).

I guess the comparable funds in the USA are: Social Security (mandatory contribution for all employees), employer-managed pensions (not all companies have one; policies vary such as DB vs. DC), personal IRA such as traditional/Roth.

nayuki··on The End of a Fair Price: Dynamic Pricing and the Normalization of Gouging
> Uber is another key villain in Gouged. Per Owens, Uber’s “greatest innovation wasn’t ‘disrupting’ the taxi industry—it was socializing and normalizing the very idea of dynamic pricing. They made us comfortable with the notion that prices could change at any moment.”

In my opinion, Uber has several key innovations over traditional taxi services:

* An accurate machine-provided fare quote that you can review at your leisure before agreeing to take a trip. (Instead of, like, calling a human dispatcher to ask for a quote.)

* The fact that the passenger can't screw over the driver by making fake requests and not showing up, or running off at the end of a trip - because the online platform is in charge of the payment collection.

* The fact that the driver can't screw the passenger over by driving extra distance, because the price is set ahead of time.

> roughly 75 percent of the items in identical Instacart baskets purchased at the same time varied in price from one shopper to the next

If the price differential is large enough, it sets up an opportunity for arbitrage. Maybe if 10 people cooperate and compare notes on each of their Instacart account's product prices, and then make group purchases using the account with the lowest prices...

In general, it's harder (though not impossible) to price-discriminate on goods rather than services. If seniors get a grocery discount for example, then it might be worthwhile to hire a senior to purchase things on your behalf.

nayuki··on How SLR cameras work: Nikon F3 (2023) [video]
This comes from mitxela, the same guy who made the fluid simulation on flipdots video that went viral a few days ago ( https://news.ycombinator.com/item?id=49854219 ).
nayuki··on C's Flexible Integer Sizes Were Not a Design Mistake
Because the language rules say so, and I'm not the one who made the rules. https://en.cppreference.com/c/language/conversion#Integer_pr...

> Integer promotion is the implicit conversion of a value of any integer type with rank less or equal to rank of int or of {a bit-field of type _Bool(until C23)/bool(since C23), int, signed int, unsigned int}, to the value of type int or unsigned int.

> If int can represent the entire range of values of the original type (or the range of values of the original bit-field), the value is converted to type int. Otherwise the value is converted to unsigned int.

The fact that the C/C++ integer conversion rules have these unintuitive footguns is why I made it a talking point.

nayuki··on C's Flexible Integer Sizes Were Not a Design Mistake
> 32-by-32 signed (you multiply -1 by -1 and get 1, with no overflow)

Wrong. You mentally casted each operand to int16_t before subsequently casting to int32_t. The first step is unjustified.

The correct calculation according to the C standard is: (int32_t)0xFFFF * (int32_t)0xFFFF, which definitely overflows.

nayuki··on C's Flexible Integer Sizes Were Not a Design Mistake
> multiplying two 32-bit values, recast as 64-bit signed integers, will not overflow

Factually wrong. Consider: (int64_t)0xFFFFFFFF * (int64_t)0xFFFFFFFF. It definitely overflows.

nayuki··on C's Flexible Integer Sizes Were Not a Design Mistake
Some pieces of code in the article look suspicious:

    #define LUAI_IS32INT ((UINT_MAX >> 30) >= 3)
If unsigned int is just 16 bits wide, then `65535 >> 30` shifts by more positions than the width of the type, which should be undefined behavior, right?

    #define NB CHAR_BIT
    #define MC ((1 << NB) - 1)
If we have a DSP machine (as mentioned in the article) where CHAR_BIT is 16 and int is 16 bits, then `1 << NB` is `1 << 16` which shifts as much as the width of the type, which I believe is undefined behavior as well.

Regardless of whether you think C's flexible integer sizes are good or bad, and whether it helped propagate the language, there's no denying that if you want to write portable code across machines, you have to put in more effort compared to a language with fixed-size integers. Whether this matters or not is a matter of situation and opinion.

Other than that, I made a simulator where you can set the bit width of each integer type, and then it shows you how `x operation y` gets promoted to some output integer type. https://www.nayuki.io/page/summary-of-c-cpp-integer-rules section "Conversion rules simulator"

nayuki··on C's Flexible Integer Sizes Were Not a Design Mistake
Thank you for being one of the few people who understands that in C/C++, `unsigned OP unsigned` can have each operand be promoted to a signed integer and then have the operation overflow and cause undefined behavior.

I chose to deal with this problem by doing a "pointless" operation to force a promotion to at least unsigned int. For example:

    uint16_t x = 0xFFFF;
    uint16_t y = 0xFFFF;
    uint16_t z = (uint16_t)((x + 0U) * (y + 0U));
This piece of code will work on any machine, such as: (uint16_t = unsigned short = 16 bits, uint32_t = unsigned int = 32 bits); (uint16_t = unsigned short = unsigned int = 16 bits, uint32_t = unsigned long = 32 bits).
nayuki··on Transit rewards
If buses and cars participate in the same road traffic (i.e. the bus doesn't have dedicated lanes), then a bus trip will never be faster than a comparable car trip. This is because you have to walk to/from the bus stop at both ends of the journey, wait for a bus to show up, ride the bus and have it stop for other passengers, transfer between routes, the bus has slower acceleration and turning than a car, etc.

Think about even the most strawman trip possible: A bus rider and a car driver start exactly at the location of a bus stop, the bus shows up exactly at the start time, both contestants ride/drive straight for a few kilometres (which happens to follow exactly one bus route, without changing buses; but the bus might stop a few times along the way for other passengers), and end exactly at a bus stop. The car will win every single time.

https://en.wikipedia.org/wiki/Downs%E2%80%93Thomson_paradox , https://www.youtube.com/watch?v=RQY6WGOoYis

nayuki··on Solitaire Alone Together
Neat concept - a web remake of a classic Windows game. I found it very hard to win though, due to the "draw three" rule. I finally won on my 12th shuffle.

Aside from this web game implementation, in past decades I grew tired of solitaire and its constrained nature. I found myself enjoying spider solitaire a bit more, where you have to be more strategic about building stuff. I discovered spider because it's bundled with Windows. https://en.wikipedia.org/wiki/Spider_(solitaire)

nayuki··on The Effect of CRTs on Pixel Art (2024)
> Modern flatscreens all have fixed resolutions

True by design.

> and purely digital interfaces,

True but not relevant. Even if you connected an LCD monitor over an analog interface like VGA or composite video, it would have to re-digitize the signal. The fact that a screen uses a digital interface can be designed independently of whether a screen has fixed pixels (LCD, OLED) or not (monochrome CRT with continuous phosphor, without shadow mask or aperture grille).

> ensuring a fixed aspect (width-to-height) ratio

True by definition because the pixels are pieces of physical hardware in the screens.

> and completely square pixels.

This is a design choice. Nothing prevents someone from designing an LCD or OLED matrix with non-square pixels. But there's also no good reason to do so. (Side note: Due to RGB striping, single-color subpixels have an aspect ratio of 1:3, so those are non-square.)

Potentially useful trivia: Some image/video formats support declaring the pixel aspect ratio. Examples include PNG ( https://w3c.github.io/png/#11pHYs ) and Matroska.

nayuki··on Subnormal floating-point numbers are expensive on Intel processors
8-bit: There is no IEEE 754 standard format.

16-bit: https://en.wikipedia.org/wiki/Half-precision_floating-point_...

nayuki··on Subnormal floating-point numbers are expensive on Intel processors
Very interesting, you are right. The IEEE 754 standard defines positive/negative zero as not subnormal numbers.

Mechanically speaking, the two zeros use the subnormal number format, so in that sense they are subnormal (but definitionally they aren't). Also, I guess FPUs treat zero differently from other subnormal numbers, which is why zero doesn't have a performance penalty.

Relevant articles to read: https://stackoverflow.com/questions/73890260/why-is-zero-not... , https://en.wikipedia.org/wiki/Sterbenz_lemma , https://en.wikipedia.org/wiki/Subnormal_number

nayuki··on Pixel is a unit of length and area
I think the notion of fractional pixels is rare indeed. But I can think of one example from astrophotography. After taking a photo, we use software to analyze the size of stars - for features like autofocus, auto-guiding, and detecting smeared images. Describing the full width at half maximum (FWHM) of stars with decimal pixels is normal practice. It's akin to fitting a Gaussian function to a measured peak, and letting the Gaussian have a fractional standard deviation that isn't constrained by the integer pixel grid.

I guess on that note, video compression motion estimation/compensation can also make use of fractional pixels.

nayuki··on Pixel is a unit of length and area
Previous discussion: https://news.ycombinator.com/item?id=43769478 (176 comments) [2025-04-23]
nayuki··on Subnormal floating-point numbers are expensive on Intel processors
I can think of one useful property of subnormal numbers off the top of my head. If subnormal processing is enabled, then for all finite values of `a` and `b`, `a != b` if and only if `a - b != 0`. But if subnormals are flushed to zero, then two tiny normal distinct values `a` and `b` would have a subnormal difference that is flushed to zero.
nayuki··on Let's make quality the norm again
In certain personal projects, I have the opposite philosophy where I don't want quality. I got addicted to designing models and 3D-printing them a year ago. Over time, I learned to reduce the amount of safety factor and make items just strong enough for their application - which saves material and printing time. I wouldn't skimp on something like a carrying handle for the printer, where failure would mean damaging the printer. But I would reduce the amount of plastic used in things like art pieces (3DBenchy - who needs structural strength?), end caps for various objects, prototypes for dimensioning. Moreover, sometimes I'm happy to see my parts break because I was thinking of redesigning it or did so already, hence I would be itching to print the new version. Aside from that, just knowing I can reprint a part anytime (without modifications) makes me much less worried about breaking or losing a part.
nayuki··on Show HN: I couldn't afford interview prep, so I built a free alternative
CLRS is a wonderful book and I learned a ton from it. https://en.wikipedia.org/wiki/Introduction_to_Algorithms , https://www.cs.mcgill.ca/~akroit/math/compsci/Cormen%20Intro...
nayuki··on Show HN: Art – draw one stroke, let symmetry complete it
I experimented with this concept over a decade ago: https://www.nayuki.io/page/symmetry-sketcher-javascript

I was probably inspired by mouse-painting tools in Corel Photo-Paint (like Adobe Photoshop) that have an "orbits" feature. https://product.corel.com/help/PHOTO-PAINT/540111130/Main/EN...

nayuki··on Show HN: What if the speed of light was 5 km/h?
Pedantic note: The symbol for the speed of light constant is c (italic lowercase c). https://en.wikipedia.org/wiki/Speed_of_light

Roman lowercase c is the metric prefix centi-. Roman uppercase C is the metric unit coulomb.

Italic uppercase C has various uses such as: a variable denoting capacitance in electrical engineering; an undetermined constant of integration in calculus.

nayuki··on Hitachi launches CO2 heat pump water heaters with solar-friendly tariff controls
Likewise, many years ago, I got confused by less common meanings of the word "schedule". The most common meaning is a written or explicit arrangement of how a person or machine spends their time, particular for future planning.

The less common uses show up in examples like "Schedule I drugs" (highly banned) or various schedules in tax laws, appendices of long documents, etc.

nayuki··on Trey Parker and Matt Stone Are Changing the Name of South Park to South America
The Simpsons have lightly mocked their parent company Fox too.
nayuki··on The ColorChecker, photography's most important 24 squares, turns 50
I didn't learn much from reading this article. Questions linger in my mind, for example: What are the CIE XYZ coordinates of each colored square? What is the spectral distribution of each square? How were the colors chosen?
nayuki··on Terpstra Keyboard
> maybe a society which has laws and regulations voted by citizens (anarchy for example) commercial products shouldn't profit over 700% or some absurdity which caps the 5000 usd number

No problemo. The consequence of that law is you'll simply not get those products on the market because there's not enough profit to justify someone spending the time to make them.

See also: Rent control, minimum wage, price control (e.g. maximum price of gasoline during a shortage).

nayuki··on Move in C++ without a std:move
Kudos to the author for explaining these concepts, but I personally find this to be a poor use of my time and mental capacity.

I dabbled in C++ programming before Rust 1.0 was released (year 2015). I have spent some time understanding things like RVO, std::move(), rvalue references, T&&, move constructors, and so on. This was the main tutorial that I read a decade ago: https://web.archive.org/web/20240108142848/http://www.thbeck...

I began programming in Rust in 2017, and it is such a breath of fresh air. It has all the power of C++ but shed all the unnecessary baggage (e.g. confusing features, duplicate features).

In relation to this article, I like Rust's clear and simple semantics about moving objects. If x and y are variables of type T which implements the Copy trait, then `x = y;` performs a simple bitwise copy. Otherwise, `x = y;` moves the object `y` to `x` and `y` is no longer allowed to be accessed ("moved away"). Whereas in C++, the article states how copy elision behavior has changed over the years:

> You get guaranteed copy elision since C++17 in the following case [implying it wasn't guaranteed before C++17]

> Then you have named return value optimization (NRVO): [...] The latter is not subject to guaranteed copy elision. You probably don't pay for a copy or move there as well.

> While this code compiles, you will get a copy construction of the return value before C++20.

> Once you switch your compiler to C++23 mode, both cases do an implicit move. No std::move required.

This is why I prefer to deal with Rust instead of C++. And this is just my commentary on specifically the behavior of moves in C++. When I pile on other issues - like copious undefined behavior everywhere (e.g. signed integer overflow, array out-of-bounds accesses), too many footguns that result in bugs and security vulnerabilities - I developed an extreme distaste for programming in C and C++.

nayuki··on PageRank explained
Here are two excellent videos that explain and visualize the PageRank algorithm:

* [2020-06-17] Spanning Tree - "How Google's PageRank Algorithm Works" (5m16s): https://www.youtube.com/watch?v=meonLcN7LD4

* [2022-05-23] Reducible - "PageRank: A Trillion Dollar Algorithm" (25m25s): https://www.youtube.com/watch?v=JGQe4kiPnrU

nayuki··on Let’s take apart your phone
Humans have a bunch of digital components at their core: DNA, RNA, and peptides. It's not all analog.

Likewise, phones have numerous analog components: microphone, speaker, camera, screen, radio modem, power regulation.

Please don't equate the word "digital" to the notions of being electronic, man-made, or modern. Digital is simply an agreement between a sender and receiver that information is finite and perfectly copyable. (By contrast, analog information is infinite and cannot be copied perfectly.)

nayuki··on Let’s take apart your phone
> Petrol stores 50 times more energy by weight, but it needs to be exploded. A doughnut stores around 15 times, but it needs to be digested.

You left out a very important fact: Combustion requires external oxygen, which is not counted in the denominator when energy-by-mass is typically considered.

nayuki··on Why Can't You Pack a Bag? (2024)
https://archive.is/27YEq
nayuki··on 3D Pinball for Windows (1995)
In this port, using the menu to disable the music has no effect. Surprisingly, typing "hidden test" does have an effect, but the interpretation of mouse movements is weird and uncontrollable, unlike the original Windows EXE game.
Page 1 of 34Next →