Literals/Floating point: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed FORMAT to '''FORMAT'''. -- ~~~~) |
(Add NetRexx implementation) |
||
Line 228: | Line 228: | ||
AccountingForm[{5.6,-6.7,10.^7}] |
AccountingForm[{5.6,-6.7,10.^7}] |
||
{5.6,(6.7),10000000.}</lang> |
{5.6,(6.7),10000000.}</lang> |
||
=={{header|NetRexx}}== |
|||
NetRexx supports ''decimal'' and ''exponential'' notation for floating point constants. |
|||
A number in ''exponential notation'' is a simple number followed immediately by the |
|||
sequence "<tt>E</tt>" (or "<tt>e</tt>"), followed immediately |
|||
by a sign ("<tt>+</tt>" or "<tt>-</tt>"), followed immediately |
|||
by one or more digits. |
|||
NetRexx supports floating point number notation in the primitive ''float'' and ''double'' types, |
|||
it's built in ''Rexx'' object and any other Java object that supports floating point numbers. |
|||
<lang NetRexx>/* NetRexx */ |
|||
options replace format comments java crossref symbols nobinary |
|||
numeric digits 40 -- make lots of space for big numbers |
|||
numeric form scientific -- set output form for exponential notation |
|||
say 'Sample using objects of type "Rexx" (default):' |
|||
fv = 1.5; say '1.5'.right(20) '==' normalize(fv).right(20) -- 1.5 |
|||
fv = -1.5; say '-1.5'.right(20) '==' normalize(fv).right(20) -- -1.5 |
|||
fv = 15e-1; say '15e-1'.right(20) '==' normalize(fv).right(20) -- 1.5 |
|||
fv = 3e-12; say '3e-12'.right(20) '==' normalize(fv).right(20) -- 3E-12 |
|||
fv = 3e+12; say '3e+12'.right(20) '==' normalize(fv).right(20) -- 3000000000000 |
|||
fv = 17.3E-12; say '17.3E-12'.right(20) '==' normalize(fv).right(20) -- 1.73E-11 |
|||
fv = 17.3E+12; say '17.3E+12'.right(20) '==' normalize(fv).right(20) -- 17300000000000 |
|||
fv = 17.3E+40; say '17.3E+40'.right(20) '==' normalize(fv).right(20) -- 1.73E+41 |
|||
fv = 0.033e+9; say '0.033e+9'.right(20) '==' normalize(fv).right(20) -- 33000000 |
|||
fv = 0.033e-9; say '0.033e-9'.right(20) '==' normalize(fv).right(20) -- 3.3E-11 |
|||
say |
|||
say 'Sample using primitive type "float":' |
|||
ff = float |
|||
ff = float 15e-1; say '15e-1'.right(20) '==' normalize(ff).right(20) -- 1.5 |
|||
ff = float 17.3E-12; say '17.3E-12'.right(20) '==' normalize(ff).right(20) -- 1.73E-11 |
|||
ff = float 17.3E+12; say '17.3E+12'.right(20) '==' normalize(ff).right(20) -- 17300000000000 |
|||
ff = float 0.033E+9; say '0.033E+9'.right(20) '==' normalize(ff).right(20) -- 33000000 |
|||
ff = float 0.033E-9; say '0.033E-9'.right(20) '==' normalize(ff).right(20) -- 3.3E-11 |
|||
say |
|||
say 'Sample using primitive type "double":' |
|||
fd = double |
|||
fd = 15e-1; say '15e-1'.right(20) '==' normalize(fd).right(20) -- 1.5 |
|||
fd = 17.3E-12; say '17.3E-12'.right(20) '==' normalize(fd).right(20) -- 1.73E-11 |
|||
fd = 17.3E+12; say '17.3E+12'.right(20) '==' normalize(fd).right(20) -- 17300000000000 |
|||
fd = 17.3E+40; say '17.3E+40'.right(20) '==' normalize(fd).right(20) -- 1.73E+41 |
|||
fd = 0.033E+9; say '0.033E+9'.right(20) '==' normalize(fd).right(20) -- 33000000 |
|||
fd = 0.033E-9; say '0.033E-9'.right(20) '==' normalize(fd).right(20) -- 3.3E-11 |
|||
say |
|||
return |
|||
/** |
|||
* Convert input to a Rexx object and add zero to the value which forces NetRexx to change its internal representation |
|||
* |
|||
* @param fv a Rexx object containing the floating point value |
|||
* @return a Rexx object which allows NetRexx string manipulation methods to act on it |
|||
*/ |
|||
method normalize(fv) private constant |
|||
return fv + 0 |
|||
</lang> |
|||
'''Output:''' |
|||
<pre> |
|||
Sample using objects of type "Rexx" (default): |
|||
1.5 == 1.5 |
|||
-1.5 == -1.5 |
|||
15e-1 == 1.5 |
|||
3e-12 == 3E-12 |
|||
3e+12 == 3000000000000 |
|||
17.3E-12 == 1.73E-11 |
|||
17.3E+12 == 17300000000000 |
|||
17.3E+40 == 1.73E+41 |
|||
0.033e+9 == 33000000 |
|||
0.033e-9 == 3.3E-11 |
|||
Sample using primitive type "float": |
|||
15e-1 == 1.5 |
|||
17.3E-12 == 1.73E-11 |
|||
17.3E+12 == 17300000000000 |
|||
0.033E+9 == 33000000 |
|||
0.033E-9 == 3.3E-11 |
|||
Sample using primitive type "double": |
|||
15e-1 == 1.5 |
|||
17.3E-12 == 1.73E-11 |
|||
17.3E+12 == 17300000000000 |
|||
17.3E+40 == 1.73E+41 |
|||
0.033E+9 == 33000000 |
|||
0.033E-9 == 3.3E-11 |
|||
</pre> |
|||
=={{header|Objeck}}== |
=={{header|Objeck}}== |