aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/lang/cpp/long.rst
diff options
context:
space:
mode:
authorHanna Mendes Levitin <hanna@anomaly-3.local>2010-12-01 03:37:07 -0600
committerHanna Mendes Levitin <hanna@anomaly-3.local>2010-12-01 03:37:07 -0600
commita0549b4a15a7093f990fffa4bc1d2d52ec1c16e2 (patch)
tree9c6383570be6d045db4d8942ca3137fc3cb5b8a0 /docs/source/lang/cpp/long.rst
parent3b7f16dba295da3a0071564ac284c25dc56e6b18 (diff)
downloadlibrambutan-a0549b4a15a7093f990fffa4bc1d2d52ec1c16e2.tar.gz
librambutan-a0549b4a15a7093f990fffa4bc1d2d52ec1c16e2.zip
docs, now with style
Diffstat (limited to 'docs/source/lang/cpp/long.rst')
-rw-r--r--docs/source/lang/cpp/long.rst52
1 files changed, 52 insertions, 0 deletions
diff --git a/docs/source/lang/cpp/long.rst b/docs/source/lang/cpp/long.rst
new file mode 100644
index 0000000..d8498c0
--- /dev/null
+++ b/docs/source/lang/cpp/long.rst
@@ -0,0 +1,52 @@
+.. highlight:: cpp
+
+.. _lang-long:
+
+``long``
+========
+
+The ``long`` data type stores extended size integer values. You can
+use a ``long`` when your values are too large to fit into an :ref:`int
+<lang-int>`. A ``long`` occupies 8 bytes of memory. This yields a
+range of approximately -9.2×10^18 to 9.2×10^18 (that's 9.2 billion
+billion, or about 92 million times the number of stars in the Milky
+Way galaxy). The exact range of a ``long`` on the Maple is from
+-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, or -2^63 to
+(2^63-1). A ``long`` it is subject to the same :ref:`overflow issues
+<lang-variables-rollover>` as any numeric data type.
+
+Here's an example of declaring a long (see :ref:`integer constants
+<lang-constants-integers-u-l>` for an explanation of the "L" at the end of the
+number)::
+
+ // Speed of light in nanometers per second (approximate).
+ long c = 299792458000000000L;
+
+The general syntax for declaring an ``long`` variable named ``var``,
+then giving it value ``val``, looks like::
+
+ long var = val;
+
+This is identical to the ``int`` syntax, with ``long`` replacing
+``int``.
+
+Note that ``long`` values will still :ref:`overflow
+<lang-int-overflow>`, just like ``int`` values, but their much
+larger range makes this less likely to happen.
+
+The downside to using a ``long`` instead of an ``int`` (besides the
+extra storage) is that :ref:`arithmetic <lang-arithmetic>` operations
+on ``long``\ s will take slightly longer than on ``int``\ s.
+
+See Also
+--------
+
+- :ref:`char <lang-char>`
+- :ref:`unsigned char <lang-unsignedchar>`
+- :ref:`int <lang-int>`
+- :ref:`unsigned int <lang-unsignedint>`
+- :ref:`unsigned long <lang-unsignedlong>`
+- :ref:`Integer Constants <lang-constants-integers>`
+- :ref:`Variables <lang-variables>`
+
+.. include:: cc-attribution.txt