Hacker Newsnew | past | comments | ask | show | jobs | submit | pksadiq's commentslogin

I wrote a similar tool[0] a few days back because I wanted a bit more accuracy with timestamp (to measure CPU/idle time) and `ts` occasionally had a deviation of several 10ms. If I knew this, and is accurate enough for me, I might not have written one.

[0] https://www.sadiqpk.org/projects/tis


This specific change shall excite many as CC BY-SA 4.0 is one way GPLv3 compatible, but CC BY-SA 3.0 is not. Which means that free software developers can now embedded many Wikimedia contents in their GPLv3 applications. This seems not mentioned in the blog post though.


Incompatibilities between content and code licences has been a perennial problem for FOSS video games. CC-BY-SA-4.0 is an important step in the right direction!


> x/2 + y/2 + (x & y & 0x01)

This returns -1 for x = INT_MIN and y = INT_MAX were the answer should be 0 (for an example). so not a correct solution


Isn't (32 bit) INT_MAX 2^31-1 and INT_MIN -2^31, so this is an acceptable solution (since the decimal average is -0.5)?


> since the decimal average is -0.5

The C standard says: When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded (This is often called ‘‘truncation toward zero’’).

So it should be 0 (as per C standard, not sure what C++ standard says)


The question is midpoint, not division, so that's irrelevant in the first place, and even if were division, the standard is wrong.


  int mid(int x, int y) {
    return (x/2 + y/2) + (1 & x & y);
  }
would be a more readable solution

edit: Actually, this fails on mid(INT_MIN, INT_MAX) and possibly other mixed sign values (returns: -1, expected: 0 (or -1 is okay?), where the precise answer is -0.5)

more edit: The C standard says: When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded (This is often called ‘‘truncation toward zero’’).

So -1/2 should be 0.


For signed ints, try

    (x >> 1) + (y >> 1) + (x & y & 1)
This rounds toward negative infinity. Also

    (x >> 1) + (y >> 1) + ((x | y) & 1)  // Rounds toward +Inf
    (x >> 1) + (y >> 1) + (x & 1)        // Rounds up if x is odd
    (x >> 1) + (y >> 1) + (y & 1)        // Rounds up if y is odd
I'd be curious if there's a bit-twiddling trick for rounding toward x or y.


Using the midpoint function is the most readable.

https://en.cppreference.com/w/cpp/numeric/midpoint

Though it's odd this allows overflow.


std::midpoint also seems to yield less efficient code with g++12 targeting x86-64: https://godbolt.org/z/j695ce98Y


std::midpoint does different thing in terms of rounding, therefore comparison is not fair.


Possibly true, but it yields less efficient code in GCC 12 for x86-64. https://godbolt.org/z/oafPrb4K8


Because it's also wrong! / rounds towards zero, while summing a&b&1 requires the division to round towards negative infinity.


> Programming from the Ground Up

> https://download-mirror.savannah.gnu.org/releases/pgubook/Pr...

There is an updated version of the book from the author: "Programming Under the Hood" or "Learn to Program with Assembly". See[0]

[0] https://github.com/johnnyb/programming_under_the_hood


What a great book! It was my introduction to 32-bit assembly on Linux. Learning AT&T syntax has both its advantages as well as drawbacks. I've noticed a lot of GNU code uses it, whereas reverse engineering literature loves Intel syntax, which is an interesting cultural difference.


> Why is this even a thing? Maybe I should just go back to buying everything with cash, it's impossible to keep up with all the crap we need to disable or hack around

And some agencies may be more interested in these exclusion databases. So I don't think there is any way to get out of this maze. When you sign up to exclude from a list, you get included in many other.


What’s the risk here? Am I branded as a terrorist for opting out of marketing? What’s the logic?


Lists can be used for things other than terrorists


Obviously, such as tracking who opted out of marketing based on their credit card spend.

The question is what unintended (and specifically undesirable) consequences that poses to the members of the list.


And it's much better when used with gdb-many-windows and speedbar


Note: GTK+ has been renamed to GTK about a year back[0]. The title may better be updated.

[0] https://mail.gnome.org/archives/gtk-devel-list/2019-February...


There is a Merge Request to support QR code for hotspot created in GNOME control center: https://gitlab.gnome.org/GNOME/gnome-control-center/merge_re... Hopefully, shall be available in next release


> What is the probability of something like this appearing in a normal program written by somebody who is unaware of trigraphs?

A good compiler (eg: gcc) will warn if any token is interpreted as a trigraph

Edit: digraph works a bit differently [0]

[0] https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: