Jump to content

Variable size/Set: Difference between revisions

added Ursala
No edit summary
(added Ursala)
Line 184:
% set baz Frankfurt
Fr</lang>
 
=={{header|Ursala}}==
There is no way to set the minimum size of natural, integer, or
rational numbers, but no need because they all have unlimited
precision.
 
For ([http://www.mpfr.org mpfr] format) arbitrary precision floating point numbers, there are several
mechanisms for setting the minimum precision, although not the exact amount of real memory used.
* If it's initialized from a literal constant, the compiler infers the intended precision from the number of digits in the constant (or 160 bits, whichever is greater).
* The library function <code>mpfr..grow(x,n)</code> returns a copy of <code>x</code> with its precision increased by <code>n</code> bits (padded with zeros).
* The library function <code>mpfr..shrink(x,n)</code> returns a copy of <code>x</code> with its precision reduced by <code>n</code> bits, or to <code>MPFR_PREC_MIN</code>, whichever is greater.
* Library functions such as <code>mpfr..pi</code> and <code>mpfr..const_catalan</code> take a natural number specifying the precision as an argument and return a constant with at least that precision.
* If two numbers of unequal precision are combined using any binary operation from the mpfr library, the result is computed and allocated using the greater precision of the two.
The last feature eliminates the need for explicitly setting the precision of numbers having exact
representations, albeit contrary to the convention in physical sciences.
<lang Ursala>p = mpfr..pi 200 # 200 bits of precision
 
x = mpfr..grow(1.0E+0,1000) # 160 default precision, grown to 1160
 
y = mpfr..shrink(1.0+0,40) # 160 default shrunk to 120
 
z = mpfr..add(p,y) # inherits 200 bits of precision
 
a = # 180 bits (not the default 160) because of more digits in the constant
 
1.00000000000000000000000000000000000000000000000000000E0</lang>
 
 
{{omit from|AWK}}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.