In C, what do you use to store numbers larger than the floating point
range? For e.g, consider the code below:
int main(void)
{
float a = 0.0;
double b = 0.0;
double f = 0.0;
a = 123456789.0;
printf("%f\n\n", a); //output: 123456792.000000
b = 123456789;
printf("%f\n\n", b); //output: 123456789.000000
printf("Enter a number: ");
scanf("%f", &f); //input: 123456789
printf("You entered: %f\n\n", f); //output: 0.000000
return 0;
}
What datatype should be used to negate the rounding error? 7 1656
Sathyaish wrote: In C, what do you use to store numbers larger than the floating point range? For e.g, consider the code below:
int main(void) {
float a = 0.0; double b = 0.0; double f = 0.0;
a = 123456789.0; printf("%f\n\n", a); //output: 123456792.000000
b = 123456789; printf("%f\n\n", b); //output: 123456789.000000
printf("Enter a number: "); scanf("%f", &f); //input: 123456789 printf("You entered: %f\n\n", f); //output: 0.000000
return 0; }
What datatype should be used to negate the rounding error?
The only two standard types you have available are `float` and
`double`, but you know that already. If you need better precision,
you'll have to use some appropriate library providing the functionality
and data types you need. There are libraries out there that support
"infinite" precision. Consider GMP ( http://www.swox.com/gmp/).
However, it is often possible to get around some of the floating point
limitations by clever choice of algorithms.
"Sathyaish" <sa*******@gmail.com> writes: In C, what do you use to store numbers larger than the floating point range? For e.g, consider the code below:
int main(void) {
float a = 0.0; double b = 0.0; double f = 0.0;
a = 123456789.0; printf("%f\n\n", a); //output: 123456792.000000
b = 123456789; printf("%f\n\n", b); //output: 123456789.000000
printf("Enter a number: "); scanf("%f", &f); //input: 123456789 printf("You entered: %f\n\n", f); //output: 0.000000
return 0; }
What datatype should be used to negate the rounding error?
This isn't a rounding error. The format to read a double using scanf
is "%lf", not "%f".
Also, you're missing the required "#include <stdio.h>".
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
"Vladimir Oka" <no****@btopenworld.com> writes:
[...] The only two standard types you have available are `float` and `double`, but you know that already. If you need better precision, you'll have to use some appropriate library providing the functionality and data types you need. There are libraries out there that support "infinite" precision. Consider GMP (http://www.swox.com/gmp/).
There's also long double, which may or may not have more precision
than double.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
In article <11**********************@e56g2000cwe.googlegroups .com> "Vladimir Oka" <no****@btopenworld.com> writes:
.... Sathyaish wrote: In C, what do you use to store numbers larger than the floating point range? For e.g, consider the code below:
This is not about range, but about precision.
int main(void) {
float a = 0.0; double b = 0.0; double f = 0.0;
a = 123456789.0; printf("%f\n\n", a); //output: 123456792.000000
a has 23 bits of precision, so rounding has to take place.
b = 123456789; printf("%f\n\n", b); //output: 123456789.000000
b has 53 bits of precision, so no rounding has to take place.
printf("Enter a number: "); scanf("%f", &f); //input: 123456789 printf("You entered: %f\n\n", f); //output: 0.000000
Does the conversion specifier in the call to scanf match with the argument?
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
why dont you use anydata structure
/*24age*/ opined: why dont you use anydata structure
What on Earth are you talking about!
Please study the link below before contributing more.
--
Vulcans believe peace should not depend on force.
-- Amanda, "Journey to Babel", stardate 3842.3
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
Sathyaish wrote: In C, what do you use to store numbers larger than the floating point range? For e.g, consider the code below:
int main(void) {
float a = 0.0; double b = 0.0; double f = 0.0;
a = 123456789.0; printf("%f\n\n", a); //output: 123456792.000000
b = 123456789; printf("%f\n\n", b); //output: 123456789.000000
printf("Enter a number: "); scanf("%f", &f); //input: 123456789 printf("You entered: %f\n\n", f); //output: 0.000000
return 0; }
What datatype should be used to negate the rounding error?
Not a rounding error. Your scanf() stuffs a float value into a double
object. This 'scanf("%lf", &f);' works better. You must also include the
stdio.h header.
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert Anderson |
last post by:
Hi There!
My web site is currently hosted on a commerical hosting server (which is not
my own) and they are not allowing me to create my own COM dll and use them
with my ASP pages. They are not...
|
by: Chrisbarbers |
last post by:
--part1_108.256bef7d.2c5af59f_boundary
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi
=A0
I have purchased a package that uses ASP and SQL,...
|
by: Glen Able |
last post by:
Should it be possible to create a custom class, 'Float', which would behave
as a drop-in replacement for the builtin float type?
As mentioned in another thread, I once tried this in rather a...
|
by: Jeff Marcum |
last post by:
I need to write a query in Access that returns the results of a text field
with the spaces replaced with underscores. So, if the data in the field was
'hello world', the query results would show...
|
by: Felix Kater |
last post by:
The C-faq says that "The malloc/free implementation remembers the size
of each block allocated and returned, so it is not necessary to remind
it of the size when freeing."
Could that length...
|
by: Steve Richter |
last post by:
I have a public variable ( "mZipServiceUrl" ) in my code behind class
that I am able to substitute into the HTML of the .aspx file:
<span onclick="WindowOpen('<%=mZipServiceUrl%>')"...
|
by: vijay.rajamanickam |
last post by:
I am a newbie w.r.t. compiler optimizations and I believe these
optimizations are generally done in function level. Can I safely assume
that
if I use getter & setter functions, I can effectively...
|
by: malice |
last post by:
I have been searching the internet for 12+ hours on how to do this. At this point I'm about to give up. I am using VB .Net 2.0 with the enterprise library jan 2006 release. This is my first time...
|
by: Rocky Zhou |
last post by:
I am accustomed to vi my pthon scripts with 'tab' indent. But when I
copy some code to my script, the indent may be 'spaces'. So I wanna a
way to substitute those 'spaces' to be 'tabs'...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
| |