Merge commit 'fe270d044d512a308fb1fdf02cb11db46df29cdb' into upstream-merge
[qemu/qemu-dev-zwu.git] / qfloat.c
blob05215f50270c7ce4f2355613b97dcac962888caa
1 /*
2 * QFloat Module
4 * Copyright (C) 2009 Red Hat Inc.
6 * Authors:
7 * Luiz Capitulino <lcapitulino@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Copyright IBM, Corp. 2009
14 * Authors:
15 * Anthony Liguori <aliguori@us.ibm.com>
17 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
18 * See the COPYING.LIB file in the top-level directory.
22 #include "qfloat.h"
23 #include "qobject.h"
24 #include "qemu-common.h"
26 static void qfloat_destroy_obj(QObject *obj);
28 static const QType qfloat_type = {
29 .code = QTYPE_QFLOAT,
30 .destroy = qfloat_destroy_obj,
33 /**
34 * qfloat_from_int(): Create a new QFloat from a float
36 * Return strong reference.
38 QFloat *qfloat_from_double(double value)
40 QFloat *qf;
42 qf = qemu_malloc(sizeof(*qf));
43 qf->value = value;
44 QOBJECT_INIT(qf, &qfloat_type);
46 return qf;
49 /**
50 * qfloat_get_double(): Get the stored float
52 double qfloat_get_double(const QFloat *qf)
54 return qf->value;
57 /**
58 * qobject_to_qfloat(): Convert a QObject into a QFloat
60 QFloat *qobject_to_qfloat(const QObject *obj)
62 if (qobject_type(obj) != QTYPE_QFLOAT)
63 return NULL;
65 return container_of(obj, QFloat, base);
68 /**
69 * qfloat_destroy_obj(): Free all memory allocated by a
70 * QFloat object
72 static void qfloat_destroy_obj(QObject *obj)
74 assert(obj != NULL);
75 qemu_free(qobject_to_qfloat(obj));