add typetest.cpp
This commit is contained in:
parent
04851b7e5f
commit
ae7f6839cc
2 changed files with 34 additions and 0 deletions
|
@ -3,5 +3,6 @@ set(CMAKE_CXX_COMPILER "clang++")
|
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Weffc++")
|
||||
|
||||
add_executable(typetest typetest.cpp)
|
||||
add_executable(auto_ptr auto_ptr.cpp)
|
||||
add_executable(unique_ptr unique_ptr.cpp)
|
||||
|
|
33
typetest.cpp
Normal file
33
typetest.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
int someInteger = 256;
|
||||
short someShort;
|
||||
long someLong;
|
||||
float someFloat;
|
||||
double someDouble;
|
||||
|
||||
someInteger++;
|
||||
assert(someInteger == 257);
|
||||
|
||||
someInteger *= 2;
|
||||
assert(someInteger == 514);
|
||||
|
||||
someShort = (short) someInteger;
|
||||
assert((int) someShort == 514); // (short more than 1 byte)
|
||||
|
||||
someLong = someShort * 10000;
|
||||
assert(someLong == 5140000l);
|
||||
|
||||
someFloat = someLong * 0.785;
|
||||
assert(abs(someFloat - 4034900.000) < 0.0001);
|
||||
|
||||
someDouble = (double)someFloat / 100000;
|
||||
assert(abs(someDouble - 40.349) < 0.0001);
|
||||
|
||||
std::cout << someDouble << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue