Variable size/Set: Difference between revisions

m
Line 387:
 
By spec, arrays may be declared with dimensions of fixed size, but as of this writing, such arrays not yet implemented. An array of fixed size that returns elements of a native type will be stored compactly, and uses exactly the memory you'd think it should, (modulo alignment constraints between elements and any slop at the end due to your memory allocator).
 
=={{header|Phix}}==
Phix native numeric types are fixed size: <br>
on 32 bit integers are 4 bytes and floats 8 bytes,<br>
on 64 bit integers are 8 bytes and floats 10 bytes.
 
Note that native integers are always signed and one bit shy of a full machine word, ie <br>
-1,073,741,824 to +1,073,741,823 (-#40000000 to #3FFFFFFF) on 32 bit, and<br>
-4,611,686,018,427,387,904 to +4,611,686,018,427,387,903 (-#4000000000000000 to #3FFFFFFFFFFFFFFF) on 64 bit.
 
Sequences are 4 or 8 bytes per element, and can grow or shrink at will.<br>
Strings are always one byte per character (ie ansi or utf-8), utf-16 and utf-32 are held as sequences.
 
When using mprf.e (aka gmp), variables can have any precision required, up to available memory.<br>
mpz (integer) variables automatically grow as needed but can optionally be initialised with a minimum bitcount to avoid later reallocations.<br>
mpfr (floating point) variables require the precision to be explicitly specified in binary bits, for example if you want PI to 1000 decimal places:
<lang Phix>include mpfr.e -- requires 0.8.0+
string nines = repeat('9',1000)
mpz ndp = mpz_init(nines) -- mpz_init(nines,3322) would be identical
integer precision = mpz_sizeinbase(ndp,2) -- 3322
mpfr pi = mpfr_init(0,precision) -- or just hard-code that 3322
mpfr_const_pi(pi)
mpfr_printf(1,"PI with 1000 decimals: %.1000RDf\n\n",pi)</lang>
 
=={{header|PL/I}}==
7,803

edits