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
15 #include "type_util.h"
18 * uint64_t to double conversions taken from gstutils.c of GStreamer project
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
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.
39 type_util_uint64_to_double(uint64_t value
)
41 if (value
& UINT64_C (0x8000000000000000))
42 return (double) ((int64_t) value
) + (double) 18446744073709551616.;
44 return (double) ((int64_t) value
);
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
63 * indent-tabs-mode: nil
66 * ex: set shiftwidth=2 tabstop=8 expandtab:
67 * :indentSize=2:tabSize=8:noTabs=true: