Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 68 lines (58 sloc) 1.28 kb
68396ea9 » rmustacc
2011-06-24 Initial commit of d32e8d0 from qemu-kvm
1 /*
2 * QFloat Module
3 *
4 * Copyright IBM, Corp. 2009
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
11 *
12 */
13
14 #include "qfloat.h"
15 #include "qobject.h"
16 #include "qemu-common.h"
17
18 static void qfloat_destroy_obj(QObject *obj);
19
20 static const QType qfloat_type = {
21 .code = QTYPE_QFLOAT,
22 .destroy = qfloat_destroy_obj,
23 };
24
25 /**
26 * qfloat_from_int(): Create a new QFloat from a float
27 *
28 * Return strong reference.
29 */
30 QFloat *qfloat_from_double(double value)
31 {
32 QFloat *qf;
33
34 qf = qemu_malloc(sizeof(*qf));
35 qf->value = value;
36 QOBJECT_INIT(qf, &qfloat_type);
37
38 return qf;
39 }
40
41 /**
42 * qfloat_get_double(): Get the stored float
43 */
44 double qfloat_get_double(const QFloat *qf)
45 {
46 return qf->value;
47 }
48
49 /**
50 * qobject_to_qfloat(): Convert a QObject into a QFloat
51 */
52 QFloat *qobject_to_qfloat(const QObject *obj)
53 {
54 if (qobject_type(obj) != QTYPE_QFLOAT)
55 return NULL;
56
57 return container_of(obj, QFloat, base);
58 }
59
60 /**
61 * qfloat_destroy_obj(): Free all memory allocated by a
62 * QFloat object
63 */
64 static void qfloat_destroy_obj(QObject *obj)
65 {
66 assert(obj != NULL);
67 qemu_free(qobject_to_qfloat(obj));
68 }
Something went wrong with that request. Please try again.