Hi,
I setprecision to be 100 for both cases. I'm wondering why the number
of digits are different.
Also, for a double number, I think any digits that are longer than 15
(or 16) are not meaningful, because it exceed the double number's
precision limit. Even if I setprecision to be 100, shall it truncate
the number to be of 15(or 16) digits?
Thanks,
Peng
$ cat main.cc
#include <iostream>
#include <iomanip>
int main() {
double a = .01;
std::cout << std::setprecisi on(100) << a << std::endl;
std::cout << std::scientific << std::setprecisi on(100) << a <<
std::endl;
}
$ ./main-g.exe
0.0100000000000 000002081668171 172168513294309 377670288085937 5
1.0000000000000 000208166817117 216851329430937 767028808593750 000000000000000 000000000000000 000000000000e-02 3 5060 Pe*******@gmail .com wrote:
I setprecision to be 100 for both cases. I'm wondering why the number
of digits are different.
Also, for a double number, I think any digits that are longer than 15
(or 16) are not meaningful, because it exceed the double number's
precision limit. Even if I setprecision to be 100, shall it truncate
the number to be of 15(or 16) digits?
Thanks,
Peng
$ cat main.cc
#include <iostream>
#include <iomanip>
int main() {
double a = .01;
std::cout << std::setprecisi on(100) << a << std::endl;
std::cout << std::scientific << std::setprecisi on(100) << a <<
std::endl;
}
$ ./main-g.exe
0.0100000000000 000002081668171 172168513294309 377670288085937 5
1.0000000000000 000208166817117 216851329430937 767028808593750 000000000000000 000000000000000 000000000000e-02
I believe 'fixed' (the default, when 'scientific' is not used), always
skips the trailing zeros.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On 2007-09-03 18:03, Victor Bazarov wrote:
Pe*******@gmail .com wrote:
>I setprecision to be 100 for both cases. I'm wondering why the number of digits are different.
Also, for a double number, I think any digits that are longer than 15 (or 16) are not meaningful, because it exceed the double number's precision limit. Even if I setprecision to be 100, shall it truncate the number to be of 15(or 16) digits?
Thanks, Peng
$ cat main.cc #include <iostream> #include <iomanip>
int main() { double a = .01; std::cout << std::setprecisi on(100) << a << std::endl; std::cout << std::scientific << std::setprecisi on(100) << a << std::endl; } $ ./main-g.exe 0.010000000000 000000208166817 117216851329430 937767028808593 75 1.000000000000 000020816681711 721685132943093 776702880859375 000000000000000 000000000000000 0000000000000e-02
I believe 'fixed' (the default, when 'scientific' is not used), always
skips the trailing zeros.
Running the same code under Windows using VC++ 2005 I get the same
number of digits printed, but it's all zeroes after the 1. I find that a
bit troubling, since I thought that 0.01 was a number that couldn't be
exactly represented.
--
Erik Wikström
Erik Wikström wrote:
On 2007-09-03 18:03, Victor Bazarov wrote:
>Pe*******@gmail .com wrote:
>>I setprecision to be 100 for both cases. I'm wondering why the number of digits are different. [..] $ ./main-g.exe 0.01000000000 000000020816681 711721685132943 093776702880859 375 1.00000000000 000002081668171 172168513294309 377670288085937 500000000000000 000000000000000 00000000000000e-02
I believe 'fixed' (the default, when 'scientific' is not used), always skips the trailing zeros.
Running the same code under Windows using VC++ 2005 I get the same
number of digits printed, but it's all zeroes after the 1. I find
that a bit troubling, since I thought that 0.01 was a number that
couldn't be exactly represented.
What you see is the external equivalent of the imprecise internal
representation. A decent library should be able to successfully
round the number when outputting is so that the round-trip (no pun
indended) from external rep to internal and back to external does
not change the appearance of the number. "0.01" in--0xB1AB1AAA (or
whatever) out--"0.01"
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Woodster |
last post by:
I am using the std::setprecision function to format variables of type
double in a string however I am unsure how to stop this appearing in
scientific notation.
For example
std::stringstream buffer;
buffer << setprecision(1) << 40.0 << "° C";
|
by: Ville Ahonen |
last post by:
I'm a total beginner at C++ so please bear with me.. When i write
cout << stddev * stddev << endl;
I get the output "4.49513e-05". How can I rephrase the above so that I
would instead get the output "0.000049513"?
Thanks alot,
Ville
|
by: Gary Wessle |
last post by:
hi
the code below is giving me what I want but it is very ugly. and will
not work for a long list of different length numbers.
could you please look at it and comment.
thank you
the desired output is:
0.555504 of an inch foreach 12.55
|
by: Wing |
last post by:
Hello eveyone,
I am programming some scientific computation based on C++. I would like
to set every output/input (e.g. cout, io file stream) to be a high
precision.
What C++ command should I use?
Thanks so much.
|
by: Wing |
last post by:
Thanks for those who answered my question previously.
Everytime I want to output high precision numbers, I use the following
code:
cout << setprecision (9) << f << endl;
where f is some double number.
However, I don't want to add "setprecision (9)" in every "cout" and
| |
by: Woody714 |
last post by:
I'm fairly new to C++ and have an assignment that is knocking me out. The text file is fairly simple:
Plain Egg
1.45
Bacon and Egg
2.45
Muffin
0.99..... etc....
|
by: jacek.dziedzic |
last post by:
Hello!
Can someone tell me what the expected output of the following
program is?
#include <fstream>
#include <iomanip>
using namespace std;
|
by: victoryusami |
last post by:
I'm not 100% sure whats even going on, but I'm working on a C++ assignment for school, and its a road trip program
#include <iostream>
#include <iomanip>
using namespace std;
char const METRIC = 'M'; // Input read as metric
char const ENGLISH = 'E'; // Input read as english
char const QUIT = 'Q'; // Input read to quit program
char const QUIT2 = 'q'; // Input read to quit program
|
by: Johannes Bauer |
last post by:
Hello group,
I've a simple problem with the precision specifiers of stringstream.
Let's say I have this:
double x = 123.4567890;
std::stringstream Strm;
Strm.precision(4);
Strm << std::scientific << x;
std::cerr << Strm.str() << std::endl;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |