Qt: TCP Stream Graphs dialog updates.
[metze/wireshark/wip.git] / wsutil / type_util.c
1 /* type_util.c
2  * Types utility routines
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #include "config.h"
12
13 #include "type_util.h"
14
15 /*
16  * guint64 to gdouble conversions taken from gstutils.c of GStreamer project
17  *
18  * GStreamer
19  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
20  *                    2000 Wim Taymans <wtay@chello.be>
21  *                    2002 Thomas Vander Stichele <thomas@apestaart.org>
22  *
23  * gstutils.h: Header for various utility functions
24  *
25  * GNU GPL v2
26  *
27  */
28
29 /* work around error C2520: conversion from unsigned __int64 to double
30  * not implemented, use signed __int64
31  *
32  * These are implemented as functions because on some platforms a 64bit int to
33  * double conversion is not defined/implemented.
34  */
35
36 gdouble
37 type_util_guint64_to_gdouble(guint64 value)
38 {
39   if (value & G_GUINT64_CONSTANT (0x8000000000000000))
40     return (gdouble) ((gint64) value) + (gdouble) 18446744073709551616.;
41   else
42     return (gdouble) ((gint64) value);
43 }
44
45 guint64
46 type_util_gdouble_to_guint64(gdouble value)
47 {
48   if (value < (gdouble) 9223372036854775808.)   /* 1 << 63 */
49     return ((guint64) ((gint64) value));
50
51   value -= (gdouble) 18446744073709551616.;
52   return ((guint64) ((gint64) value));
53 }
54
55 /*
56  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
57  *
58  * Local Variables:
59  * c-basic-offset: 2
60  * tab-width: 8
61  * indent-tabs-mode: nil
62  * End:
63  *
64  * ex: set shiftwidth=2 tabstop=8 expandtab:
65  * :indentSize=2:tabSize=8:noTabs=true:
66  */