/usr/local/include/OpenEXR/ImfRational.h
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // SPDX-License-Identifier: BSD-3-Clause |
3 | | // Copyright (c) Contributors to the OpenEXR Project. |
4 | | // |
5 | | |
6 | | #ifndef INCLUDED_IMF_RATIONAL_H |
7 | | #define INCLUDED_IMF_RATIONAL_H |
8 | | |
9 | | #include "ImfExport.h" |
10 | | #include "ImfNamespace.h" |
11 | | |
12 | | //----------------------------------------------------------------------------- |
13 | | // |
14 | | // Rational numbers |
15 | | // |
16 | | // A rational number is represented as pair of integers, n and d. |
17 | | // The value of of the rational number is |
18 | | // |
19 | | // n/d for d > 0 |
20 | | // positive infinity for n > 0, d == 0 |
21 | | // negative infinity for n < 0, d == 0 |
22 | | // not a number (NaN) for n == 0, d == 0 |
23 | | // |
24 | | //----------------------------------------------------------------------------- |
25 | | |
26 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER |
27 | | |
28 | | class IMF_EXPORT_TYPE Rational |
29 | | { |
30 | | public: |
31 | | int n; // numerator |
32 | | unsigned int d; // denominator |
33 | | |
34 | | //---------------------------------------- |
35 | | // Default constructor, sets value to zero |
36 | | //---------------------------------------- |
37 | | |
38 | | Rational () : n (0), d (1) {} |
39 | | |
40 | | //------------------------------------- |
41 | | // Constructor, explicitly sets n and d |
42 | | //------------------------------------- |
43 | | |
44 | | Rational (int n, int d) : n (n), d (d) {} |
45 | | |
46 | | //---------------------------- |
47 | | // Constructor, approximates x |
48 | | //---------------------------- |
49 | | |
50 | | IMF_EXPORT |
51 | | explicit Rational (double x); |
52 | | |
53 | | //--------------------------------- |
54 | | // Approximate conversion to double |
55 | | //--------------------------------- |
56 | | |
57 | 0 | operator double () const { return double (n) / double (d); } |
58 | | }; |
59 | | |
60 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT |
61 | | |
62 | | #endif |