Thread: Re: [Dev-C++] float and double
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <Rob...@ao...> - 2001-03-06 13:21:05
|
In a message dated 06/03/01 13:09:20 GMT Standard Time,=20 pet...@im... writes: << Any quick explanations on the difference between a float and a double whe= n used as variables? >> Take a look at float.h :-) Or look below ;o) <</* * The characteristics of float. */ /* The radix for floating point representation. */ #define FLT_RADIX 2 /* Decimal digits of precision. */ #define FLT_DIG 6 /* Smallest number such that 1+x !=3D 1 */ #define FLT_EPSILON 1.19209290e-07F /* The number of base FLT_RADIX digits in the mantissa. */ #define FLT_MANT_DIG 24 /* The maximum floating point number. */ #define FLT_MAX 3.40282347e+38F /* Maximum n such that FLT_RADIX^n - 1 is representable. */ #define FLT_MAX_EXP 128 /* Maximum n such that 10^n is representable. */ #define FLT_MAX_10_EXP 38 /* Minimum normalized floating-point number. */ #define FLT_MIN 1.17549435e-38F /* Minimum n such that FLT_RADIX^n is a normalized number. */ #define FLT_MIN_EXP (-125) /* Minimum n such that 10^n is a normalized number. */ #define FLT_MIN_10_EXP (-37) /* * The characteristics of double. */ #define DBL_DIG 15 #define DBL_EPSILON 1.1102230246251568e-16 #define DBL_MANT_DIG 53 #define DBL_MAX 1.7976931348623157e+308 #define DBL_MAX_EXP 1024 #define DBL_MAX_10_EXP 308 #define DBL_MIN 2.2250738585072014e-308 #define DBL_MIN_EXP (-1021) #define DBL_MIN_10_EXP (-307)>> XANDER: Who's a little fear demon? Come on, who's a little fear demon? GILES: Don't taunt the fear demon. XANDER: Why? Can he hurt me? GILES: No, it's just tacky. ... GACHNAR: I am the Dark Lord! Fear me! WILLOW: He=E2=80=99s so cute! BtVS Season 4 - "Fear, Itself" |
|
From: <Rob...@ao...> - 2001-03-06 16:04:05
|
In a message dated 06/03/01 14:33:57 GMT Standard Time,=20
pet...@im... writes:
<< trav_cost =3D (km_travelled * 0.3);
wear_cost =3D ((km_travelled / 1000) - ((km_travelled % 1000) / 100) *
200); >>
I'm not an expert myself - but maybe the compiler is treating 1000, 1000 &=20
100 as integers as there is no .0 involved? Maybe changing 1000 to 1000.0 an=
d=20
so on would resolve it? :-)
If not then back to the drawing board I'm afraid :-)
Rob! x ;o)
XANDER: Who's a little fear demon? Come on, who's a little fear demon?
GILES: Don't taunt the fear demon.
XANDER: Why? Can he hurt me?
GILES: No, it's just tacky.
...
GACHNAR: I am the Dark Lord! Fear me!
WILLOW: He=E2=80=99s so cute!
BtVS Season 4 - "Fear, Itself"
|
|
From: Jack D. <ja...@am...> - 2001-03-06 18:21:13
|
You may have to include the following headers. Try the first one first.
#include <stdlib.h> #include <cmath>
Sometimes compilers do not automatically include the stdlib.h
----- Original Message -----
From: <Rob...@ao...>
To: <dev...@li...>
Sent: Tuesday, March 06, 2001 10:03 AM
Subject: Re: [Dev-C++] float and double
In a message dated 06/03/01 14:33:57 GMT Standard Time,
pet...@im... writes:
<< trav_cost = (km_travelled * 0.3);
wear_cost = ((km_travelled / 1000) - ((km_travelled % 1000) / 100) *
200); >>
I'm not an expert myself - but maybe the compiler is treating 1000, 1000 &
100 as integers as there is no .0 involved? Maybe changing 1000 to 1000.0
and
so on would resolve it? :-)
If not then back to the drawing board I'm afraid :-)
Rob! x ;o)
XANDER: Who's a little fear demon? Come on, who's a little fear demon?
GILES: Don't taunt the fear demon.
XANDER: Why? Can he hurt me?
GILES: No, it's just tacky.
...
GACHNAR: I am the Dark Lord! Fear me!
WILLOW: He’s so cute!
BtVS Season 4 - "Fear, Itself"
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Robert D B. <lon...@ju...> - 2001-03-06 16:33:26
|
wear_cost = ((km_travelled / 1000) - (((int)km_travelled % 1000) / 100)
* 200);
This needs to be cast as an int
Regards lonestar36
On Wed, 7 Mar 2001 01:13:31 +1100 "petermead" <pet...@im...>
writes:
> Robert I like it...
>
> &
>
> Q: Any ideas on why this modulus returns an error when compiled?
>
> /* basic code I am learning for colledge.
> Hire cost is $0.30 per km and $200 per complete 1000km travelled */
> // To Calculate hire car cost.
> // By Peter Mead 06-03-2001.
>
> #include <iostream.h>
>
> void main()
>
> {
>
> float ini_reading;
> float fin_reading;
> float km_travelled;
> float trav_cost;
> float wear_cost;
>
> // Title.
> cout << "Calculate the hire car cost. \n\n";
>
> // Ask for initial odometer reading.
> cout << "Please Enter the initial odometer reading :";
> cin >> ini_reading;
>
> // Ask for finial reading.
> cout << endl;
> cout << "Please Enter the finial odometer reading :";
> cin >> fin_reading;
>
> // Calculate costs.
> km_travelled = (fin_reading - ini_reading);
> trav_cost = (km_travelled * 0.3);
> wear_cost = ((km_travelled / 1000) - ((km_travelled % 1000) /
> 100) *
> 200);
>
> // Display total hire car cost.
> cout << "The total hire car cost is $" << (wear_cost +
> trav_cost);
> cout << endl << endl;
>
> // Finish program.
> cin.ignore(1);
> cin.get();
>
>
> }
>
> TIA...
>
> ----==<(*)>==----
> Peter Mead :^)
> pet...@im...
> (GMT+10)_Victoria, Australia
> ~~~~~~~~~~~~~~~~~~~~~~
> ----- Original Message -----
> From: <Rob...@ao...>
> To: <dev...@li...>
> Sent: Wednesday, March 07, 2001 12:22 AM
> Subject: Re: [Dev-C++] float and double
>
>
> In a message dated 06/03/01 13:09:20 GMT Standard Time,
> pet...@im... writes:
>
> << Any quick explanations on the difference between a float and a
> double
> when
> used as variables? >>
>
> Take a look at float.h :-)
>
> Or look below ;o)
>
> <</*
> * The characteristics of float.
> */
>
> /* The radix for floating point representation. */
> #define FLT_RADIX 2
>
> /* Decimal digits of precision. */
> #define FLT_DIG 6
>
> /* Smallest number such that 1+x != 1 */
> #define FLT_EPSILON 1.19209290e-07F
>
> /* The number of base FLT_RADIX digits in the mantissa. */
> #define FLT_MANT_DIG 24
>
> /* The maximum floating point number. */
> #define FLT_MAX 3.40282347e+38F
>
> /* Maximum n such that FLT_RADIX^n - 1 is representable. */
> #define FLT_MAX_EXP 128
>
> /* Maximum n such that 10^n is representable. */
> #define FLT_MAX_10_EXP 38
>
> /* Minimum normalized floating-point number. */
> #define FLT_MIN 1.17549435e-38F
>
> /* Minimum n such that FLT_RADIX^n is a normalized number. */
> #define FLT_MIN_EXP (-125)
>
> /* Minimum n such that 10^n is a normalized number. */
> #define FLT_MIN_10_EXP (-37)
>
>
> /*
> * The characteristics of double.
> */
> #define DBL_DIG 15
> #define DBL_EPSILON 1.1102230246251568e-16
> #define DBL_MANT_DIG 53
> #define DBL_MAX 1.7976931348623157e+308
> #define DBL_MAX_EXP 1024
> #define DBL_MAX_10_EXP 308
> #define DBL_MIN 2.2250738585072014e-308
> #define DBL_MIN_EXP (-1021)
> #define DBL_MIN_10_EXP (-307)>>
>
> XANDER: Who's a little fear demon? Come on, who's a little fear
> demon?
> GILES: Don't taunt the fear demon.
> XANDER: Why? Can he hurt me?
> GILES: No, it's just tacky.
> ...
> GACHNAR: I am the Dark Lord! Fear me!
> WILLOW: Heâs so cute!
> BtVS Season 4 - "Fear, Itself"
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> |
|
From: petermead <pet...@im...> - 2001-03-06 14:12:26
|
Robert I like it...
&
Q: Any ideas on why this modulus returns an error when compiled?
/* basic code I am learning for colledge.
Hire cost is $0.30 per km and $200 per complete 1000km travelled */
// To Calculate hire car cost.
// By Peter Mead 06-03-2001.
#include <iostream.h>
void main()
{
float ini_reading;
float fin_reading;
float km_travelled;
float trav_cost;
float wear_cost;
// Title.
cout << "Calculate the hire car cost. \n\n";
// Ask for initial odometer reading.
cout << "Please Enter the initial odometer reading :";
cin >> ini_reading;
// Ask for finial reading.
cout << endl;
cout << "Please Enter the finial odometer reading :";
cin >> fin_reading;
// Calculate costs.
km_travelled = (fin_reading - ini_reading);
trav_cost = (km_travelled * 0.3);
wear_cost = ((km_travelled / 1000) - ((km_travelled % 1000) / 100) *
200);
// Display total hire car cost.
cout << "The total hire car cost is $" << (wear_cost + trav_cost);
cout << endl << endl;
// Finish program.
cin.ignore(1);
cin.get();
}
TIA...
----==<(*)>==----
Peter Mead :^)
pet...@im...
(GMT+10)_Victoria, Australia
~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: <Rob...@ao...>
To: <dev...@li...>
Sent: Wednesday, March 07, 2001 12:22 AM
Subject: Re: [Dev-C++] float and double
In a message dated 06/03/01 13:09:20 GMT Standard Time,
pet...@im... writes:
<< Any quick explanations on the difference between a float and a double
when
used as variables? >>
Take a look at float.h :-)
Or look below ;o)
<</*
* The characteristics of float.
*/
/* The radix for floating point representation. */
#define FLT_RADIX 2
/* Decimal digits of precision. */
#define FLT_DIG 6
/* Smallest number such that 1+x != 1 */
#define FLT_EPSILON 1.19209290e-07F
/* The number of base FLT_RADIX digits in the mantissa. */
#define FLT_MANT_DIG 24
/* The maximum floating point number. */
#define FLT_MAX 3.40282347e+38F
/* Maximum n such that FLT_RADIX^n - 1 is representable. */
#define FLT_MAX_EXP 128
/* Maximum n such that 10^n is representable. */
#define FLT_MAX_10_EXP 38
/* Minimum normalized floating-point number. */
#define FLT_MIN 1.17549435e-38F
/* Minimum n such that FLT_RADIX^n is a normalized number. */
#define FLT_MIN_EXP (-125)
/* Minimum n such that 10^n is a normalized number. */
#define FLT_MIN_10_EXP (-37)
/*
* The characteristics of double.
*/
#define DBL_DIG 15
#define DBL_EPSILON 1.1102230246251568e-16
#define DBL_MANT_DIG 53
#define DBL_MAX 1.7976931348623157e+308
#define DBL_MAX_EXP 1024
#define DBL_MAX_10_EXP 308
#define DBL_MIN 2.2250738585072014e-308
#define DBL_MIN_EXP (-1021)
#define DBL_MIN_10_EXP (-307)>>
XANDER: Who's a little fear demon? Come on, who's a little fear demon?
GILES: Don't taunt the fear demon.
XANDER: Why? Can he hurt me?
GILES: No, it's just tacky.
...
GACHNAR: I am the Dark Lord! Fear me!
WILLOW: He’s so cute!
BtVS Season 4 - "Fear, Itself"
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|