Hi,
I want to represent a double in char* as accurate as possible, but as
short as possible:
double char*
10000 1E5
1000.00123 1000.00123
....
How can I archive this?
%.10f prints too much, and %.10g is too inaccurate.
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%c gl%ssic%ccom%c" , "ma", 58, 'g', 64, "ba", 46, 10);}
_______________ _______________ __________
Looking for a good game? Do it yourself!
GLBasic - you can do www.GLBasic.com 14 7978
"Gernot Frisch" <Me@Privacy.net > wrote in message
news:2s******** *****@uni-berlin.de... I want to represent a double in char* as accurate as possible, but as short as possible:
This is the intent of the %g formatter in printf.
double char* 10000 1E5 1000.00123 1000.00123 ...
How can I archive this? %.10f prints too much, and %.10g is too inaccurate.
How is %g "too inaccurate", could you provide an example ?
The accuracy of a double, in IEEE format, is limited to about 15 decimal
digits. So a %.15g should do what you asked for.
Regards,
Ivan
-- http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
"Ivan Vecerina" <NO************ *************** *******@vecerin a.com>
schrieb im Newsbeitrag news:ck******** **@newshispeed. ch... "Gernot Frisch" <Me@Privacy.net > wrote in message news:2s******** *****@uni-berlin.de... I want to represent a double in char* as accurate as possible, but as short as possible: This is the intent of the %g formatter in printf.
double char* 10000 1E5 1000.00123 1000.00123 ...
How can I archive this? %.10f prints too much, and %.10g is too inaccurate. How is %g "too inaccurate", could you provide an example ? The accuracy of a double, in IEEE format, is limited to about 15 decimal digits. So a %.15g should do what you asked for.
double f = 10000.000000012 3567;
printf("%20.15f - %.15g\n", f, f);
// 10000.000000012 356000 - 10000.000000012 4
Gernot Frisch wrote: "Ivan Vecerina" <NO************ *************** *******@vecerin a.com> schrieb im Newsbeitrag news:ck******** **@newshispeed. ch... "Gernot Frisch" <Me@Privacy.net > wrote in message news:2s******** *****@uni-berlin.de... I want to represent a double in char* as accurate as possible, but as short as possible: This is the intent of the %g formatter in printf.
double char* 10000 1E5 1000.00123 1000.00123 ...
How can I archive this? %.10f prints too much, and %.10g is too inaccurate. How is %g "too inaccurate", could you provide an example ? The accuracy of a double, in IEEE format, is limited to about 15 decimal digits. So a %.15g should do what you asked for.
double f = 10000.000000012 3567;
cout the digits
10000.000000012 3567
00000 0000111111111 (Note: 1 reads: 14
12345 6789012345678 4
So everything to the right of
......123
is most likely noise anyway (assuming a standard
precission of 15 digits)
Note: 15 digits does *not* mean: 15 digits after comma.
It means 15 digits total!
--
Karl Heinz Buchegger kb******@gascad .at
Gernot Frisch wrote: "Ivan Vecerina" <NO************ *************** *******@vecerin a.com> schrieb im Newsbeitrag news:ck******** **@newshispeed. ch... "Gernot Frisch" <Me@Privacy.net > wrote in message news:2s******** *****@uni-berlin.de... I want to represent a double in char* as accurate as possible, but as short as possible: This is the intent of the %g formatter in printf.
double char* 10000 1E5 1000.00123 1000.00123 ...
How can I archive this? %.10f prints too much, and %.10g is too inaccurate. How is %g "too inaccurate", could you provide an example ? The accuracy of a double, in IEEE format, is limited to about 15 decimal digits. So a %.15g should do what you asked for.
double f = 10000.000000012 3567;
cout the digits
10000.000000012 3567
00000 0000111111111 (Note: 1 reads: 14
12345 6789012345678 4
So everything to the right of
.......000123
is most likely noise anyway (assuming a standard
precission of 15 digits)
Note: 15 digits does *not* mean: 15 digits after comma.
It means 15 digits total!
--
Karl Heinz Buchegger kb******@gascad .at
> cout the digits 10000.000000012 3567
00000 0000111111111 (Note: 1 reads: 14 12345 6789012345678 4
So everything to the right of
.......000123
is most likely noise anyway (assuming a standard precission of 15 digits)
Note: 15 digits does *not* mean: 15 digits after comma. It means 15 digits total!
So, why is %.15f printing it correctly? Coincidence?
Gernot Frisch wrote: cout the digits
10000.000000012 3567
00000 0000111111111 (Note: 1 reads: 14 12345 6789012345678 4
So everything to the right of
.......000123
is most likely noise anyway (assuming a standard precission of 15 digits)
Note: 15 digits does *not* mean: 15 digits after comma. It means 15 digits total!
So, why is %.15f printing it correctly? Coincidence?
15 is average. It depends on the number itself how many digits you get
exactly. BTW by assining 10000.000000012 3567 and getting
10000.000000012 356000 one cannot talk from correctly. The last
digit you assigned was 7, printf brought back a 0 (and didn't round
the previous 6 to 7).
Might be interesting for you: http://www.petebecker.com/js200006.html http://docs.sun.com/source/806-3568/ncg_goldberg.html
--
Karl Heinz Buchegger kb******@gascad .at
Gernot Frisch wrote: cout the digits
10000.0000000 123567
00000 0000111111111 (Note: 1 reads: 14 12345 6789012345678 4
So everything to the right of
.......000123
is most likely noise anyway (assuming a standard precission of 15 digits)
Note: 15 digits does *not* mean: 15 digits after comma. It means 15 digits total!
So, why is %.15f printing it correctly? Coincidence?
Absolutely.
Change the number (to be, e.g., 10000.000000012 3333) and see if
you get the same "precise" output. I got two different results
on Linux (g++ v 3.2.2) and IRIX (MIPSpro 7.3). Both had garbage
after the first 16 digits. sizeof(double) is 8 on both systems.
Also, change the leading 1 to, say, leading 9, and you will get
even "less" accuracy -- the garbage will begin to appear in the
16th digit.
V This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: steve |
last post by:
I am quite frustrated with php’s include, as I have spent a ton of
time on it already... anyone can tell me why it was designed like this
(or something I don’t get)?
The path in include is relative NOT to the immediate script that is
including it, but is relative to the top-level calling script.
In practice, this means that you have to constantly worry and adjust
paths in includes, based on the startup scripts that call these...
|
by: aku |
last post by:
I'm looking for the absolute fastest way
to count the nr of bits that are set to "1"
in a string. Presumably I then first need the
fastest way to do this in a byte.
I think this is it, but welcome any improvements:
i = 0;
if (g && 1) i++;
if (g && 2) i++;
|
by: Peter Mount |
last post by:
Hello
I'm having trouble with " scanf("%c", &answer);" on line 20 below. When I
run the program in cygwin on Windows 98SE it skips that line completely and
ends the program. Does scanf have problems with "%c" or is it the operating
system I'm using?
1 #include <stdio.h>
2
3 int main()
|
by: baumann.Pan |
last post by:
hi all,
i want to get the address of buf, which defined as
char buf = "abcde";
so can call
strsep(address of buf, pointer to token);
|
by: markryde |
last post by:
Hello,
I saw in some open source projects a use of "!!" in "C" code;
for example:
in some header file
#define event_pending(v) \
(!!(v)->vcpu_info->evtchn_upcall_pending & \
!(v)->vcpu_info->evtchn_upcall_mask)
whereas evtchn_upcall_pending is of type unsigned char
(and also evtchn_upcall_mask is of type unsigned char).
| |
by: chandanlinster |
last post by:
consider the program,
/*********************************************************/
int
main()
{
int a;
printf("a = %u\n", a);
printf("*a = %u\n", *a);
return 0;
}
|
by: Spidey |
last post by:
for(;0;)
printf("hello");
even the condition s wrong i get a hello printed on the screen
y s this happening
|
by: candy_init |
last post by:
Hi all,
I just came across the following program:
#include <stdio.h>
int main()
{
float a = 12.5;
printf("%d\n", a);
printf("%d\n", *(int *)&a);
return 0;
|
by: hiteshthappa |
last post by:
hi
Can anyone please help me in finding the total number of words in a
file
I get the newlines, characters and blankspaces correctly but counting
words ia problem.I have tried many ways but it didnt help.
Here is my code......
#include <string.h>
#include <stdio.h>
main(int argc , char *argv)
|
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: 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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |