regen pidl all: rm epan/dissectors/pidl/*-stamp; pushd epan/dissectors/pidl/ && make...
[wireshark-sm.git] / wsutil / type_util.c
blobcfe9fe7086db1ea2aee1271ffddb6c40502322cf
1 /* type_util.c
2 * Types utility routines
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "config.h"
13 #include <glib.h>
15 #include "type_util.h"
18 * uint64_t to double conversions taken from gstutils.c of GStreamer project
20 * GStreamer
21 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
22 * 2000 Wim Taymans <wtay@chello.be>
23 * 2002 Thomas Vander Stichele <thomas@apestaart.org>
25 * gstutils.h: Header for various utility functions
27 * GNU GPL v2
31 /* work around error C2520: conversion from unsigned __int64 to double
32 * not implemented, use signed __int64
34 * These are implemented as functions because on some platforms a 64bit int to
35 * double conversion is not defined/implemented.
38 double
39 type_util_uint64_to_double(uint64_t value)
41 if (value & UINT64_C (0x8000000000000000))
42 return (double) ((int64_t) value) + (double) 18446744073709551616.;
43 else
44 return (double) ((int64_t) value);
47 uint64_t
48 type_util_double_to_uint64(double value)
50 if (value < (double) 9223372036854775808.) /* 1 << 63 */
51 return ((uint64_t) ((int64_t) value));
53 value -= (double) 18446744073709551616.;
54 return ((uint64_t) ((int64_t) value));
58 * Editor modelines - https://www.wireshark.org/tools/modelines.html
60 * Local Variables:
61 * c-basic-offset: 2
62 * tab-width: 8
63 * indent-tabs-mode: nil
64 * End:
66 * ex: set shiftwidth=2 tabstop=8 expandtab:
67 * :indentSize=2:tabSize=8:noTabs=true: