Newsgroup: comp.lang.c++
Subject: converting double to int
From: ram@...
Date: 19 Nov 2013 12:23:40 GMT
#include <iostream>
#include <ostream>
int main()
{ ::std::cout << int( 2.6 )<< '\n';
::std::cout << int{ 2.6 }<< '\n';
::std::cout << ( int )2.6 << '\n';
::std::cout << static_cast< int >( 2.6 )<< '\n'; }
Under which circumstances is which way of the above to
convert a double to an int the best style?
Are there any differences in the semantics above?
Is there yet another way to write the conversion?
PS: Oh yeah: the int{} notation forbids narrowing!
I should have compiled with -pedantic-errors!
So, int{} differs from the rest, it is not a kind of
cast or conversion, rather a compile-time assertion
of the number being not wider than int?
Is the number ?2.6? an argument or an operand in
?int{ 2.6 }?? It does not seem to be a function
call. So it is not an argument. But is this an
application of an operator? No. So it also is not
an operand? So, what is it then?
Subject: converting double to int
From: ram@...
Date: 19 Nov 2013 12:23:40 GMT
#include <iostream>
#include <ostream>
int main()
{ ::std::cout << int( 2.6 )<< '\n';
::std::cout << int{ 2.6 }<< '\n';
::std::cout << ( int )2.6 << '\n';
::std::cout << static_cast< int >( 2.6 )<< '\n'; }
Under which circumstances is which way of the above to
convert a double to an int the best style?
Are there any differences in the semantics above?
Is there yet another way to write the conversion?
PS: Oh yeah: the int{} notation forbids narrowing!
I should have compiled with -pedantic-errors!
So, int{} differs from the rest, it is not a kind of
cast or conversion, rather a compile-time assertion
of the number being not wider than int?
Is the number ?2.6? an argument or an operand in
?int{ 2.6 }?? It does not seem to be a function
call. So it is not an argument. But is this an
application of an operator? No. So it also is not
an operand? So, what is it then?
via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?131627-converting-double-to-int&goto=newpost
View all the progranning help forums at:
http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums
No comments:
Post a Comment