File: basic_types.rst

package info (click to toggle)
xtl 0.8.1-1~0.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,180 kB
  • sloc: cpp: 16,767; makefile: 164; python: 25
file content (78 lines) | stat: -rw-r--r-- 2,284 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht

   Distributed under the terms of the BSD 3-Clause License.

   The full license is in the file LICENSE, distributed with this software.

Basic types
===========

xbasic_fixed_string
-------------------

TODO

xcomplex
--------

`xcomplex` is the equivalent to `std::complex`, where the real ang imaginary
part can be stored either as values, or as references. Therefore, it can be
used as a proxy on real values already initialized. This is particularly
interesting for storing real and imaginary parts in different containers,
and gather them as complex values for computation. This allows optimzations
(such as vectorization) on the real and imgaginary values.

.. code::

    #include <iostream>
    #include <vector>
    #include "xtl/xcomplex.hpp"

    std::vector<double> arg1_real = { 1., 2.};
    std::vector<double> arg1_imag = { 3., 4.};
    std::vector<double> arg2_real = { 2., 4.};
    std::vector<double> arg2_real = { 1., 3.};
    std::vector<double> res_real(2);
    std::vector<double> res_imag(2);

    using complex = xtl::xcomplex<double&, double&>;
    using const_complex = xtl::xcomplex<const double&, const double&>;
    for (size_t i = 0; i < 2; ++i)
    {
        complex res(res_real[i], res_img[i]);
        res = const_complex(arg1_real, arg1_imag) * const_complex(arg2_real, arg2_imag);
        std::cout << "res = (" << res.real(), << ", " << res.imag() << std::endl;
    }

The API of `xtl::xcomplex` is the same as that of `std::complex`, with the ability
to store values as references. Full documentation can be found on
`cppreference <https://en.cppreference.com/w/cpp/numeric/complex>`_.

half_float
----------

The `half_float` class implements an IEEE-conformant half-precision floating-point type
with the usual arithmetic operators and conversions. It is implicitly convertible from
single-precision floating-point, which makes expressions and functions with mixed-type
operands to be of the most precise operand type.

.. code::

    #include <iostream<
    #include "xtl/xhalf.hpp"

    xtl::half_float f0 = 1.0f;
    xtl::half_float f1 = 2.0f;
    auto res = f0 + f1;
    std::cout << res << std::endl;

xmasked_value
-------------

TODO

xoptional
---------

TODO