Go to advanced search

by jahboater
Wed Jun 23, 2021 9:16 am
Forum: Ubuntu
Topic: Can you attach to a running process with gdb in Ubuntu on Pi?
Replies: 7
Views: 203

Re: Can you attach to a running process with gdb in Ubuntu on Pi?

For interest, it (gdb -p) works on Raspberry Pi OS - as long as the process is yours.
by jahboater
Wed Jun 23, 2021 7:36 am
Forum: Beginners
Topic: CPU in wait state over 99% of time
Replies: 4
Views: 192

Re: CPU in wait state over 99% of time

What does "vmstat" say ?

Code: Select all

vmstat 10 10
by jahboater
Mon Jun 21, 2021 1:42 pm
Forum: Beginners
Topic: How much storage do I really need?
Replies: 5
Views: 218

Re: How much storage do I really need?

Hello I'm about to get a raspberry pi and I will be using it for learning linux, programming webservers, and learning more languages, etc. I'm not sure how much storage I really need. I'm deciding rather 16gb or 32gb. What should I do? Look at the prices of Sandisk A1 cards on, say Amazon, and you ...
by jahboater
Sun Jun 20, 2021 11:42 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

Why is printf even allowed to produce more than DECIMAL_DIG significant digits? It cleary knows how many of them are gibberish by the very definition of DECIMAL_DIG. The integer part has to be printed in its entirety, so it has to print something. So I think %f is unsuitable for these very large nu...
by jahboater
Sun Jun 20, 2021 8:13 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

In the definition of `%f` I see no justification for inventing a huge pile of random digits that cannot possibly be justified by the bits of the double given. Its true elsewhere. If you gave "%.100g" say, it will print 100 sig figs, as requested, regardless of the available precision. The...
by jahboater
Sun Jun 20, 2021 8:10 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

%f prints the number as ddd.ddd and the given precision says how may digits after the decimal point (defaulting to 6). It has to print everything before the decimal in full, even if the available precision has nowhere near enough digits. In the definition of `%f` I see no justification for inventin...
by jahboater
Sun Jun 20, 2021 7:43 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

Whilst we are here, how come when I do: printf("%f\n", d); I get ludicrous output like: 898846567431157953864652595394512366808988489471153286367150405788663379027504815663542386612037680105600569399356966788293948844072083112464237153197370621888839467124327426381511098006230470597265414...
by jahboater
Sun Jun 20, 2021 5:08 pm
Forum: C/C++
Topic: atomic or volatile, that is the question ( Whether 'tis nobler in the mind to mutex them)
Replies: 74
Views: 2091

Re: atomic or volatile, that is the question ( Whether 'tis nobler in the mind to mutex them)

In this code "some_register" is not used elsewhere in your code. As it has no effect on your program the optimiser may well optimise it away completely. To avoid this use "volatile". As described here: https://barrgroup.com/embedded-systems/how-to/c-volatile-keyword and all over...
by jahboater
Sun Jun 20, 2021 4:51 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

Still, we have a simple example code here that behaves differently with different machines and compilers. I consider that as bad as having some kind of mathematical proof that causes different mathematicians to come to different conclusions. We would not like that would we? Compilers don't call thi...
by jahboater
Sun Jun 20, 2021 10:00 am
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

Heater, You might find these GCC builtins useful for testing: double x; x = __builtin_inf(); // Positive Infinity (or use the C99 standard macro INFINITY) x = __builtin_nan("0"); // Quiet NaN - tag bits zero x = __builtin_nans("0"); // Signaling NaN - tag bits zero They should wo...
by jahboater
Sun Jun 20, 2021 8:55 am
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

I see that -ffast-math turns on -ffinite-math-only, which I find surprising as this disallows non-finite values. -ffast-math Sets the options -fno-math-errno, -funsafe-math-optimizations, -ffinite-math-only, -fno-rounding-math, -fno-signaling-nans, -fcx-limited-range and -fexcess-precision=fast. Thi...
by jahboater
Sun Jun 20, 2021 6:07 am
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

It's the "-ffinite-math-only", which apparently does break standards compliant code. Oddly producing different behaviour with gcc-10 and clang 12.0.5 on my Mac Book, where it always detects infinity, vs gcc 7.5 on a Jetson NX, where it fails to detect infinity. By using "-ffinite-mat...
by jahboater
Sat Jun 19, 2021 10:31 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

Years ago, I saw that the compiler was producing checks for NaN's before each and every "x > y" sort of floating-point comparison.
Proving that it was "ordered".
It doesn't seem to do that now, I don't know why.
-ffinite-math-only removed those checks of course.
by jahboater
Sat Jun 19, 2021 10:25 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

The results are different on my Pi. Without the -ffinite-math-only option it behaves as your code does. With the -ffinite-math-only option it fails to spot the infinity condition because the check has been removed, and loops forever. That's as expected I suppose. $ ./try 2.000000 8.000000 88.000000 ...
by jahboater
Sat Jun 19, 2021 10:17 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

It does produce different code. This is for the Pi4 in 64-bit mode with GCC 11.1. As you can see there is quite a lot more code without the option. This is very interesting, its years since I last looked at it. In the "without option" code it refers to isinf() (which has been elided from t...
by jahboater
Sat Jun 19, 2021 8:38 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

Because I'm daft I have just been trying to craft an example where using "-ffinite-math-only" did cause a program to behave differently :) If you succeed with finite values, then perhaps raise a bug. You would expect the handling of NaN's etc to be different of course, that's the point of...
by jahboater
Sat Jun 19, 2021 8:16 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

-ffinite-math-only Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or +-Infs. This option should never be turned on by any -O option since it can result in incorrect output for programs which depend on an exact implementation of IEEE or ISO rule...
by jahboater
Sat Jun 19, 2021 7:07 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

Perhaps that is not a big deal for you. It niggles me. It doesn't niggle me because: Left to itself the compiler will produce correct code that complies with IEEE 754 (so be consistent and reproducible) and will be as accurate as possible. I believe this is true for Fortran and C with their vast us...
by jahboater
Sat Jun 19, 2021 4:57 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

If whatever magic compiler switch changes the observable behaviour of whatever data type then a reader of the source cannot tell what happens simply from the source he is reading. That is the thing that niggles me. Apart from the execution, time the observable behaviour does not change . So no need...
by jahboater
Sat Jun 19, 2021 4:09 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

But then my question is: If the observable behaviour is the same then why is there a need for the magic switch? Why not just do that all the time at -O3 or whatever? Like all other standard compliant optimisations that follow the "as if" rule. I think the compiler always has to cover all ...
by jahboater
Sat Jun 19, 2021 2:05 pm
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

cppreference.com tells me : undefined behavior - there are no restrictions on the behavior of the program. Examples of undefined behavior are data races, memory accesses outside of array bounds, signed integer overflow .... Yes, that's true now. But it wont be in time. Your link above says:- [P0907...
by jahboater
Sat Jun 19, 2021 10:00 am
Forum: Advanced users
Topic: Maximum stable overclocking speed of a Pi 4 or 400
Replies: 55
Views: 2127

Re: Maximum stable overclocking speed of a Pi 4 or 400

Many overclockers seem to be pushing more than 2GHz. Yes. I tend to be rather conservative with overclocking, I like to have a good margin of safety to avoid throttling or possible instability. But for some time now I have been running a Pi4 at 2.1GHz with never a problem. It doesn't throttle under...
by jahboater
Sat Jun 19, 2021 9:49 am
Forum: General discussion
Topic: MicroSD card failures after 6months or so.
Replies: 7
Views: 404

Re: MicroSD card failures after 6months or so.

It would be nice to have this a standard in the OS; I use it even on 1MB models. I use it on my 256MB model Pi1 :) Works fine. I ran UNIX on an Amdahl mainframe long long ago (early 80's) and its /tmp was in memory even then. It is common amongst distros now. I presumed Pi OS did not because of the...
by jahboater
Sat Jun 19, 2021 9:16 am
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

Type "uint64_t" is defined to be a two's complement binary integer... Nope. two's comp is a representation of singed integers not unsigned. But I know what you mean. My bad. I wrote that too quickly! Yes I would hope that unsigned integers are the same everywhere. I'm not convinced about ...
by jahboater
Sat Jun 19, 2021 8:20 am
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 58
Views: 1589

Re: TIL: "==" is not "is equal" for "double"

Depending on architecture and likely the compiler implementation. Type "double" has a fixed format for all C implementations ISO/IEC 60559 (IEEE 754 binary 64). Type "uint64_t" is defined to be a two's complement binary integer (defined by the language standard I believe). True ...

Go to advanced search