- Reproducing a sequence from a binary tree... - 5 Updates
- Function type syntax confusion - 4 Updates
- Sausages ... - 1 Update
- Two different Results between C and C++ - 4 Updates
- How to define 2 bit variable - 1 Update
- How to define 2 bit variable - 5 Updates
- XanaNews Statistic for comp.lang.c++. 6/1/2020 1:06:00 AM - 1 Update
- HMI - 2 Updates
- wxWidgets Compilation Error - 1 Update
- g++ compiles, msvc crashes, is the code correct? - 1 Update
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jun 02 03:18PM -0700 On 6/2/2020 2:23 PM, The Real Non Homosexual wrote: > e can either mean exponent or the euler constant. The latter. |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jun 02 11:43PM -0700 On 6/2/2020 11:39 PM, Chris M. Thomasson wrote: > The seventh root: > (-0.119748,-1.07716) > Raised to the tenth power gets -1+2i. Its basically equal to modding in a sense: https://youtu.be/qhbuKbxJsk8 |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jun 02 11:39PM -0700 On 6/2/2020 9:13 PM, Alf P. Steinbach wrote: > On 02.06.2020 08:30, Chris M. Thomasson wrote: [...] > } > ----------------------------------------------------------------------------- > And yes, the two loops produce the same output. I am not trying to find all of the roots, just a single targeted one. Say root 6 of base 10. Say, there are ten roots in any complex number z wrt z^10, I only need the 6'th root. The sixth root of complex number, say -1+2i in base ten is: 6 digit precision: (-0.730018,-0.801057) Raise this to the tenth power and you get -1+2i. The seventh root: (-0.119748,-1.07716) Raised to the tenth power gets -1+2i. |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jun 03 01:37PM +0200 On 03.06.2020 08:43, Chris M. Thomasson wrote: >> Raised to the tenth power gets -1+2i. > Its basically equal to modding in a sense: > https://youtu.be/qhbuKbxJsk8 Oh, OK. Up front disclaimer: I haven't looked at the video. One optimization opportunity is that you call `std::abs`, which involves a costly square root, only to feed that later as argument to `pow`. Instead call `std::norm`, which produces the square, and adjust the exponent argument to `pow`. Like, const double radius = std::pow( std::norm(z), (1.0/b)/2 ); Another possible optimization for calculation of a single root of general z is that e.g. sin(x) can be computed as sqrt(1 - cos(x)^2), plus relevant sign adjustment. But I'm not sure if it's faster. After all the trig functions are done in hardware now. And maybe you could compute the integral real root faster via Newton/Raphson approximation rather than via general `pow`, just as `sqrt(x)` is probably faster than `pow(x, 0.5)`. I haven't tried though, and it precludes the optimization of using `norm`, and again, since the basic math ops are done in hardware now it's questionable whether a software Newton/Raphson loop would be faster than hardware `pow`. Still one could try, and measure. Cheers!, - Alf |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jun 03 09:12PM +0200 On 03.06.2020 13:37, Alf P. Steinbach wrote: > Newton/Raphson approximation rather than via general `pow`, just as > `sqrt(x)` is probably faster than `pow(x, 0.5)`. I haven't tried though, > and it precludes the optimization of using `norm`, No it doesn't. Just calculate the base 2*b root. Here I am correcting myself again, for the second time this thread. > basic math ops are done in hardware now it's questionable whether a > software Newton/Raphson loop would be faster than hardware `pow`. Still > one could try, and measure. - Alf |
Juha Nieminen <nospam@thanks.invalid>: Jun 02 04:59AM > A set hold data objects, and pointers are data objects so a set of > pointers makes sense. Functions are not considered to be data objects > in either C or C++ so you can't put them into collections. The second template parameter is a comparator, not the element type. |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Jun 02 10:36AM +0100 >> pointers makes sense. Functions are not considered to be data objects >> in either C or C++ so you can't put them into collections. > The second template parameter is a comparator, not the element type. Ah, yes, I missed the comma. Oddly, though, the reason you can't use an actual function type there is the same. A compare "thing" must be a copy-constructable object, so a function type is ruled out. The comparator is put into the collection -- it's part of the collection's data. -- Ben. |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Jun 01 02:50AM +0100 > call syntax is available for pointers only. > Indexing and calling works for actual arrays and functions only > because of the implicit conversions to pointer. This not how things happened historically. Originally, functions were called as functions, and a call through a pointer-to-function required a dereference: (*f)(... args ...) The switch to calling through a pointer (and the associated ubiquity of the decay of functions to pointers) came along only in C90. As you say, this change makes arrays and functions analogous, but it was not there in the early days. -- Ben. |
Juha Nieminen <nospam@thanks.invalid>: May 31 04:13PM It's still unclear to me what the difference is between the function type syntax of the form "ReturnType(*)(ParameterTypes)" and "ReturnType(ParameterTypes)". Sometimes they seem to be interchangeable, sometimes they don't. For example, this is valid: //------------------------------------------- using F1 = int(*)(int); using F2 = int(int); void foo1(F1 funcPtr); // ok void foo2(F2 funcPtr); // ok //------------------------------------------- However, this is not valid: //------------------------------------------- F1 funcPtr1 = someFunc; // ok F2 funcPtr2 = someFunc; // error //------------------------------------------- Likewise: //------------------------------------------- std::function<int(int)> funcObj1; // ok std::function<int(*)(int)> funcObj2; // error std::set<int, bool(*)(int, int)> set1; // ok std::set<int, bool(int, int)> set2; // error //------------------------------------------- So they are like the reverse of each other. F2 above can be used for a function declaration, which might give some insight into what it means. In other words: //------------------------------------------- F2 someFunction; // ok int main() { int value = someFunction(5); // ok. } int someFunction(int v) { return v+1; } //------------------------------------------- |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: May 30 10:00PM +0100 ... beg the question. /Flibble -- "Snakes didn't evolve, instead talking snakes with legs changed into snakes." - Rick C. Hodgin "You won't burn in hell. But be nice anyway." – Ricky Gervais "I see Atheists are fighting and killing each other again, over who doesn't believe in any God the most. Oh, no..wait.. that never happens." – Ricky Gervais "Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Byrne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?" "I'd say, bone cancer in children? What's that about?" Fry replied. "How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil." "Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say." |
Real Troll <real.troll@trolls.com>: Jun 02 04:08AM -1000 Just noticed that these two program give two different results. One is a C program and other is a C++ program. <********** C++ ******************> #include <iostream> using namespace std; int main(){ cout << sizeof('a') << endl; cout << sizeof(1!=1) << endl; return 0; } <********** C ******************> #include<stdio.h> #include <stdlib.h> int main(){ printf("%4zu", sizeof('a')); printf("%4zu", sizeof(1!=1)); return 0; } |
Bart <bc@freeuk.com>: Jun 02 07:55PM +0100 On 02/06/2020 19:45, Juha Nieminen wrote: > the philosophy of "you don't pay for what you don't use"). Maybe > it has something to do with C, at least originally, supporting > multi-character constants like 'ab'. Maybe because the type of 97 is int too. Then 'a' is just another way of writing 97. |
Juha Nieminen <nospam@thanks.invalid>: Jun 02 06:45PM > Just noticed that these two program give two different results. One is a > C program and other is a C++ program. The type of 'a' in C is int, while in C++ it's char. I'm not exactly sure why its type is int in C (given that C has always had char as a type, and it has, too, mostly been designed from the ground up with the philosophy of "you don't pay for what you don't use"). Maybe it has something to do with C, at least originally, supporting multi-character constants like 'ab'. I'm also not completely certain why this is one thing which C++ decided to change. (I suppose it's good that it changed it, but I'm not really sure why this.) |
Lew Pitcher <lew.pitcher@digitalfreehold.ca>: Jun 02 03:11PM -0400 On June 2, 2020 14:55, Bart wrote: >> multi-character constants like 'ab'. > Maybe because the type of 97 is int too. Then 'a' is just another way of > writing 97. Perhaps you are joking? Everyone knows that the C character constant 'a' has a value of 129 (in EBCDIC-US, of course). -- Lew Pitcher "In Skills, We Trust" |
ram@zedat.fu-berlin.de (Stefan Ram): Jun 02 09:21PM >10 >11 >so bool and integer type not required. Thanks in advance If you only need a few of those bit pairs, you have no memory concerns and can use one or even two int objects to store two bits without hesitation. If you need a lot of those bit pairs, try to hold them in some kind of array. Then you can pack s * CHAR_BIT bits in an object of size s. Bit pair p then resides at the array offset 2 * p /( s * CHAR_BIT ) and the object offset 2 * p % ( s * CHAR_BIT ), and you can use the operators "&", "|", ">>", "<<", and "=" to read/write a pair of bits. In a real programming language like Pascal, you can simply write packed array[ 1..n ]of( s00, s01, s10, s11 ) or omit "packed" and let the compiler do the detail work. In C++, there is »::std::vector< bool >« which is neither a vector nor does it contain bool objects. You could use this as a kind of an array of single bits and do the combining of pairs of two bits yourself. |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jun 02 01:10PM On Tue, 2020-06-02, Adnan Rashid wrote: > 10 > 11 > so bool and integer type not required. Thanks in advance Depends on what you want to do with it. One solution is enum class Bits { Zero, One, Two, Three }; but that won't, I think, be more compact in memory than struct Bits { Bits(bool a, bool b); private: unsigned char bits; }; and not a lot more compact than std::pair<bool, bool> /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
Bonita Montero <Bonita.Montero@gmail.com>: Jun 02 06:00PM +0200 > std::pair<bool, bool> This never would be 2 bits large. |
Bonita Montero <Bonita.Montero@gmail.com>: Jun 02 02:44PM +0200 struct { unsigned value : 2; } s; You can't define bitfields out of a struct. |
Nikolaj Lazic <nlazicBEZ_OVOGA@mudrac.ffzg.hr>: Jun 02 01:24PM > 10 > 11 > so bool and integer type not required. Thanks in advance Minimal storage size is char or byte. If you want to store 1 bit you have to allocate 1 byte at least. |
Bart <bc@freeuk.com>: Jun 02 02:56PM +0100 On 02/06/2020 13:08, Adnan Rashid wrote: > 10 > 11 > so bool and integer type not required. Thanks in advance Implementations typically allow such variables of 8 to 64 bits. Most applications will only need some of the 2**8 to 2**64 possible values; they just ignore the rest. How many 2-bit variables will there be in total? If only one, then the packing/unpacking code needed will far exceed the 6 bits saved from uint8_t. |
queequeg@trust.no1 (Queequeg): Jun 01 11:01AM > 13 15 Sam http: This is interesting. His original header is: X-Mailer: http://www.courier-mta.org/cone/ Looks like XanaNews takes only the part before the first '/' (as other clients put version there, for example: Mozilla/4.0). I'm wondering if it's standarized and courier-mta is non-conformant, or if it isn't standarized and XanaNews should have an exception for URLs like this (or even extract the name from the URL, in this case courier-mta). -- Bend the facts to fit the conclusion. It's easier that way. |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jun 06 06:50PM -0700 On 6/5/2020 11:54 AM, Chris M. Thomasson wrote: >> Spacecraft displays should be 4:3 and NOT widescreen to ensure >> consistency with 2001: A Space Odyssey. > lol. What about a Clockwork Orange? Keep the eyes open, or you might miss something important... ;^) |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jun 06 07:07PM -0700 On 6/5/2020 11:54 PM, Juha Nieminen wrote: > You are one of the most vocal opponents of that religious guy who keeps > spamming this newsgroup with off-topic posts. > You are no different from him. You are both hypocrites. https://youtu.be/7mrI2xtkEMA |
taliadon <taliadon@yahoo.co.uk>: Jun 07 02:20AM +0100 On 28/05/2020 18:51, Mr Flibble wrote: >> What is your question about C++? > Indeed. wxWidgets is MFC and MFC isn't C++; MFC is a "bag of shite". > /Flibble wxWidgets (msw) is not MFC, it's WIN32. |
Ian Collins <ian-news@hotmail.com>: Jun 07 12:01PM +1200 On 07/06/2020 10:59, Manfred wrote: > https://en.cppreference.com/w/cpp/types/is_enum > By the way, I compiled it with gcc 9.3 and it works fine - also, to the > OP, FWIW the code is valid for me. Ah, I forgot -std=c++17. -- Ian. |
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. |
No comments:
Post a Comment