- How to get signed zeros in C++/C? - 4 Updates
- size_t - 7 Updates
- error compiling simple threading example... - 3 Updates
- 'class' and 'struct' at link time - 7 Updates
- Why does this generate an error (Debug Assertion Failed) - 1 Update
- What problem does this self-assignment function have? - 3 Updates
Peng Yu <pengyu.ut@gmail.com>: Jun 10 07:50AM -0700 I don't find how to express signed zeros in C++/C. Does anybody know what is the proper way to do so? Are they just -0.0 and +0.0? How to distinguish signed zeros from true zeros. http://en.wikipedia.org/wiki/Signed_zero Regard, Peng |
Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid>: Jun 10 05:18PM +0200 > what is the proper way to do so? Are they just -0.0 and +0.0? How to > distinguish signed zeros from true zeros. > http://en.wikipedia.org/wiki/Signed_zero AFAIK there is no literal for those. You need to use either copysign(), or the signbit() macro (from <cmath>). -- Alain. |
Victor Bazarov <v.bazarov@comcast.invalid>: Jun 10 11:19AM -0400 On 6/10/2015 10:50 AM, Peng Yu wrote: > I don't find how to express signed zeros in C++/C. Does anybody know what is the proper way to do so? Are they just -0.0 and +0.0? How to distinguish signed zeros from true zeros. What's "true zeros"? The IEEE 754 floating point standard has a negative zero representation in which if the sign bit is set and the rest are clear. A "regular" zero (all bits clear) is considered positive. (I just looked at the Signed zero article, and it has that description). I am almost sure C++ has no way to express negative zero since the hosted system may not be able to represent it. The Standard does not require any particular representation of floating point values. If your system has IEEE 754, your compiler can have its own way of expressing it either in a literal or by invoking some function (possibly intrinsic) but that is *implementation-specific* and not general. > http://en.wikipedia.org/wiki/Signed_zero V -- I do not respond to top-posted replies, please don't ask |
"Öö Tiib" <ootiib@hot.ee>: Jun 10 09:14AM -0700 On Wednesday, 10 June 2015 17:51:01 UTC+3, Peng Yu wrote: > I don't find how to express signed zeros in C++/C. > Does anybody know what is the proper way to do so? Are they > just -0.0 and +0.0? In C++ '-0.0' and '+0.0' are not 'double' literals by its parsing rules. These are expressions where unary minus or plus operators are applied to 'double' literal '0.0'. What such floating point arithmetic does (like those unary operators) is not regulated by C or C++ standard. It is left implementation-specific. Target platform may for example (and often does) follow IEC 559/IEEE 754 standard of floating point arithmetic. You can check if it does with 'std::numeric_limits<double>::is_iec559'. It works compile-time so you can 'static_assert' if your code assumes that it does. #include <iostream> #include <limits> int main() { std::cout << (std::numeric_limits<double>::is_iec559 ? "double follows IEEE 754 on your platform" : "RTFM about double on your platform") << '\n'; double someZero = -0.0; std::cout << "Some zero:" << someZero << '\n' << "Some zero negated:" << -someZero << std::endl; return 0; } > How to distinguish signed zeros from true zeros. > http://en.wikipedia.org/wiki/Signed_zero The link that you posted answers that question. Can't you read it? Either use 'copysign' from <cmath> or see if '1/someZero' produces negative or positive infinity. |
asetofsymbols@gmail.com: Jun 09 07:03PM -0700 I wrote:" int main() {std::string str = "Hello, World!"; size_t i, j; i=str.size(); if(i) for( --i; ; --i) {std::cout << str[i]; if(i==0) break; } " #define R return #define P printf #define G(a,b) if(a) goto b size_t i, j; i=strlen(s); j=i; G(i==-1, l3); G(1, l2); l1: --i; P("%c", s[i]); l2: G(i, l1); l3: R j; |
"Lőrinczy Zsigmond" <nospam@for.me>: Jun 10 05:19AM +0200 On 2015.06.05. 20:25, Doug Mika wrote: > for (size_t i = strlen (str) - 1; i >= 0; i--){ > ... > } You've already got countless working and non-working code-snippets, here is another: for (size_t i= strlen(str)+1; --i;) { process (str[i]); } |
scott@slp53.sl.home (Scott Lurndal): Jun 10 03:10PM >operates to reduce safety rather than increase it. >ssize_t should generally be avoided where not mandated as part of a >POSIX interface that a program is obliged to use. The abstract type ssize_t was added long after the interfaces which used it were defined (e.g. the read(2) system call return value was defined as a 16-bit signed integer in V6 (late 70's)). When 32-bit systems became prevalent, int was extended to 32-bits (not without some painful work fixing broken apps). Meanwhile, X/Open, POSIX, etc. needed to abstract the return type for read, write et. alia to allow for future software portability[*], and because legacy software needed to see -1 as a return code from read on error, an abstract type (ssize_t) was defined. ssize_t "This is intended to be a signed analog of size_t. The wording is such that an implementation may either choose to use a longer type or simply to use the signed version of the type that underlies size_t. All functions that return ssize_t {read() and write()} describe as 'implementation defined' the result of an input exceeding {SSIZE_MAX}. It is recognized that some implementations might have 'int' that are smaller than size_t. A portable application would be constrained to not perform I/O in pieces larger than {SSIZE_MAX}, but a portable application using extensions would be able to use the full range if the implementation provided an extended range, while still having a single type-compatible interface." [P1003.4/D14.1 May 1993] This has been well-known for a quarter century. Given {SSIZE_MAX} on modern 64-bit systems, restricting I/O to {SSIZE_MAX} doesn't seem to be a limiting constraint. Without changing 20+ years of legacy unix code, there was no other solution. You can bitch about it all you want, but it is what it is. [*] http://www.unix.org/version2/whatsnew/lfs20mar.html |
scott@slp53.sl.home (Scott Lurndal): Jun 10 03:11PM >>You know, C is still a subset of C++; and it always will be, purists >>like yourself notwithstanding. >Not really. nullptr is not a keyword in C, but it is a keyword in C++. Not in the dialect of C++ that I'm required to use. I work in the real world, not some academic or personal paradise. NULL works in C++11 too. scott |
legalize+jeeves@mail.xmission.com (Richard): Jun 10 03:34PM [Please do not mail me a copy of your followup] =?UTF-8?B?TMWRcmluY3p5IFpzaWdtb25k?= <nospam@for.me> spake the secret code >for (size_t i= strlen(str)+1; --i;) { > process (str[i]); >} Also wrong (and please stop using C string functions, they are nothing but a source of trouble): #include <iostream> #include <string> int main() { std::string s("foo"); for (std::size_t i = s.length()+1; --i;) { std::cout << "i: " << i << ", '" << s[i] << "'\n"; } return 0; } output: i: 3, '\000' i: 2, 'o' i: 1, 'o' -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
legalize+jeeves@mail.xmission.com (Richard): Jun 10 03:41PM [Please do not mail me a copy of your followup] slp53@pacbell.net spake the secret code >>>like yourself notwithstanding. >>Not really. nullptr is not a keyword in C, but it is a keyword in C++. >Not in the dialect of C++ that I'm required to use. That's your problem, not mine. The addition of the keyword nullptr to the language is certainly not some academic pedantry. >NULL works in C++11 too. Except for where it doesn't and then you *need* nullptr. It wasn't a gratuitous addition to the language, it really is necessary. I *think* this is the video where Stephan T. Lavavej explains this: <http://channel9.msdn.com/Shows/Going+Deep/Stephan-T-Lavavej-Everything-you-ever-wanted-to-know-about-nullptr> -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
"Lőrinczy Zsigmond" <zsiga@nospam.for.me>: Jun 10 06:12PM +0200 Thank you for testing it, you are right, we still have to subtract one which makes it in-elegant: for (size_t i= strlen(str)+1; --i;) { process (str[i-1]); } |
Doug Mika <dougmmika@gmail.com>: Jun 09 07:30PM -0700 On Tuesday, June 9, 2015 at 5:42:01 PM UTC-5, Chris M. Thomasson wrote: > witch compiles your example. It runs fine with: > http://www.tutorialspoint.com/compile_cpp11_online.php > ;^) That worked absolutely seamlessly. Now what are the chances you'll know how to get the same problem fixed on MinGW 4.8.1 running on Netbeans GUI? |
"Chris M. Thomasson" <nospam@nospam.nospam>: Jun 09 09:43PM -0700 > "Doug Mika" wrote in message > news:dc121475-2de9-4797-a3fd-3b9208a5c9e1@googlegroups.com... > > On Tuesday, June 9, 2015 at 5:42:01 PM UTC-5, Chris M. Thomasson wrote: [...] > That worked absolutely seamlessly. > Now what are the chances you'll know how to get the > same problem fixed on MinGW 4.8.1 running on Netbeans GUI? The following command line works for me with mingw 4.9.2: g++ -std=c++11 -pthread main.cpp I have not used Netbeans in many years. The last time I used it was when I was working in Solaris. I cannot remember how you can change the build options. However, this may help you out a bit: http://stackoverflow.com/questions/25683355/how-do-i-add-std-c11-to-the-compiler-options-in-my-netbeans-ide https://forums.netbeans.org/ntopic18439.html Gook luck Doug! :^) |
Doug Mika <dougmmika@gmail.com>: Jun 10 08:30AM -0700 On Tuesday, June 9, 2015 at 2:10:25 PM UTC-5, Doug Mika wrote: > Thanks to all in advance. > (Using MinGW with the following command: > g++ -std=c++11 -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/welcome.o.d" -o build/Debug/MinGW-Windows/welcome.o welcome.cc) So I came upon a little program to test whether MinGW supports threads on windows platforms: #include <thread> #include <iostream> int main() { #if !defined(_GLIBCXX_HAS_GTHREADS) std::cout << "glib doesn't have gthreads on my platform\n";
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment