Go to advanced search

by Paeryn
Sat Jun 19, 2021 8:32 am
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 47
Views: 1143

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

The result is defined , but it's unspecified as to what that result is. If compiled using the same compiler on the same architecture then you should always get the same result. It isn't the unruly Undefined Behaviour, just its younger sibling Unspecified Behaviour who is well mannered and tries to b...
by Paeryn
Sat Jun 19, 2021 12:51 am
Forum: C/C++
Topic: TIL: "==" is not "is equal" for "double"
Replies: 47
Views: 1143

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

Because according to the standard: "It is undefined behavior to read a union member with a different type from the one with which it was written. " That's old wording, as jahboater said earlier C18 states that the parts of the union holding the value for the reading member will be reinter...
by Paeryn
Wed Jun 16, 2021 4:40 pm
Forum: C/C++
Topic: Geany C: Code works correctly only with debugger
Replies: 22
Views: 782

Re: Geany C: Code works correctly only with debugger

A "correct" way to do this that I have seen is to use a volatile union. Something along the lines of volatile union { float f; uint8_t b[4]; } tmp; memcpy(tmp.b, rx_buff+4, 4); // or byte by byte if you prefer mtr_w[cnt] = (double)tmp.f; By making it volatile, you are telling the compiler...
by Paeryn
Mon Jun 14, 2021 4:40 pm
Forum: C/C++
Topic: Schrödinger's Code - Undefined behavior in theory and practice
Replies: 85
Views: 3132

Re: Schrödinger's Code - Undefined behavior in theory and practice

Is there a general programming language that retains or can retain numbers as general fractions as opposed to fractions of the base? It wouldn't be that difficult to implement, simplification (factorisation) of the fractions would not be needed internally so speedwise it would not be a great impact...
by Paeryn
Mon Jun 14, 2021 12:04 pm
Forum: C/C++
Topic: GCC Linker problem
Replies: 9
Views: 420

Re: GCC Linker problem

Thank you for your effort and patiences. Yes, I know where to add libaries and I did what you suggested. Now the LIB make part is: ################################################################################ # Automatically-generated file. Do not edit! ##########################################...
by Paeryn
Mon Jun 14, 2021 10:56 am
Forum: C/C++
Topic: GCC Linker problem
Replies: 9
Views: 420

Re: GCC Linker problem

I've not used Eclipse for a long time but a quick search with Google says you put the linker settings in Project->Properties->C/C++ Build->Settings->Tool Settings Then choose Cross GCC Linker->Libraries->Libraries and add the libraries needed there. You won't be able to use pkg-config there but if y...
by Paeryn
Mon Jun 14, 2021 9:45 am
Forum: C/C++
Topic: GCC Linker problem
Replies: 9
Views: 420

Re: GCC Linker problem

The error messages suggests that a library which provides the missing symbols hasn't been given to the linker. What was the command line you used to compile? Basic usage of glib will just need the following adding to link line. $(pkg-config --libs glib-2.0) But if you use gobject then change that to...
by Paeryn
Sat Jun 12, 2021 6:11 pm
Forum: Beginners
Topic: [SOLVED] Log viewer software and how to perform boolean searches in package manager?
Replies: 4
Views: 181

Re: Log viewer software and how to perform boolean searches in package manager?

It's still not perfect - it matches 'electrophysio log ical' too. If I could remember how to grep for word boundaries I'd use that. If you want grep to only match whole words then pass -w to it, or you can use \< and \> to match the start of or end of a word (you'll need to quote the search term if...
by Paeryn
Fri Jun 11, 2021 11:23 am
Forum: Python
Topic: I need help with "IndexError: list index out of range"
Replies: 12
Views: 521

Re: I need help with "IndexError: list index out of range"

No, according to the OP lines is obtained using f.readlines() which returns a list of strings, each string being one line of the file, so lines[0] is a string containing the first line of the file. Point taken. Let me offer my appologies. I obviously wasn't firing on all cylinders yesterday. I'd bl...
by Paeryn
Thu Jun 10, 2021 10:31 pm
Forum: C/C++
Topic: gmp (Gnu multiple precision arithmetic lib) 5x faster on intel i7 than on Pi400 (two samples)
Replies: 138
Views: 7449

Re: gmp (Gnu multiple precision arithmetic lib) 5x faster on intel i7 than on Pi400 (two samples)

so it may only have a single avx512 core Two CPUs on that machine as shown before, and each has 2 AVX-512 FMA Units, so 4 in total: https://ark.intel.com/content/www/us/en/ark/products/120483/intel-xeon-gold-6126-processor-19-25m-cache-2-60-ghz.html ... so if you only have 24 threads worth of work,...
by Paeryn
Thu Jun 10, 2021 9:50 pm
Forum: Python
Topic: I need help with "IndexError: list index out of range"
Replies: 12
Views: 521

Re: I need help with "IndexError: list index out of range"

Yes but lines[0] returns only the first character of lines. Guess what? That'll always be one character long so can never be equal to "YES" If what you actuall want is the last three characters of the first line in lines, try this: while lines.splitlines()[0].strip()[-3:] != 'YES': No, ac...
by Paeryn
Thu Jun 10, 2021 8:54 pm
Forum: C/C++
Topic: Schrödinger's Code - Undefined behavior in theory and practice
Replies: 85
Views: 3132

Re: Schrödinger's Code - Undefined behavior in theory and practice

Arm's fpu (and hence I assume IEEE 754) will return NaN if the numerator and denominator are both zero or both inf. This will flag an FP_InvalidOperation exception. If the numerator is inf. or the denominator is 0 then the result is +inf. if they have the same sign or -inf. if they have different si...
by Paeryn
Thu Jun 10, 2021 8:03 pm
Forum: C/C++
Topic: Schrödinger's Code - Undefined behavior in theory and practice
Replies: 85
Views: 3132

Re: Schrödinger's Code - Undefined behavior in theory and practice

x = y / 0; There is no integer representation for infinity. It doesn't matter that there is no integer representation of infinity since y / 0 doesn't equal infinity. Assuming 5 / 0 did equal inf. then reversing it you'd add up an infinite number of zeros but you'll find that you're still 5 short. D...
by Paeryn
Thu Jun 10, 2021 7:14 pm
Forum: Python
Topic: Odd Caching issue
Replies: 2
Views: 184

Re: Odd Caching issue

while True: doorbell_sensor.wait_for_press() date_string = time.strftime ('%y%m%d%H%M') time_log = open ('/home/pi/data/door_log.txt', 'a+') time_log.write (date_string + "\n") # calls pi2 to take photo etc process = subprocess.Popen("ssh pi2 /home/pi/bin/take_still.sh", shell=T...
by Paeryn
Thu Jun 10, 2021 2:15 pm
Forum: Advanced users
Topic: What's /usr/bin/dash and why should I care?
Replies: 17
Views: 561

Re: What's /usr/bin/dash and why should I care?

Normally sh, dash & bash are in /bin and not /usr/bin and the system shell scripts explicitly use /bin/sh as the interpreter. At least this is how it is on RPiOS (and every other Linux distro I've ever used).
by Paeryn
Wed Jun 09, 2021 7:35 pm
Forum: C/C++
Topic: Schrödinger's Code - Undefined behavior in theory and practice
Replies: 85
Views: 3132

Re: Schrödinger's Code - Undefined behavior in theory and practice

I've been looking into GCC's optimisation passes w.r.t. how it optimises sumdiv() and fails to warn about s being used uninitialised. The way it expands the returns is to create an internal temporary that is either set to s or 47 and returns that temporary (it simplifies things so there is only one ...
by Paeryn
Wed Jun 09, 2021 1:12 am
Forum: C/C++
Topic: Schrödinger's Code - Undefined behavior in theory and practice
Replies: 85
Views: 3132

Re: Schrödinger's Code - Undefined behavior in theory and practice

I am tired but for the life of me can't get a warning out of gcc for Fig2 (sumdiv). Ditto for GCC 11.1. Looks like a compiler bug to me. It knows perfectly well that "s" is uninitialized and elides references to it. -Wuninitialized should complain. Hmm ... It's a long standing issue that ...
by Paeryn
Sun Jun 06, 2021 11:35 pm
Forum: C/C++
Topic: gmp (Gnu multiple precision arithmetic lib) 5x faster on intel i7 than on Pi400 (two samples)
Replies: 138
Views: 7449

Re: gmp (Gnu multiple precision arithmetic lib) 5x faster on intel i7 than on Pi400 (two samples)

I get the idea. I just had this niggling idea that using "volatile" is not the correct thing to do. My compiler agrees: ➜ sqr g++-10 -std=c++20 -Ittmath -I/usr/local/include -L/usr/local/Cellar/gmp/6.2.1/lib/ -O3 -pedantic -fomit-frame-pointer -m64 -o sqr sqr.cpp -lgmp sqr.cpp: In functio...
by Paeryn
Sun Jun 06, 2021 10:30 pm
Forum: General discussion
Topic: Corporate identity Raspberry pi
Replies: 42
Views: 1572

Re: Corporate identity Raspberry pi

I should probably mention that, while I don't wear t-shirts with images or slogans on them, my wife does. Most of hers are cat related. If the OP can come up with t-shirts that manage to combine Pis and cats, he might have something. "The cat that got at the Raspberry Pi" aka Kira, the Ko...
by Paeryn
Sun Jun 06, 2021 10:14 pm
Forum: Advanced users
Topic: What's /usr/bin/dash and why should I care?
Replies: 17
Views: 561

Re: What's /usr/bin/dash and why should I care?

On modern systems you'll probably not notice any speed difference, there will be some but I'd guess that it'd be too small to notice unless you are spawning lots of shells at once. Bash will run in a compatibility mode if it detects that it was started as /bin/sh (I think it disables some of the bas...
by Paeryn
Sat Jun 05, 2021 9:44 pm
Forum: Python
Topic: Threads -- need better understanding
Replies: 13
Views: 401

Re: Threads -- need better understanding

One thing to be aware of with tkinter and threads is that only the main thread should directly interact with the GUI (apart from one exception). That exception is getting and setting values of variables that have the type StringVar, IntVar, DoubleVar or BooleanVar, you can safely read and update the...
by Paeryn
Sat Jun 05, 2021 12:44 pm
Forum: Python
Topic: How to compare new data to old data?
Replies: 10
Views: 439

Re: How to compare new data to old data?

Okay...here's a snippet of what I have so far....apples to apples, oranges to oranges ;) if MIWD <= 1 and MIWD >= 45: #look at Onaway and RogersCity to forecast if ONRepo == RCRepo: forecast = ONRepo print forecast else: forecast = "Weather changing" print forecast This outer if condition...
by Paeryn
Sat Jun 05, 2021 10:55 am
Forum: Beginners
Topic: "find" doesn't find a certain file
Replies: 103
Views: 3049

Re: "find" doesn't find a certain file

There you are wrong. What you are doing with the Arduino and trying to do with the Pi is Developer, not User. I have to disagree, I would never call me a developer, I am an Arduino user and a Raspi user and a Windows PC user and a smartphone user for tinkering and gaming and building some "MOC...
by Paeryn
Fri Jun 04, 2021 1:49 pm
Forum: Troubleshooting
Topic: lxsession folder missing?
Replies: 8
Views: 248

Re: lxsession folder missing?

Once I can get to that file (if thats still used) I will us the code below as " lxterminal " worked for me before @lxpanel --profile LXDE-pi @pcmanfm --desktop --profile LXDE-pi @xscreensaver -no-splash @point-rpi @lxterminal -e python3 /home/pi/filename.py If your RPiOS is up-to-date you...
by Paeryn
Thu Jun 03, 2021 2:21 pm
Forum: C/C++
Topic: gmp (Gnu multiple precision arithmetic lib) 5x faster on intel i7 than on Pi400 (two samples)
Replies: 138
Views: 7449

Re: gmp (Gnu multiple precision arithmetic lib) 5x faster on intel i7 than on Pi400 (two samples)

64bit "gcd()" does not call "__umodti3()": __uint128_t gcd(unsigned long a, unsigned long b) { if (a<b) b%=a; while (b!=0) { a%=b; if (a==0) return b; b%=a; } return a; } gcd: cmp rdi, rsi jnb .L16 mov rax, rsi xor edx, edx div rdi mov rsi, rdx jmp .L16 .L7: xor edx, edx div rsi...

Go to advanced search