« first day (1701 days earlier)      last day (1143 days later) » 

8:54 AM
@John yeah, just call it?
 
 
3 hours later…
11:40 AM
In C++ if you want to take a square root of an unsigned long long and only care about the integer portion, what's the best method to use? I know there's sqrtl which returns long double, but not sure if it will get messed up converting from signed to unsigned.
 
a cast will truncate away the fractional portion so it's fine
 
@ratchetfreak according to here the data range of double is the same as long double. According to here it's compiler dependent. My question is, since I only care about the integer portion, does it make sense to use sqrtl or just sqrt?
Like does double reserved a portion for before the decimal point and a portion for after, or is that not how it works?
 
 
1 hour later…
12:58 PM
the accuracy needed for the integer part of a square root of a long long (64 bits) is only 32 bits
a double has more than enough accuracy in the mantissa for that
 
 
1 hour later…
2:11 PM
@northerner The first source you link is from a Microsoft reference, so it is likely true for a Windows platform. The second link is a more general answer about C++ in general. long double may or may not be larger than double, depending on the target platform.
 
 
2 hours later…
3:52 PM
Why does this segfault on the last line?
template <typename T> class wqueue
{
    list<T>          m_queue;
    pthread_mutex_t  m_mutex;
    pthread_cond_t   m_condv;
    struct timespec* max_wait;

  public:
    wqueue() {
        (*max_wait) = {0, 0};
 
@Hakaishin because there is no memory backing the pointer?
 
Meaning?
 
you're writing to random memory or if you're lucky nullptr
 
ah no wait yes
 
you need to allocate max_wait first
 
3:54 PM
I usually don't work with structs
 
structs are just like classes?
just public by default
so why are you using a pointer?
 
ugh, do I have to use mallox I guess?
pthread_cond_timedwait expects one
With classes I never have to use malloc, but this is I guess because the libs I use hide the malloc behind an abstraction
 
@Hakaishin yes but it doesn't actually expect a malloc'd one
it just expects the address of one
you don't need that as a pointer
 
how else would you do it?
I have:
clock_gettime(CLOCK_REALTIME, max_wait);
max_wait->tv_nsec += 100000;
pthread_cond_timedwait(&m_condv, &m_mutex, max_wait);
 
just have it as a local to the class and then use the address of operator
 
3:57 PM
timespec max_wait;

timespec* pointer = &max_wait;
you already did it with m_condv and the mutex
 
or better yet... use the facilities in the stdlib
instead of using pthreads directly
 
good point, that worked
I'm just adapting some code I inherited, don't plan on looking too much into it, I just need to make it non blocking
 
4:08 PM
Hi, I have a loop that produces a value at every iteration, and I need to stop the loop when a value is equal to a precedently produced value. How can I do this without storing all the values?
I remember of reading about a way to do this some time ago, but I can't find the explanation anymore.
 
4:27 PM
like
type previous;
type value;
do{
previous = value;
value = calculate();
}while(previous != value)
with maybe a placeholder value for the first loop, or a bool check or something like that
 
5:03 PM
I don't get my profiler output, 78% of my time is spent in libc-2.31.so__clone
 
@Hakaishin you should probably look at that "inverted call tree" thing most profilers have, to see which part of your code calls that
 
i'm using clion, how do I get the inverted call tree?
I only see flame graph, call tree and method list, none of which show methods I wrote :D
 
if none of them show methods you wrote, are you compiling with debug symbols?
 
yes
It goes from all directly into the clone call, no intermediate function calls
 
weird are you comping with -fno-emit-framepointer ?
 
5:13 PM
wait, I found my functions. It's a tiny fraction on the right somewhere
But it's only about 20%, I kinda don't get where 80% is spent in the lic clone call
and there is no "outer scope" to speak, it just says all then clone as seen in the image, that's weird
 
5:54 PM
whats the equivalent in c++ of django and flask?
whats the best way to build microservices and monoliths in c++?
 
@PeterT I need to check for all the precedently produced values, not just the previus one. I remember of reading about a matematical technique to do this without storing all the values, saving a lot of memory, but I don't remember what it was called.
 
6:32 PM
@ThePirate42 If the numbers that are generated are effectively random, then you need some sort of state to store which numbers have been generated. Depending on the distribution, you can either store all numbers that have been generated or create some flag set to when if a number has been generated or not.
If you are asking for "any solution that does not store the values generated" then a bitset with a number of bits equal to the number of possible values is one alternative.
 
 
1 hour later…
7:43 PM
@ThePirate42 The key to your issue is your specific definition of "values". For example, if your situation has "value" that are constraints to always be integers in the range [0,49], and your loop is generating millions upon millions of them, then instead of storing all millions of results, you should just use a wasGenerated[i] array of 50 booleans.
If your specific definition of "value" is even further constrained to be integers in the range [0,7], then you could further extend this idea to have memory needs of only one byte (instead of setting a boolean array element, you are setting an one bit within that byte) -- this is essentially @Francois' bitset idea.
On the other hand, if your definition of "values" is each loop iteration might be generating any arbitrary 32-bit number, for example, then you're not going to be able to get away from storing them all.
 
@CowCorporation My value is a complex<double>. Well, I suppose there is no solution then.
(yes I'm trying to plot a fractal)
 
yeah, there's no way I can imagine a good de-duplication without storage if you're sampling that dense
 
Since your data are doubles, what is your intention for "equal to a previously produced value" ?
 
except of course if there's some constraints you're willing to make like Francois suggested. I.e. make a bitmap that's sampling the space in some grid-like structure
 
sorry i solved it as I was typing it out
haha
 
7:52 PM
@ThePirate42: For scientific applications that manipulate floating point data, there's often the concept of an epsilon. So in some situations, even with complex<double>, the space of possible data might be constrained such that you could group the potentially-generated data into "bins", and still do a wasGenerated[i] type of idea.
But since your application is fractals, I'm assuming that's not gunna be the case for you
 
@PeterT All the complex<double> are in the square with vertexes -2+2i 2+2i -2-2i 2-2i
 
And what kind of precision is needed?
That is, is it okay for 1.5+1.5i and 2+2i to be considered the "same" ?
Or if those two points should be "different", but okay for 1.9+1.9i and 2+2i to be considered the "same"?
For example, if a precision of 0.5 in each dimension is acceptable, then you only have 25 possible points, which means you could use a bitset type of approach
oops, make that more like 100 possible points, but I think you get the idea
 
@CowCorporation I didn't think of that. I guess it depends on how c++ approximates calculations
 
Are you aware of the fact that when you have two floating point (double) values (stored in two double variables x and y), that it is inherently unsafe in C++ to test an expression like if (x == y) {...}
 
well it's not "unsafe" it just "doesn't necessarily do what most people expect"
 
7:59 PM
@PeterT, true enough, I'm just concerned that @ThePirate42 might be relying on an incorrect assumption about the representation of computed floating point value, and how to determine "sameness"
 
@CowCorporation I didn't think of that, but now that I think about it what I was trying to do doesn't make sense without an exact representation of rational numbers
@CowCorporation Guess I'll have to use another approach. Anyway, thank you for the time and the help!
 

« first day (1701 days earlier)      last day (1143 days later) »