Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - Русский


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 — convert boolean matrix to a zero one matrix.
  • int8 — преобразование в однобайтное представление целого числа
  • inttype — возвращает тип целых чисел, используемых в типах целочисленных данных
  • type — возвращает тип переменной
  • bin2dec — преобразование из двоичной системы счисления в десятичную
  • oct2dec — преобразование из восьмеричной системы счисления в десятичную
  • hex2dec — преобразование из шестнадцатеричной системы счисления в десятичную
  • base2dec — преобразование из числа по основанию b в десятичное число

History

ВерсияОписание
6.0 New int64 and uint64 encoded integers can now be converted.
Report an issue
<< clean Плавающая запятая 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 Jun 17 17:55:05 CEST 2024