xo-unit: example: + ex4 .. ex6
This commit is contained in:
parent
7c7373427e
commit
ba31d2c112
7 changed files with 116 additions and 0 deletions
|
|
@ -1,3 +1,6 @@
|
|||
add_subdirectory(ex1)
|
||||
add_subdirectory(ex2)
|
||||
add_subdirectory(ex3)
|
||||
add_subdirectory(ex4)
|
||||
add_subdirectory(ex5)
|
||||
add_subdirectory(ex6)
|
||||
|
|
|
|||
15
example/ex4/CMakeLists.txt
Normal file
15
example/ex4/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# xo-unit/example/ex4/CMakeLists.txt
|
||||
|
||||
set(SELF_EXE xo_unit_ex4)
|
||||
set(SELF_SRCS ex4.cpp)
|
||||
|
||||
add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
xo_include_options2(${SELF_EXE})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# dependencies..
|
||||
|
||||
xo_self_dependency(${SELF_EXE} xo_unit)
|
||||
xo_dependency(${SELF_EXE} reflect)
|
||||
|
||||
# end CMakeLists.txt
|
||||
26
example/ex4/ex4.cpp
Normal file
26
example/ex4/ex4.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/** @file ex4.cpp **/
|
||||
|
||||
#include "xo/unit/quantity.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main () {
|
||||
namespace u = xo::unit::units;
|
||||
namespace qty = xo::unit::qty;
|
||||
using namespace std;
|
||||
|
||||
/* 20% volatility over 250 days (approx number of trading days in one year) */
|
||||
auto t1 = qty::milliseconds(1);
|
||||
/* 10% volatility over 30 days */
|
||||
auto t2 = qty::minutes(1);
|
||||
|
||||
auto r1 = t1 / t2.with_repr<double>();
|
||||
auto r2 = t2 / t1.with_repr<double>();
|
||||
|
||||
static_assert(same_as<decltype(r1), double>);
|
||||
static_assert(same_as<decltype(r2), double>);
|
||||
|
||||
cerr << "t1: " << t1 << ", t2: " << t2 << ", t1/t2: " << r1 << ", t2/t1: " << r2 << endl;
|
||||
}
|
||||
|
||||
/** end ex4.cpp */
|
||||
15
example/ex5/CMakeLists.txt
Normal file
15
example/ex5/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# xo-unit/example/ex5/CMakeLists.txt
|
||||
|
||||
set(SELF_EXE xo_unit_ex5)
|
||||
set(SELF_SRCS ex5.cpp)
|
||||
|
||||
add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
xo_include_options2(${SELF_EXE})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# dependencies..
|
||||
|
||||
xo_self_dependency(${SELF_EXE} xo_unit)
|
||||
xo_dependency(${SELF_EXE} reflect)
|
||||
|
||||
# end CMakeLists.txt
|
||||
23
example/ex5/ex5.cpp
Normal file
23
example/ex5/ex5.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/** @file ex5.cpp **/
|
||||
|
||||
#include "xo/unit/quantity.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main () {
|
||||
namespace u = xo::unit::units;
|
||||
namespace qty = xo::unit::qty;
|
||||
using namespace std;
|
||||
|
||||
/* 20% volatility over 250 days (approx number of trading days in one year) */
|
||||
auto q1 = qty::volatility250d(0.2);
|
||||
/* 10% volatility over 30 days */
|
||||
auto q2 = qty::volatility30d(0.1);
|
||||
|
||||
auto sum = q1 + q2;
|
||||
auto prod = q1 * q2;
|
||||
|
||||
cerr << "q1: " << q1 << ", q2: " << q2 << ", q1+q2: " << sum << ", q1*q2: " << prod << endl;
|
||||
}
|
||||
|
||||
/** end ex5.cpp */
|
||||
15
example/ex6/CMakeLists.txt
Normal file
15
example/ex6/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# xo-unit/example/ex6/CMakeLists.txt
|
||||
|
||||
set(SELF_EXE xo_unit_ex6)
|
||||
set(SELF_SRCS ex6.cpp)
|
||||
|
||||
add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
xo_include_options2(${SELF_EXE})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# dependencies..
|
||||
|
||||
xo_self_dependency(${SELF_EXE} xo_unit)
|
||||
xo_dependency(${SELF_EXE} reflect)
|
||||
|
||||
# end CMakeLists.txt
|
||||
19
example/ex6/ex6.cpp
Normal file
19
example/ex6/ex6.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/** @file ex6.cpp **/
|
||||
|
||||
#include "xo/unit/quantity.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main () {
|
||||
namespace u = xo::unit::units;
|
||||
namespace qty = xo::unit::qty;
|
||||
using namespace std;
|
||||
|
||||
auto t1 = qty::milliseconds(25.0);
|
||||
auto t1_usec = t1.with_unit<u::microsecond>();
|
||||
auto t1_sec = t1.with_unit<u::second>();
|
||||
|
||||
cerr << "t1: " << t1 << ", t1_usec: " << t1_usec << ", t1_sec: " << t1_sec << endl;
|
||||
}
|
||||
|
||||
/** end ex6.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue