- How can I get an implementation of fmod()? - 4 Updates
- Sieve of Eratosthenes - 18 Updates
- Pure beauty - 1 Update
- What is visitor pattern? - 1 Update
Megumin <chrisramirez0227@gmail.com>: Aug 30 10:52PM -0700 After researching I found something that seems quite correct but I ain't implement it yet.(for this is going to be running on a hardware which can process one operation for 1024 numbers at once so using indefinite loops is not recommended) float temp = y; while((temp<<1)<x)temp<<=1; while(x>y){ if(x>temp)x-=temp; temp/=2; } no matter what thank you all for your insights. |
Bonita Montero <Bonita.Montero@gmail.com>: Aug 31 11:00AM +0200 Am 31.08.2023 um 07:52 schrieb Megumin: > After researching I found something that seems quite correct but I ain't implement it yet.(for this is going to be running on a hardware which can process one operation for 1024 numbers at once so using indefinite loops is not recommended) > float temp = y; > while((temp<<1)<x)temp<<=1; Trying to shift floats ? |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Aug 31 09:48PM +0100 > After researching I found something that seems quite correct but I > ain't implement it yet. Have you tried: x - (int)(x/y) * y ? Obviously you might be worried about corner cases and accuracy, but that is at least a starting point. > if(x>temp)x-=temp; > temp/=2; > } This is not valid C or C++. If can point to where you found it, maybe we can help make some sense of what it is trying to achieve? -- Ben. |
Keith Thompson <Keith.S.Thompson+u@gmail.com>: Aug 31 02:37PM -0700 > temp/=2; > } > no matter what thank you all for your insights. Suggestion: Always compile code before posting it. The "<<" operator cannot be applied to floating-point operands. And indentation makes code much more legible. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */ |
Tim Rentsch <tr.17687@z991.linuxsc.com>: Aug 30 05:45PM -0700 >>> and I imagine a bit can be shaved off the time. >> Thank you for this. Would you mind posting your code? > Hmm... It's a bit of a mess... but sure. [...] It looks quite okay. I haven't yet had time to look at it closely but I look forward to doing so. >> you have a reference for the Atkin/Bernstein algorithm (or even >> better, code?)? > Well, there's this: https://en.wikipedia.org/wiki/Sieve_of_Atkin Excellent! And this page has a link to DJ Bernstein's fast primes code, which is stunningly swift. Thank you for both. |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Aug 31 03:18AM +0100 >> Hmm... It's a bit of a mess... but sure. [...] > It looks quite okay. I haven't yet had time to look at it > closely but I look forward to doing so. About 20% of the time was spent counting the primes, so I added a population count function to the bitset operations. And there's an obvious halving one can do on the upper bound of the first loop. That brought the time down to about 28 seconds. >> Well, there's this: https://en.wikipedia.org/wiki/Sieve_of_Atkin > Excellent! And this page has a link to DJ Bernstein's fast > primes code, which is stunningly swift. I haven't looked at it yet. It would probably have put me off! > Thank you for both. You're welcome. -- Ben. |
Muttley@dastardlyhq.com: Aug 31 08:22AM On Wed, 30 Aug 2023 18:31:32 +0200 >> Are you posting this code for lols? >I often concatenate a small number of statements with the comma-operator >to save screen space. I never had any issues with that. That's just a To save space? Seriously?? >matter of personal taste. If you're noticing this until now, I'm going Its not just personal taste, it makes the code harder to parse for anyone who has to maintain it and could easily lead to logical errors if someone modifies it and forgets to replace the ; with a , at the end. >But that's just the syntax issue. My code is also superior in terms of >safety (iterator debuggin) and performance (+2/3 more performance with >g++ 12 and a Sklake-CPU). Yes, we know how wonderful your code is after you seem to spend multiple days on some trivial task. Obviously no one else could ever manage what you did, you're a coding god. |
Bonita Montero <Bonita.Montero@gmail.com>: Aug 31 11:00AM +0200 > To save space? Seriously?? It's my taste. > Its not just personal taste, it makes the code harder to parse for anyone > who has to maintain ... Not true, you just feel unsecure with that for whaterver reason. > Yes, we know how wonderful your code is after you seem to spend multiple days > on some trivial task. ... The task is not trivial if you consider my solution. You won't manage to have it that fast. |
Bonita Montero <Bonita.Montero@gmail.com>: Aug 31 11:52AM +0200 > Yes, we know how wonderful your code is after you seem to spend multiple days > on some trivial task. Obviously no one else could ever manage what you did, > you're a coding god. I just benchmarked my code with an upper bound of 1E3 against your code on a Skylake CPU with g++ 12 and -march=native. My code runs about 0.9s, your code takes 5.26s. Any questions ? |
scott@slp53.sl.home (Scott Lurndal): Aug 31 02:43PM >>I often concatenate a small number of statements with the comma-operator >>to save screen space. I never had any issues with that. That's just a >To save space? Seriously?? cfront used to generate extensive comma laden expressions. It did cause problems with PCC's temporary register allocation algorithms that I had to fix back around 1989. |
Bonita Montero <Bonita.Montero@gmail.com>: Aug 31 04:57PM +0200 Am 31.08.2023 um 16:43 schrieb Scott Lurndal: > cfront used to generate extensive comma laden expressions. It did > cause problems with PCC's temporary register allocation algorithms > that I had to fix back around 1989. There's for sure no compiler that generates different code whether you youse individual ;-separated statements or one comma-separated statement as both are sequence points. |
Muttley@dastardlyhq.com: Aug 31 03:22PM On Thu, 31 Aug 2023 11:52:09 +0200 >I just benchmarked my code with an upper bound of 1E3 against your code >on a Skylake CPU with g++ 12 and -march=native. My code runs about 0.9s, >your code takes 5.26s. Any questions ? Yes , do you have a life? My code took about 20 mins to write , you seem to have been working on yours for over a week now. |
Muttley@dastardlyhq.com: Aug 31 03:23PM On Thu, 31 Aug 2023 11:00:06 +0200 >> Its not just personal taste, it makes the code harder to parse for anyone >> who has to maintain ... >Not true, you just feel unsecure with that for whaterver reason. You sound like the python devs who claim there's no problem with significant whitespace with indentation. |
Muttley@dastardlyhq.com: Aug 31 03:25PM On Thu, 31 Aug 2023 14:43:34 GMT >>>to save screen space. I never had any issues with that. That's just a >>To save space? Seriously?? >cfront used to generate extensive comma laden expressions. It did I don't even understand why C/C++ allows comma seperation of calls in a block. It should be restricted to a few specific locations such as inside for(). |
Bonita Montero <Bonita.Montero@gmail.com>: Aug 31 05:28PM +0200 > You sound like the python devs who claim there's no problem with significant > whitespace with indentation. You're too compulsive for that world. |
Bonita Montero <Bonita.Montero@gmail.com>: Aug 31 05:32PM +0200 >> your code takes 5.26s. Any questions ? > Yes , do you have a life? My code took about 20 mins to write , you seem to > have been working on yours for over a week now. You complained about my code and I explained why it was more complex. You probably have nothing more to say about that. With the questions you usually ask about C++, I assume that you would not be able to write such secure and performance code. Writing performant code is part of my job. I write software for high frequency trading, so you have to think about which constructs result in which code and how efficient it is. |
Bonita Montero <Bonita.Montero@gmail.com>: Aug 31 05:33PM +0200 > I don't even understand why C/C++ allows comma seperation of calls in a block. I think you would change the world that there are less annoyances for you. |
Muttley@dastardlyhq.com: Aug 31 03:44PM On Thu, 31 Aug 2023 17:32:15 +0200 >Writing performant code is part of my job. I write software for high >frequency trading, so you have to think about which constructs result >in which code and how efficient it is. HFC is far more impacted by network delays than any minor inefficiencies in the software. Its highly I/O bound. |
Bonita Montero <Bonita.Montero@gmail.com>: Aug 31 05:50PM +0200 > HFC is far more impacted by network delays than any minor inefficiencies in > the software. Its highly I/O bound. Read the Wikipedia article about HFC then you won't need to elaborate everything by your own ideas. |
scott@slp53.sl.home (Scott Lurndal): Aug 31 04:10PM >There's for sure no compiler that generates different code whether >you youse individual ;-separated statements or one comma-separated >statement as both are sequence points. Are you familiar with the term non-sequitur? I don't believe code generation was ever referred to in the post you replied to, and therefore your reply is non-responsive. |
scott@slp53.sl.home (Scott Lurndal): Aug 31 04:12PM >> I don't even understand why C/C++ allows comma seperation of calls in a block. >I think you would change the world that there are less annoyances for >you. pot kettle black |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Aug 31 09:33PM +0100 > I just benchmarked my code with an upper bound of 1E3 against your code > on a Skylake CPU with g++ 12 and -march=native. My code runs about 0.9s, > your code takes 5.26s. Any questions ? Is the 1E3 a typo? And if not, does it mean 1000 as I would interpret it? A prime sieve up to 1000 should be almost un-measurably fast. -- Ben. |
Bonita Montero <Bonita.Montero@gmail.com>: Aug 31 08:59PM +0200 I wrote a small Win32 tool that combines time from Unix, start from Windows and runas from Windows in one. For this I just needed a function that processes the number of clock cycles spent by the process into a string. I wanted to use iterator debugging as much as possible so that the whole thing is as good as safe from out -of-bound errors. Here is the function: string formatClockCycles( uint64_t clockCycles, char separator ) { char digits[32]; auto [end, ec] = to_chars( digits, std::end( digits ), clockCycles ); string_view svDigits( digits, end ); size_t dots = (svDigits.length() - 1) / 3; string_view::iterator itDigits = svDigits.end(); string dottified; dottified.resize( svDigits.length() + dots, '*' ); string::iterator itRet = dottified.end(); for( ; dots--; itDigits -= 3, itRet -= 4 ) copy( itDigits - 3, itDigits, itRet - 3 ), itRet[-4] = separator; copy( svDigits.begin(), itDigits, dottified.begin() ); return dottified; } |
Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>: Aug 30 11:18PM -0400 Bonita Montero wrote: >> backward-compatible changes to the type hierarchy **given in the >> problem, not "needed by Visitor"**, ideally, no changes at all. > You simply don't understand what I wrote. Of course if you say so. |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |