{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Large Integers in Tables and Autotranslation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "JSON has a problem when integers get larger than 1016\n", "because JavaScript uses floating point for all its numbers.\n", "Most languages, including Python, R, and the JVM languages like Groovy can easily handle integers up to 1019,\n", "and sometimes larger.\n", "\n", "Numbers this large are useful for measuring time in nanoseconds, for example.\n", "\n", "BeakerX table and plot widgets have special support 64-bit and arbitrary precision values. Run these cells, then hover over the columns to see their types." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 64-bit Longs" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def millis = new Date().time\n", "def nanos = millis * 1000 * 1000L\n", "\n", "[[time: nanos + 7 * 1, next_time:(nanos + 77) * 1, temp:14.6],\n", " [time: nanos + 7 * 2, next_time:(nanos + 88) * 2, temp:18.1],\n", " [time: nanos + 7 * 3, next_time:(nanos + 99) * 3, temp:23.6]]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## BigNums (arbitrary precision)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def today = new Date()\n", "def millis = today.time\n", "// the \"g\" makes this a bignum, with as many bits as needed\n", "def nanos = millis * 1000 * 1000g\n", "\n", "[[time: nanos + 7 * 1, next_time:(nanos + 77) * 777, temp:3.351],\n", " [time: nanos + 7 * 2, next_time:(nanos + 88) * 888, temp:2.355],\n", " [time: nanos + 7 * 3, next_time:(nanos + 99) * 999, temp:2.728]]" ] } ], "metadata": { "kernelspec": { "display_name": "Groovy", "language": "groovy", "name": "groovy" }, "language_info": { "codemirror_mode": "groovy", "file_extension": ".groovy", "mimetype": "", "name": "Groovy", "nbconverter_exporter": "", "version": "2.4.3" } }, "nbformat": 4, "nbformat_minor": 2 }