Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.1 - 日本語

Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Scilabヘルプ >> Elementary Functions > Floating point > double

double

converts inttype integers or booleans into decimal encoding

Syntax

y = double(X)

Arguments

X

matrix of encoded integers or booleans

y

matrix of numbers in decimal notation

Description

converts data stored using 1, 2, 4 or 8 bytes integers into decimal representation on 8 bytes. If X entries are already double precision floats, nothing is done.

double() and iconvert(..,0) are equivalent and have the same speed.
Booleans can also be processed with double(). However, bool2s() does it roughly twice faster.
Since the mantissa of uint64 is encoded on 64 bits while the mantissa of (double precision) decimal numbers is encoded only on 52 bits, the relative accuracy of uint64 integers greater than 252 may then be up to 212 ~4000 times better for them than for "double". As a consequence, applying double() on int64 or uint64 integers greater than 252 change their values and downgrades their accuracy (roundoff errors). Some examples illustrating such effects are provided herebelow.

Examples

x = int8([0 12 140])
double(x)

// Applying double() rounds off and truncates int64() or uint64() numbers
// ----------------------------------------------------------------------
i = int64(2)^52        // 52 bits, as for decimal numbers mantissa
i = [i+(0:3:9)'  i+(3:30:93)'  i+(30:300:930)']
err = i - double(i)    // no errors for |integers|<= 2^52
i = int64(2)^53        // 53 bits integers => more accurate than decimal numbers
i = [i+(0:3:9)'  i+(3:30:93)'  i+(30:300:930)']
err = i - double(i)    // round-off errors appear
i = int64(2)^55
i = [i+(0:3:9)'  i+(3:30:93)'  i+(30:300:930)']
err = i - double(i)
i = int64(2)^62
i = [i+(0:3:9)'  i+(3:30:93)'  i+(30:300:930)']
err = i - double(i)
--> i = int64(2)^52     // 52 bits, as for decimal numbers mantissa
 i  =
  4503599627370496

--> i = [i+(0:3:9)'  i+(3:30:93)'  i+(30:300:930)']
 i  =
  4503599627370496  4503599627370499  4503599627370526
  4503599627370499  4503599627370529  4503599627370826
  4503599627370502  4503599627370559  4503599627371126
  4503599627370505  4503599627370589  4503599627371426

--> err = i - double(i)   // no errors for |integers|<= 2^52
 err  =
  0  0  0
  0  0  0
  0  0  0
  0  0  0

--> i = int64(2)^53      // 53 bits integers => more accurate than decimal numbers
 i  =
  9007199254740992

--> i = [i+(0:3:9)'  i+(3:30:93)'  i+(30:300:930)']
 i  =
  9007199254740992  9007199254740995  9007199254741022
  9007199254740995  9007199254741025  9007199254741322
  9007199254740998  9007199254741055  9007199254741622
  9007199254741001  9007199254741085  9007199254741922

--> err = i - double(i)     // round-off errors appear
 err  =
  0 -1  0
 -1  1  0
  0 -1  0
  1  1  0

--> i = int64(2)^55
 i  =
  36028797018963968

--> i = [i+(0:3:9)'  i+(3:30:93)'  i+(30:300:930)']
 i  =
  36028797018963968  36028797018963971  36028797018963998
  36028797018963971  36028797018964001  36028797018964298
  36028797018963974  36028797018964031  36028797018964598
  36028797018963977  36028797018964061  36028797018964898

--> err = i - double(i)
 err  =
  0  3 -2
  3  1  2
 -2 -1 -2
  1 -3  2

--> i = int64(2)^62
 i  =
  4611686018427387904

--> i = [i+(0:3:9)'  i+(3:30:93)'  i+(30:300:930)']
 i  =
  4611686018427387904  4611686018427387907  4611686018427387934
  4611686018427387907  4611686018427387937  4611686018427388234
  4611686018427387910  4611686018427387967  4611686018427388534
  4611686018427387913  4611686018427387997  4611686018427388834

--> err = i - double(i)
 err  =
  0  3  30
  3  33  330
  6  63 -394
  9  93 -94

// Comparing speeds of double(), bool2s() and iconvert(,0) on booleans
// -------------------------------------------------------------------
b = (rand(1000,1000)<0.5);
tic(),for i=1:100, bool2s(b); end, toc()
tic(),for i=1:100, double(b); end, toc()
tic(),for i=1:100, iconvert(b,0); end, toc()
--> b = (rand(1000,1000)<0.5);
--> tic(),for i=1:100, bool2s(b); end, toc()
 ans  =
   1.1680533

--> tic(),for i=1:100, double(b); end, toc()
 ans  =
   2.9003021

--> tic(),for i=1:100, iconvert(b,0); end, toc()
 ans  =
   2.1867567

// Speed comparison between double() and iconvert(..,0) on int32 integers
// ----------------------------------------------------------------------
i = int32((rand(1000,1000)-0.5)*1000);
tic(),for j=1:100, double(i); end, toc()
tic(),for j=1:100, iconvert(i,0); end, toc()
--> i = int32((rand(1000,1000)-0.5)*10000);
--> tic(),for j=1:100, double(i); end, toc()
 ans  =
   2.2464656

--> tic(),for j=1:100, iconvert(i,0); end, toc()
 ans  =
   2.2771408

See also

  • iconvert — 1または8バイト整数表現に変換する
  • bool2s — 論理値行列を0,1を値とする行列に変換する.
  • int8 — 1バイト整数形式に変換する
  • inttype — 整数データ型で使用される整数型
  • type — 変数の型を返す
  • bin2dec — 2進表現を整数に変換
  • oct2dec — 8進数を10進数に変換
  • hex2dec — 16進数から10進数への変換
  • base2dec — bを基底とする表現から整数への変換

History

VersionDescription
6.0 New int64 and uint64 encoded integers can now be converted.
Report an issue
<< clean Floating point fix >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Feb 12 23:12:40 CET 2018