scsi: Ensure command and transfer lengths are set for all SCSI devices
[qemu-kvm.git] / qfloat.c
blob98338f3b71a442971e5a69e5d85f78c80194ff85
1 /*
2 * QFloat Module
4 * Copyright IBM, Corp. 2009
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
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.
14 #include "qfloat.h"
15 #include "qobject.h"
16 #include "qemu-common.h"
18 static void qfloat_destroy_obj(QObject *obj);
20 static const QType qfloat_type = {
21 .code = QTYPE_QFLOAT,
22 .destroy = qfloat_destroy_obj,
25 /**
26 * qfloat_from_int(): Create a new QFloat from a float
28 * Return strong reference.
30 QFloat *qfloat_from_double(double value)
32 QFloat *qf;
34 qf = g_malloc(sizeof(*qf));
35 qf->value = value;
36 QOBJECT_INIT(qf, &qfloat_type);
38 return qf;
41 /**
42 * qfloat_get_double(): Get the stored float
44 double qfloat_get_double(const QFloat *qf)
46 return qf->value;
49 /**
50 * qobject_to_qfloat(): Convert a QObject into a QFloat
52 QFloat *qobject_to_qfloat(const QObject *obj)
54 if (qobject_type(obj) != QTYPE_QFLOAT)
55 return NULL;
57 return container_of(obj, QFloat, base);
60 /**
61 * qfloat_destroy_obj(): Free all memory allocated by a
62 * QFloat object
64 static void qfloat_destroy_obj(QObject *obj)
66 assert(obj != NULL);
67 g_free(qobject_to_qfloat(obj));