| 1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- |
| 2 |
* |
| 3 |
* Copyright (C) 2011 Richard Hughes <[email protected]> |
| 4 |
* |
| 5 |
* Licensed under the GNU General Public License Version 2 |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 |
*/ |
| 21 |
|
| 22 |
#if !defined (__COLORHUG_H_INSIDE__) && !defined (CD_COMPILATION) |
| 23 |
#error "Only <colorhug.h> can be included directly." |
| 24 |
#endif |
| 25 |
|
| 26 |
#ifndef __CH_MATH_H |
| 27 |
#define __CH_MATH_H |
| 28 |
|
| 29 |
#include <glib.h> |
| 30 |
|
| 31 |
#include "ch-common.h" |
| 32 |
|
| 33 |
G_BEGIN_DECLS |
| 34 |
|
| 35 |
/* a 32 bit struct to hold numbers from the range -32767 to +32768 |
| 36 |
* with a precision of at least 0.000015 */ |
| 37 |
typedef union { |
| 38 |
struct { |
| 39 |
guint8 bytes[4]; |
| 40 |
}; |
| 41 |
struct { |
| 42 |
guint16 fraction; |
| 43 |
gint16 offset; |
| 44 |
}; |
| 45 |
struct { |
| 46 |
gint32 raw; |
| 47 |
}; |
| 48 |
} ChPackedFloat; |
| 49 |
|
| 50 |
gint32 ch_packed_float_get_value (const ChPackedFloat *pf); |
| 51 |
void ch_packed_float_set_value (ChPackedFloat *pf, |
| 52 |
const gint32 value); |
| 53 |
|
| 54 |
void ch_packed_float_to_double (const ChPackedFloat *pf, |
| 55 |
gdouble *value); |
| 56 |
void ch_double_to_packed_float (gdouble value, |
| 57 |
ChPackedFloat *pf); |
| 58 |
|
| 59 |
ChError ch_packed_float_add (const ChPackedFloat *pf1, |
| 60 |
const ChPackedFloat *pf2, |
| 61 |
ChPackedFloat *result); |
| 62 |
ChError ch_packed_float_multiply (const ChPackedFloat *pf1, |
| 63 |
const ChPackedFloat *pf2, |
| 64 |
ChPackedFloat *result); |
| 65 |
|
| 66 |
G_END_DECLS |
| 67 |
|
| 68 |
#endif /* __CH_MATH_H */ |