From e7aaf2dedd0b9b8d2ab1a63ed0ba4f64abe1301b Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Sun, 28 Aug 2005 00:03:30 +0000
Subject: [PATCH] added wxLongLong::ToDouble()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35323 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/changes.txt           |  1 +
 docs/latex/wx/longlong.tex | 25 +++++++++++++++++++++++++
 include/wx/longlong.h      |  6 ++++++
 src/common/longlong.cpp    | 13 +++++++++++++
 4 files changed, 45 insertions(+)

diff --git a/docs/changes.txt b/docs/changes.txt
index 88c8290700..1f873e4e2a 100644
--- a/docs/changes.txt
+++ b/docs/changes.txt
@@ -15,6 +15,7 @@ All:
 - Added wxImage::RotateHue() and RGB <-> HSV conversions (John Anderson).
 - Fixed compilation with IBM xlC compiler.
 - wxABI_VERSION, see 'Backward Compatibility' topic overview in the manual.
+- Added wxLongLong::ToDouble()
 
 All (GUI):
 
diff --git a/docs/latex/wx/longlong.tex b/docs/latex/wx/longlong.tex
index 9676ca6152..68ed4dfa6a 100644
--- a/docs/latex/wx/longlong.tex
+++ b/docs/latex/wx/longlong.tex
@@ -46,18 +46,21 @@ No base class
 
 \latexignore{\rtfignore{\wxheading{Members}}}
 
+
 \membersection{wxLongLong::wxLongLong}\label{wxlonglongwxlonglongdef}
 
 \func{}{wxLongLong}{\void}
 
 Default constructor initializes the object to 0.
 
+
 \membersection{wxLongLong::wxLongLong}\label{wxlonglongwxlonglongll}
 
 \func{}{wxLongLong}{\param{wxLongLong\_t }{ll}}
 
 Constructor from native long long (only for compilers supporting it).
 
+
 \membersection{wxLongLong::wxLongLong}\label{wxlonglongwxlonglong}
 
 \func{}{wxLongLong}{\param{long }{hi}, \param{unsigned long }{lo}}
@@ -65,12 +68,14 @@ Constructor from native long long (only for compilers supporting it).
 Constructor from 2 longs: the high and low part are combined into one
 wxLongLong.
 
+
 \membersection{wxLongLong::operator=}\label{wxlonglongoperatorassign}
 
 \func{wxLongLong\& operator}{operator=}{\param{wxLongLong\_t }{ll}}
 
 Assignment operator from native long long (only for compilers supporting it).
 
+
 \membersection{wxLongLong::Abs}\label{wxlonglongabs}
 
 \constfunc{wxLongLong}{Abs}{\void}
@@ -80,6 +85,7 @@ Assignment operator from native long long (only for compilers supporting it).
 Returns an absolute value of wxLongLong - either making a copy (const version)
 or modifying it in place (the second one).  Not in wxULongLong.
 
+
 \membersection{wxLongLong::Assign}\label{wxlonglongassign}
 
 \func{wxLongLong\&}{Assign}{\param{double }{d}}
@@ -88,24 +94,35 @@ This allows to convert a double value to wxLongLong type. Such conversion is
 not always possible in which case the result will be silently truncated in a
 platform-dependent way.  Not in wxULongLong.
 
+
 \membersection{wxLongLong::GetHi}\label{wxlonglonggethi}
 
 \constfunc{long}{GetHi}{\void}
 
 Returns the high 32 bits of 64 bit integer.
 
+
 \membersection{wxLongLong::GetLo}\label{wxlonglonggetlo}
 
 \constfunc{unsigned long}{GetLo}{\void}
 
 Returns the low 32 bits of 64 bit integer.
 
+
 \membersection{wxLongLong::GetValue}\label{wxlonglonggetvalue}
 
 \constfunc{wxLongLong\_t}{GetValue}{\void}
 
 Convert to native long long (only for compilers supporting it)
 
+
+\membersection{wxLongLong::ToDouble}\label{wxlonglonggetdouble}
+
+\constfunc{double}{ToDouble}{\void}
+
+Returns the value as \texttt{double}.
+
+
 \membersection{wxLongLong::ToLong}\label{wxlonglongtolong}
 
 \constfunc{long}{ToLong}{\void}
@@ -114,24 +131,28 @@ Truncate wxLongLong to long. If the conversion loses data (i.e. the wxLongLong
 value is outside the range of built-in long type), an assert will be triggered
 in debug mode.
 
+
 \membersection{wxLongLong::ToString}\label{wxlonglongtostring}
 
 \constfunc{wxString}{ToString}{\void}
 
 Returns the string representation of a wxLongLong.
 
+
 \membersection{wxLongLong::operator$+$}\label{wxlonglongoperatorplus}
 
 \constfunc{wxLongLong}{operator$+$}{\param{const wxLongLong\& }{ll}}
 
 Adds 2 wxLongLongs together and returns the result.
 
+
 \membersection{wxLongLong::operator$+=$}\label{wxlonglongoperatorplusassign}
 
 \func{wxLongLong\&}{operator+}{\param{const wxLongLong\& }{ll}}
 
 Add another wxLongLong to this one.
 
+
 \membersection{wxLongLong::operator$++$}\label{wxlonglongoperatorinc}
 
 \func{wxLongLong\&}{operator$++$}{\void}
@@ -140,24 +161,28 @@ Add another wxLongLong to this one.
 
 Pre/post increment operator.
 
+
 \membersection{wxLongLong::operator$-$}\label{wxlonglongoperatorunaryminus}
 
 \constfunc{wxLongLong}{operator$-$}{\void}
 
 Returns the value of this wxLongLong with opposite sign.  Not in wxULongLong.
 
+
 \membersection{wxLongLong::operator$-$}\label{wxlonglongoperatorminus}
 
 \constfunc{wxLongLong}{operator$-$}{\param{const wxLongLong\& }{ll}}
 
 Subtracts 2 wxLongLongs and returns the result.
 
+
 \membersection{wxLongLong::operator$-=$}\label{wxlonglongoperatorminusassign}
 
 \func{wxLongLong\&}{operator-}{\param{const wxLongLong\& }{ll}}
 
 Subtracts another wxLongLong from this one.
 
+
 \membersection{wxLongLong::operator$--$}\label{wxlonglongoperatordec}
 
 \func{wxLongLong\&}{operator$--$}{\void}
diff --git a/include/wx/longlong.h b/include/wx/longlong.h
index 3adf4335b8..27cf9e8d1a 100644
--- a/include/wx/longlong.h
+++ b/include/wx/longlong.h
@@ -164,6 +164,9 @@ public:
         return (long)m_ll;
     }
 
+        // convert to double
+    double ToDouble() const { return m_ll; }
+
     // don't provide implicit conversion to wxLongLong_t or we will have an
     // ambiguity for all arithmetic operations
     //operator wxLongLong_t() const { return m_ll; }
@@ -590,6 +593,9 @@ public:
         return (long)m_lo;
     }
 
+        // convert to double
+    double ToDouble() const;
+
     // operations
         // addition
     wxLongLongWx operator+(const wxLongLongWx& ll) const;
diff --git a/src/common/longlong.cpp b/src/common/longlong.cpp
index 4646ce0d7b..aa5207c3f8 100644
--- a/src/common/longlong.cpp
+++ b/src/common/longlong.cpp
@@ -134,6 +134,19 @@ wxLongLongWx& wxLongLongWx::Assign(double d)
     return *this;
 }
 
+double wxLongLongWx::ToDouble() const
+{
+    double d = m_hi;
+    d *= 1.0 + (double)ULONG_MAX;
+    d += m_lo;
+
+#ifdef wxLONGLONG_TEST_MODE
+    wxASSERT( d == m_ll );
+#endif // wxLONGLONG_TEST_MODE
+
+    return d;
+}
+
 wxLongLongWx wxLongLongWx::operator<<(int shift) const
 {
     wxLongLongWx ll(*this);
-- 
2.50.0

