Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #10936 > unrolled thread
| Started by | ramtin <tom.t.2090@gmail.com> |
|---|---|
| First post | 2011-10-17 12:40 -0700 |
| Last post | 2011-10-30 22:27 +1300 |
| Articles | 20 on this page of 22 — 13 participants |
Back to article view | Back to comp.lang.c++
float ramtin <tom.t.2090@gmail.com> - 2011-10-17 12:40 -0700
Re: float Dombo <dombo@disposable.invalid> - 2011-10-17 21:47 +0200
Re: float Thomas Boell <tboell@domain.invalid> - 2011-10-17 21:50 +0200
Re: float Sjouke Burry <S@P.NL> - 2011-10-26 23:13 +0000
Re: float Saeed Amrollahi <amrollahi.saeed@gmail.com> - 2011-10-17 13:05 -0700
Re: float Ian Collins <ian-news@hotmail.com> - 2011-10-18 09:23 +1300
Re: float Leigh Johnston <leigh@i42.co.uk> - 2011-10-17 21:25 +0100
Re: float Leigh Johnston <leigh@i42.co.uk> - 2011-10-17 21:31 +0100
Re: float Leigh Johnston <leigh@i42.co.uk> - 2011-10-17 21:33 +0100
Re: float Ian Collins <ian-news@hotmail.com> - 2011-10-18 09:35 +1300
Re: float ramtin <tom.t.2090@gmail.com> - 2011-10-17 13:49 -0700
Re: float Ian Collins <ian-news@hotmail.com> - 2011-10-18 09:19 +1300
Re: float "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2011-10-18 00:55 +0100
Re: float SG <s.gesemann@gmail.com> - 2011-10-18 05:34 -0700
Re: float Christopher <cpisz@austin.rr.com> - 2011-10-27 14:29 -0700
Re: float Dombo <dombo@disposable.invalid> - 2011-10-28 18:14 +0200
Re: float 88888 Dihedral <dihedral88888@googlemail.com> - 2011-10-28 21:06 -0700
Re: float red floyd <no.spam.here@its.invalid> - 2011-10-28 22:14 -0700
Re: float 88888 Dihedral <dihedral88888@googlemail.com> - 2011-10-28 23:27 -0700
Re: float red floyd <no.spam.here@its.invalid> - 2011-10-29 08:24 -0700
Re: float ptyxs <kerloch@gmail.com> - 2011-10-30 01:40 -0700
Re: float Ian Collins <ian-news@hotmail.com> - 2011-10-30 22:27 +1300
Page 1 of 2 [1] 2 Next page →
| From | ramtin <tom.t.2090@gmail.com> |
|---|---|
| Date | 2011-10-17 12:40 -0700 |
| Subject | float |
| Message-ID | <fa3c19f8-c2ed-4d12-b18e-e40b574cdd31@g16g2000yqi.googlegroups.com> |
hi all ,
#include "stdafx.h"
#include <stdio.h>
using namespace System;
int main(array<System::String ^> ^args)
{
float d = 4 / 3 ;
printf("%f",d);
return 0;
}
when you run this ,it will be 1 in d ,but it should be 1.3333 in it !!!
[toc] | [next] | [standalone]
| From | Dombo <dombo@disposable.invalid> |
|---|---|
| Date | 2011-10-17 21:47 +0200 |
| Message-ID | <4e9c863e$0$14713$5fc3050@news.tiscali.nl> |
| In reply to | #10936 |
Op 17-Oct-11 21:40, ramtin schreef:
> hi all ,
>
> #include "stdafx.h"
> #include<stdio.h>
> using namespace System;
>
> int main(array<System::String ^> ^args)
> {
> float d = 4 / 3 ;
> printf("%f",d);
> return 0;
> }
>
> when you run this ,it will be 1 in d ,but it should be 1.3333 in it !!!
That is because 4 and 3 are integers, so the result of the division will
be an integer as well, after that the integer result is converted to a
float. If you use 4.0/3.0 you should get something close to 1.3333.
[toc] | [prev] | [next] | [standalone]
| From | Thomas Boell <tboell@domain.invalid> |
|---|---|
| Date | 2011-10-17 21:50 +0200 |
| Message-ID | <20111017215005.66a8d93d@arcadia> |
| In reply to | #10936 |
On Mon, 17 Oct 2011 12:40:40 -0700 (PDT)
ramtin <tom.t.2090@gmail.com> wrote:
> hi all ,
>
> #include "stdafx.h"
> #include <stdio.h>
> using namespace System;
>
> int main(array<System::String ^> ^args)
> {
> float d = 4 / 3 ;
> printf("%f",d);
> return 0;
> }
>
> when you run this ,it will be 1 in d ,but it should be 1.3333 in it !!!
What language is it?
[toc] | [prev] | [next] | [standalone]
| From | Sjouke Burry <S@P.NL> |
|---|---|
| Date | 2011-10-26 23:13 +0000 |
| Message-ID | <Xns9F8BCBFBFFA0sjoukeburrysoesterbe@213.75.12.10> |
| In reply to | #10939 |
Thomas Boell <tboell@domain.invalid> wrote in
news:20111017215005.66a8d93d@arcadia:
> On Mon, 17 Oct 2011 12:40:40 -0700 (PDT)
> ramtin <tom.t.2090@gmail.com> wrote:
>
>> hi all ,
>>
>> #include "stdafx.h"
>> #include <stdio.h>
>> using namespace System;
>>
>> int main(array<System::String ^> ^args)
>> {
>> float d = 4 / 3 ;
>> printf("%f",d);
>> return 0;
>> }
>>
>> when you run this ,it will be 1 in d ,but it should be 1.3333 in it
cut
(int(4/(int)3 equals 1.
so whats new today??
[toc] | [prev] | [next] | [standalone]
| From | Saeed Amrollahi <amrollahi.saeed@gmail.com> |
|---|---|
| Date | 2011-10-17 13:05 -0700 |
| Message-ID | <c8e5a21a-c456-44b7-823c-5d6a7f3ea76d@g25g2000yqh.googlegroups.com> |
| In reply to | #10936 |
On Oct 17, 10:40 pm, ramtin <tom.t.2...@gmail.com> wrote:
> hi all ,
>
> #include "stdafx.h"
> #include <stdio.h>
> using namespace System;
>
> int main(array<System::String ^> ^args)
> {
> float d = 4 / 3 ;
> printf("%f",d);
> return 0;
>
> }
>
> when you run this ,it will be 1 in d ,but it should be 1.3333 in it !!!
Hi Ramtin
Besides what Dombo wrote you can use static_cast:
float d = static_cast<float>(4)/3;
Regards,
-- Saeed Amrollahi
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-10-18 09:23 +1300 |
| Message-ID | <9g3h6iFpouU3@mid.individual.net> |
| In reply to | #10940 |
On 10/18/11 09:05 AM, Saeed Amrollahi wrote:
> On Oct 17, 10:40 pm, ramtin<tom.t.2...@gmail.com> wrote:
>> hi all ,
>>
>> #include "stdafx.h"
>> #include<stdio.h>
>> using namespace System;
>>
>> int main(array<System::String ^> ^args)
>> {
>> float d = 4 / 3 ;
>> printf("%f",d);
>> return 0;
>>
>> }
>>
>> when you run this ,it will be 1 in d ,but it should be 1.3333 in it !!!
>
> Hi Ramtin
> Besides what Dombo wrote you can use static_cast:
> float d = static_cast<float>(4)/3;
If the OP were using C++, wouldn't it be easier just to write
float d = float(4) / 3;
?
Either way, the rules of whatever language the OP is using may be different.
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Leigh Johnston <leigh@i42.co.uk> |
|---|---|
| Date | 2011-10-17 21:25 +0100 |
| Message-ID | <XIGdnUIx58bFEgHTnZ2dnUVZ8hCdnZ2d@giganews.com> |
| In reply to | #10942 |
On 17/10/2011 21:23, Ian Collins wrote:
> On 10/18/11 09:05 AM, Saeed Amrollahi wrote:
>> On Oct 17, 10:40 pm, ramtin<tom.t.2...@gmail.com> wrote:
>>> hi all ,
>>>
>>> #include "stdafx.h"
>>> #include<stdio.h>
>>> using namespace System;
>>>
>>> int main(array<System::String ^> ^args)
>>> {
>>> float d = 4 / 3 ;
>>> printf("%f",d);
>>> return 0;
>>>
>>> }
>>>
>>> when you run this ,it will be 1 in d ,but it should be 1.3333 in it !!!
>>
>> Hi Ramtin
>> Besides what Dombo wrote you can use static_cast:
>> float d = static_cast<float>(4)/3;
>
> If the OP were using C++, wouldn't it be easier just to write
>
> float d = float(4) / 3;
No it would be easier to just write
float d = 4.0f / 3.0f;
/Leigh
[toc] | [prev] | [next] | [standalone]
| From | Leigh Johnston <leigh@i42.co.uk> |
|---|---|
| Date | 2011-10-17 21:31 +0100 |
| Message-ID | <Ieedndng-aNZDQHTnZ2dnUVZ8j-dnZ2d@giganews.com> |
| In reply to | #10943 |
On 17/10/2011 21:25, Leigh Johnston wrote:
> On 17/10/2011 21:23, Ian Collins wrote:
>> On 10/18/11 09:05 AM, Saeed Amrollahi wrote:
>>> On Oct 17, 10:40 pm, ramtin<tom.t.2...@gmail.com> wrote:
>>>> hi all ,
>>>>
>>>> #include "stdafx.h"
>>>> #include<stdio.h>
>>>> using namespace System;
>>>>
>>>> int main(array<System::String ^> ^args)
>>>> {
>>>> float d = 4 / 3 ;
>>>> printf("%f",d);
>>>> return 0;
>>>>
>>>> }
>>>>
>>>> when you run this ,it will be 1 in d ,but it should be 1.3333 in it !!!
>>>
>>> Hi Ramtin
>>> Besides what Dombo wrote you can use static_cast:
>>> float d = static_cast<float>(4)/3;
>>
>> If the OP were using C++, wouldn't it be easier just to write
>>
>> float d = float(4) / 3;
>
> No it would be easier to just write
>
> float d = 4.0f / 3.0f;
Or even:
float d = 4.0 / 3.0;
as the compiler will probably optimize the division into a constant
assignment.
/Leigh
[toc] | [prev] | [next] | [standalone]
| From | Leigh Johnston <leigh@i42.co.uk> |
|---|---|
| Date | 2011-10-17 21:33 +0100 |
| Message-ID | <Ieedndjg-aOtDAHTnZ2dnUVZ8j-dnZ2d@giganews.com> |
| In reply to | #10944 |
On 17/10/2011 21:31, Leigh Johnston wrote:
> On 17/10/2011 21:25, Leigh Johnston wrote:
>> On 17/10/2011 21:23, Ian Collins wrote:
>>> On 10/18/11 09:05 AM, Saeed Amrollahi wrote:
>>>> On Oct 17, 10:40 pm, ramtin<tom.t.2...@gmail.com> wrote:
>>>>> hi all ,
>>>>>
>>>>> #include "stdafx.h"
>>>>> #include<stdio.h>
>>>>> using namespace System;
>>>>>
>>>>> int main(array<System::String ^> ^args)
>>>>> {
>>>>> float d = 4 / 3 ;
>>>>> printf("%f",d);
>>>>> return 0;
>>>>>
>>>>> }
>>>>>
>>>>> when you run this ,it will be 1 in d ,but it should be 1.3333 in it
>>>>> !!!
>>>>
>>>> Hi Ramtin
>>>> Besides what Dombo wrote you can use static_cast:
>>>> float d = static_cast<float>(4)/3;
>>>
>>> If the OP were using C++, wouldn't it be easier just to write
>>>
>>> float d = float(4) / 3;
>>
>> No it would be easier to just write
>>
>> float d = 4.0f / 3.0f;
>
> Or even:
>
> float d = 4.0 / 3.0;
>
> as the compiler will probably optimize the division into a constant
> assignment.
>
Actually no as that will probably result in a truncation warning so
yeah, 4.0f / 3.0f is the way to go.
/Leigh
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-10-18 09:35 +1300 |
| Message-ID | <9g3ht3FpouU4@mid.individual.net> |
| In reply to | #10944 |
On 10/18/11 09:31 AM, Leigh Johnston wrote:
> On 17/10/2011 21:25, Leigh Johnston wrote:
>> On 17/10/2011 21:23, Ian Collins wrote:
>>> On 10/18/11 09:05 AM, Saeed Amrollahi wrote:
>>>> On Oct 17, 10:40 pm, ramtin<tom.t.2...@gmail.com> wrote:
>>>>> hi all ,
>>>>>
>>>>> #include "stdafx.h"
>>>>> #include<stdio.h>
>>>>> using namespace System;
>>>>>
>>>>> int main(array<System::String ^> ^args)
>>>>> {
>>>>> float d = 4 / 3 ;
>>>>> printf("%f",d);
>>>>> return 0;
>>>>>
>>>>> }
>>>>>
>>>>> when you run this ,it will be 1 in d ,but it should be 1.3333 in it !!!
>>>>
>>>> Hi Ramtin
>>>> Besides what Dombo wrote you can use static_cast:
>>>> float d = static_cast<float>(4)/3;
>>>
>>> If the OP were using C++, wouldn't it be easier just to write
>>>
>>> float d = float(4) / 3;
>>
>> No it would be easier to just write
>>
>> float d = 4.0f / 3.0f;
>
> Or even:
>
> float d = 4.0 / 3.0;
>
> as the compiler will probably optimize the division into a constant
> assignment.
That was already posted (the "what Dombo wrote" referenced above).
My point was there is no need to use static_cast, a temporary will do.
If the '4' was an integer variable for example.
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | ramtin <tom.t.2090@gmail.com> |
|---|---|
| Date | 2011-10-17 13:49 -0700 |
| Message-ID | <3e788fa7-5555-46f7-892a-68339ee1571e@f16g2000yqk.googlegroups.com> |
| In reply to | #10946 |
On Oct 17, 1:35 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> On 10/18/11 09:31 AM, Leigh Johnston wrote:
>
>
>
>
>
>
>
>
>
> > On 17/10/2011 21:25, Leigh Johnston wrote:
> >> On 17/10/2011 21:23, Ian Collins wrote:
> >>> On 10/18/11 09:05 AM, Saeed Amrollahi wrote:
> >>>> On Oct 17, 10:40 pm, ramtin<tom.t.2...@gmail.com> wrote:
> >>>>> hi all ,
>
> >>>>> #include "stdafx.h"
> >>>>> #include<stdio.h>
> >>>>> using namespace System;
>
> >>>>> int main(array<System::String ^> ^args)
> >>>>> {
> >>>>> float d = 4 / 3 ;
> >>>>> printf("%f",d);
> >>>>> return 0;
>
> >>>>> }
>
> >>>>> when you run this ,it will be 1 in d ,but it should be 1.3333 in it !!!
>
> >>>> Hi Ramtin
> >>>> Besides what Dombo wrote you can use static_cast:
> >>>> float d = static_cast<float>(4)/3;
>
> >>> If the OP were using C++, wouldn't it be easier just to write
>
> >>> float d = float(4) / 3;
>
> >> No it would be easier to just write
>
> >> float d = 4.0f / 3.0f;
>
> > Or even:
>
> > float d = 4.0 / 3.0;
>
> > as the compiler will probably optimize the division into a constant
> > assignment.
>
> That was already posted (the "what Dombo wrote" referenced above).
>
> My point was there is no need to use static_cast, a temporary will do.
> If the '4' was an integer variable for example.
>
> --
> Ian Collins
thanks of all . . .
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-10-18 09:19 +1300 |
| Message-ID | <9g3gusFpouU2@mid.individual.net> |
| In reply to | #10936 |
On 10/18/11 08:40 AM, ramtin wrote: > hi all , > > #include "stdafx.h" > #include<stdio.h> > using namespace System; > > int main(array<System::String ^> ^args) This looks like a language almost, but not entirely, unlike C++. -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | "Paul" <pchrist<nospam>or@yahoo.co.uk> |
|---|---|
| Date | 2011-10-18 00:55 +0100 |
| Message-ID | <j7ifa7$1h10$1@adenine.netfront.net> |
| In reply to | #10941 |
"Ian Collins" <ian-news@hotmail.com> wrote in message news:9g3gusFpouU2@mid.individual.net... > On 10/18/11 08:40 AM, ramtin wrote: >> hi all , >> >> #include "stdafx.h" >> #include<stdio.h> >> using namespace System; >> >> int main(array<System::String ^> ^args) > > This looks like a language almost, but not entirely, unlike C++. > That is the syntax use din MSVC++ when you create a windows form projec(C++), probably a .net thing. --- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | SG <s.gesemann@gmail.com> |
|---|---|
| Date | 2011-10-18 05:34 -0700 |
| Message-ID | <e90591e7-d70e-4326-9a90-43b47acbfcb5@m4g2000yqm.googlegroups.com> |
| In reply to | #10949 |
On 18 Okt., 01:55, Paul wrote: > Ian Collins wrote in message > > [...] ramtin wrote: > > >> int main(array<System::String ^> ^args) > > > This looks like a language almost, but not entirely, unlike C++. > > That is the syntax use din MSVC++ when you create a windows form > projec(C++), probably a .net thing. I would guess that a large fraction of the competent regulars (including Ian) already know exactly what it is: C++/CLI. And yes, that's what you get if you ask Herb Sutter to make .NET easily accessible from C++ by use of language extensions. Off-topic: I makes me chuckle a bit to see almost the same syntax being used for C++/CX where the CX language extensions are used to deal with WinRT's ref-counting object system. I guess Microsoft lost a bit of interest in .NET and C++/CLI since this seems to make the CLI and CX extensions mutually exclusive. Btw, I can recommend Herb Sutter's "modern C++" talk. It almost sounds like he's trying to convert .NET developers. "Look, how easy it is to write modern and safe C++ code!". Cheers! SG
[toc] | [prev] | [next] | [standalone]
| From | Christopher <cpisz@austin.rr.com> |
|---|---|
| Date | 2011-10-27 14:29 -0700 |
| Message-ID | <bd838e28-bcfd-4c3a-9915-b1b7811d2bcb@a17g2000yqj.googlegroups.com> |
| In reply to | #10967 |
On Oct 18, 7:34 am, SG <s.gesem...@gmail.com> wrote: > On 18 Okt., 01:55, Paul wrote: > > > Ian Collins wrote in message > > > [...] ramtin wrote: > > > >> int main(array<System::String ^> ^args) > > > > This looks like a language almost, but not entirely, unlike C++. > > > That is the syntax use din MSVC++ when you create a windows form > > projec(C++), probably a .net thing. > > I would guess that a large fraction of the competent regulars > (including Ian) already know exactly what it is: C++/CLI. And yes, > that's what you get if you ask Herb Sutter to make .NET easily > accessible from C++ by use of language extensions. > > Off-topic: I makes me chuckle a bit to see almost the same syntax > being used for C++/CX where the CX language extensions are used to > deal with WinRT's ref-counting object system. I guess Microsoft lost a > bit of interest in .NET and C++/CLI since this seems to make the CLI > and CX extensions mutually exclusive. Btw, I can recommend Herb > Sutter's "modern C++" talk. It almost sounds like he's trying to > convert .NET developers. "Look, how easy it is to write modern and > safe C++ code!". > > Cheers! > SG I never really understood what advantage there would be in using C++/ CLI. If I want CLI, why wouldn't I just use C# instead? Maybe so I can have pointers? OT anyway I suppose.
[toc] | [prev] | [next] | [standalone]
| From | Dombo <dombo@disposable.invalid> |
|---|---|
| Date | 2011-10-28 18:14 +0200 |
| Message-ID | <4eaad4d4$0$14713$5fc3050@news.tiscali.nl> |
| In reply to | #11121 |
Op 27-Oct-11 23:29, Christopher schreef: > On Oct 18, 7:34 am, SG<s.gesem...@gmail.com> wrote: >> On 18 Okt., 01:55, Paul wrote: >> >>> Ian Collins wrote in message >>>> [...] ramtin wrote: >> >>>>> int main(array<System::String ^> ^args) >> >>>> This looks like a language almost, but not entirely, unlike C++. >> >>> That is the syntax use din MSVC++ when you create a windows form >>> projec(C++), probably a .net thing. >> >> I would guess that a large fraction of the competent regulars >> (including Ian) already know exactly what it is: C++/CLI. And yes, >> that's what you get if you ask Herb Sutter to make .NET easily >> accessible from C++ by use of language extensions. >> >> Off-topic: I makes me chuckle a bit to see almost the same syntax >> being used for C++/CX where the CX language extensions are used to >> deal with WinRT's ref-counting object system. I guess Microsoft lost a >> bit of interest in .NET and C++/CLI since this seems to make the CLI >> and CX extensions mutually exclusive. Btw, I can recommend Herb >> Sutter's "modern C++" talk. It almost sounds like he's trying to >> convert .NET developers. "Look, how easy it is to write modern and >> safe C++ code!". >> >> Cheers! >> SG > > I never really understood what advantage there would be in using C++/ > CLI. If I want CLI, why wouldn't I just use C# instead? +1
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2011-10-28 21:06 -0700 |
| Message-ID | <30622906.1033.1319861173538.JavaMail.geo-discussion-forums@prfk19> |
| In reply to | #10936 |
float d1= 4/3 ; /* promote to inetger only in the right hand side result */ float d2= 4.0/3 ; /* promote to float */ float d3= 4/3.0 ; float d4= 4.0/3.0;
[toc] | [prev] | [next] | [standalone]
| From | red floyd <no.spam.here@its.invalid> |
|---|---|
| Date | 2011-10-28 22:14 -0700 |
| Message-ID | <j8g236$agd$2@dont-email.me> |
| In reply to | #11136 |
On 10/28/2011 9:06 PM, 88888 Dihedral wrote: > float d1= 4/3 ; /* promote to inetger only in the right hand side result */ No, that's integer arithmetic, result promoted to float. > > float d2= 4.0/3 ; /* promote to float */ > float d3= 4/3.0 ; > float d4= 4.0/3.0; Technically, the first two are promote to double, truncate to float. The third is already double, truncate to float.
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2011-10-28 23:27 -0700 |
| Message-ID | <5339181.3288.1319869626025.JavaMail.geo-discussion-forums@prog16> |
| In reply to | #11137 |
red floyd於 2011年10月29日星期六UTC+8下午1時14分07秒寫道: > On 10/28/2011 9:06 PM, 88888 Dihedral wrote: > > float d1= 4/3 ; /* promote to inetger only in the right hand side result */ > No, that's integer arithmetic, result promoted to float. > > > > > float d2= 4.0/3 ; /* promote to float */ > > float d3= 4/3.0 ; > > float d4= 4.0/3.0; > > Technically, the first two are promote to double, truncate to float. > The third is already double, truncate to float. ------------------------------------------------------ int x=3; int y=4; float d = x/y ; float d= ((float)x)/y ; /* whether the compiler knows x,y are constants up to now ? */
[toc] | [prev] | [next] | [standalone]
| From | red floyd <no.spam.here@its.invalid> |
|---|---|
| Date | 2011-10-29 08:24 -0700 |
| Message-ID | <j8h5r4$v4q$1@dont-email.me> |
| In reply to | #11138 |
On 10/28/2011 11:27 PM, 88888 Dihedral wrote: > > > red floyd於 2011年10月29日星期六UTC+8下午1時14分07秒寫道: >> On 10/28/2011 9:06 PM, 88888 Dihedral wrote: >>> float d1= 4/3 ; /* promote to inetger only in the right hand side result */ >> No, that's integer arithmetic, result promoted to float. >> >>> >>> float d2= 4.0/3 ; /* promote to float */ >>> float d3= 4/3.0 ; >>> float d4= 4.0/3.0; >> >> Technically, the first two are promote to double, truncate to float. >> The third is already double, truncate to float. > ------------------------------------------------------ > int x=3; > int y=4; > > float d = x/y ; > float d= ((float)x)/y ; > > /* whether the compiler knows x,y are constants up to now ? */ > What's your point? 4.0 and 3.0 are *DOUBLE* constants.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c++
csiph-web