YARP
Yet Another Robot Platform
NetFloat64.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef YARP_OS_NETFLOAT64_H
8#define YARP_OS_NETFLOAT64_H
9
10#include <yarp/conf/numeric.h>
11
12#include <yarp/os/api.h>
13
15//
16// The goal of this file is just to define a 64 bit signed little-endian
17// IEC 559/IEEE 754 floating point type.
18//
20
21#if !YARP_FLOAT64_IS_IEC559
22 // YARP assumes that floating point values are serialized as IEC 559/IEEE 754
23 // floating point types.
24 // If you receive the following error, this means that float and double, on
25 // your platform, are not IEC 559, and therefore some conversion must be
26 // performed whenever reading or writing a floating point value from the
27 // network.
28 // See, for example https://github.com/MalcolmMcLean/ieee754/ for a possible
29 // implementation of the read and write methods.
30 YARP_COMPILER_ERROR("Unsupported compiler. Please implement yarp::os::NetFloat64")
31#endif
32
33namespace yarp::os {
34
39#ifdef YARP_LITTLE_ENDIAN
40
42
43#else // YARP_LITTLE_ENDIAN
44
45typedef yarp::conf::float64_t RawNetFloat64;
46union UnionNetFloat64
47{
49 unsigned char c[8];
50};
52{
53private:
54 double raw_value;
55 double swap(double x) const;
56 RawNetFloat64 get() const;
57 void set(RawNetFloat64 v);
58
59public:
60 NetFloat64();
61 NetFloat64(RawNetFloat64 val);
62 operator RawNetFloat64() const;
63 RawNetFloat64 operator+(RawNetFloat64 v) const;
64 RawNetFloat64 operator-(RawNetFloat64 v) const;
65 RawNetFloat64 operator*(RawNetFloat64 v) const;
66 RawNetFloat64 operator/(RawNetFloat64 v) const;
67 void operator+=(RawNetFloat64 v);
68 void operator-=(RawNetFloat64 v);
69 void operator*=(RawNetFloat64 v);
70 void operator/=(RawNetFloat64 v);
71};
72
73#endif // YARP_LITTLE_ENDIAN
74
75} // namespace yarp::os
76
77#endif // YARP_OS_NETFLOAT64_H
Vector operator+(const Vector &a, const double &s)
Mathematical operations.
Definition: math.cpp:27
Vector operator-(const Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Definition: math.cpp:82
Vector operator*(double k, const Vector &b)
Scalar-vector product operator (defined in Math.h).
Definition: math.cpp:143
Vector & operator-=(Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Definition: math.cpp:98
Vector & operator+=(Vector &a, const double &s)
Addition operator between a scalar and a vector (defined in Math.h).
Definition: math.cpp:38
Vector & operator/=(Vector &a, const Vector &b)
Vector-vector element-wise division operator (defined in Math.h).
Definition: math.cpp:266
Vector operator/(const Vector &a, const Vector &b)
Vector-vector element-wise division operator (defined in Math.h).
Definition: math.cpp:260
Vector & operator*=(Vector &a, double k)
Vector-scalar product operator (defined in Math.h).
Definition: math.cpp:154
double float64_t
Definition: numeric.h:77
An interface to the operating system, including Port based communication.
yarp::conf::float64_t NetFloat64
Definition of the NetFloat64 type.
Definition: NetFloat64.h:41
#define YARP_COMPILER_ERROR(x)
Generate an error at build time on supported compilers.
Definition: system.h:112
#define YARP_os_API
Definition: api.h:18