RosettaCodeData/Task/Literals-Floating-point/NetRexx/literals-floating-point.netrexx
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

48 lines
2.5 KiB
Text

/* 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