iconEuler Reference

Output Formats

Content

Output formats, and conversions to radians etc.

In general, Euler either sets an output format for all numbers of a specific type, or uses functions to print a value in some format. E.g., one can select fracformat or use printfrac.

Note that the default format for Euler is longformat with 12 digits of precision. Zero rounding is on so that very small numbers print as 0. Dense output is on. This prints row vectors in a very dense form with brackets.

Printing and Converting

function rad ()
  rad(d[,min,sec]) converts to radians
  
  rad(x) transfers degree x to radians. If min and sec are present,
  these will be used to set minutes and seconds of the angle.
  
  x° works too instead of rad(x).
  
  See: 
degprint (Output Formats),
degprint (Basic Utilities)
function deg (x)
  deg(x) transfers radians x to degrees
  
  See: 
rad (Output Formats),
rad (Basic Utilities),
degprint (Output Formats),
degprint (Basic Utilities)
function degprint (x : real scalar, dms:integer=1)
  Print radians x in degrees.
  
  This function returns a string with a representation of the radial
  angle x in degrees. By default, the function will print minutes and
  seconds. Turn this off with <dms.
  
  See: 
degformat (Output Formats),
degformat (Basic Utilities)
function degformat (on:integer=1)
  Use degree format from now on.
  
  This calls _useformat with the degprint function.
  
  See: 
degprint (Output Formats),
degprint (Basic Utilities)
function polarprint (x:complex scalar, format="%g")
  Print x in polar form, if it is complex.
  
  Prints the complex number in the form (r,phi°). The format for r
  can be set with format="...".
  
  >load format; polarprint(1+I,format="%0.12g")
  (1.41421356237,45°)
  
  See: 
polarformat (Output Formats),
polarformat (Basic Utilities),
polar (Mathematical Functions),
polar (Maxima Documentation)
function polarformat (on:integer=1)
  Sets the format to polar form.
  
  See: 
polarprint (Output Formats),
polarprint (Basic Utilities)
function ipmprint (x:interval scalar)
  Print an interval using plus-minus notation.
  
  >ipmprint(~1,2~)
  1.5±0.5
  
  See: 
ipmformat (Output Formats),
ipmformat (Basic Utilities)
function ipmformat (on:integer=1)
  Set the format to plus-minus notation
  
  See: 
ipmprint (Output Formats),
ipmprint (Basic Utilities)
function print (x:real scalar, digits:integer=2, length:integer=10, ..
    unit:string="")
  Print the real number x formatted.
  
  The default format is two digits after the comma, and a total
  length of 10 digits. An optional unit can be added.
  
  >print(101/891,unit="%")
  0.11%
  
  See: 
printf (Output Formats),
printf (Basic Utilities),
printf (Maxima Documentation)
function comment printf (format,x)
  Print a value with a C-format.
  
  The format can be decimal (%d, %x) or floating point (%g, %e, %f)
  if x is a number, or a string format (%s) if x is a string. Length
  modifiers (%20g), digits settings (%10.5f) or adjustments (%-20.5f)
  are allowed.
  
  The format string is checked for a valid format. It should not be
  possible to crash Euler via this function.
  
  x : real number
  format : a format string
  
  >printf("pi = %0.2f",pi)
  pi = 3.14
  >printf("left adjusted: --- %-20.10e ---",pi)
  left adjusted: --- 3.1415926536e+000    ---
  >printf("pi = %0.10g",pi)
  pi = 3.141592654
  >printf("%20s","Just a test")
  Just a test
  >printf(''String: "%20s"'',"Just a test")
  String: "         Just a test"
  
  See: 
printf (Basic Utilities),
printf (Maxima Documentation),
Formats (Overview)

Output Formats

function overwrite format (n, digits=none, all=0)
  format(n,m) sets the output format to m digits and width n.
  
  format(n,m) : Turns zero rounding and dense output off. Then calls
  the builtin function _format, which sets the output width to n
  places, and the precision digits to m.
  
  format(n) : Works like goodformat with n digits of acccuracy. Dense
  output and zero rounding is on.
  
  all : If true, the set scalar format will be disabled.
  
  >format(6,2); (1:10)/3, longformat; // reset to default
  0.33  0.67  1.00  1.33  1.67  2.00  2.33  2.67  3.00  3.33
  >format(20,5); (1:4)'/3, longformat; // reset to default
  0.33333
  0.66667
  1.00000
  1.33333
  >format(3); pi, // like goodformat
  3.14
  
  See: 
goodformat (Output Formats),
goodformat (Basic Utilities),
Formats (Overview)
function comment zerorounding (f)
  Sets rounding to 0 of small numbers for output
  
  See: 
Formats (Overview)
function comment denseoutput (f)
  Sets dense output for row vectors
  
  See: 
Formats (Overview)
function comment scalarformat (f)
  Enables or disables the special output for scalars
  
  See: 
setscalarformat (Output Formats),
setscalarformat (Basic Utilities),
Formats (Overview)
function comment setscalarformat (n)
  Sets the number of digits for the scalar format
  
  See: 
scalarformat (Basic Utilities),
Formats (Overview)
function comment iformat (n)
  Sets the number of digits for interval output
function overwrite goodformat (n,digits=none,all=0)
  goodformat(n,m) sets the output format to m digits and width n.
  
  Selects a nice format. For integers, the decimal dot will not be
  included. For very large or very small numbers, the exponential
  format will be used.
  
  This turn zero rounding on and dense output on. Then it calls the
  builtin function _goodformat, which sets the width to m digits and
  the precession to n digits. The width will only be used for matrix
  output with more than one row unless dense output is off.
  
  goodformat(n,m) : sets m digits of precission and a total length of
  n digits.
  
  goodformat(m) : total length is m+8, which is sufficient for
  exponential formats.
  
  all : if on, the scalar format is disabled.
  
  The difference to format is that the output of integers uses no
  decimal dot. Moreover, the dense output prints row vectors with
  brackets.
  
  all : If on this is applied to scalars too.
  
  >goodformat(6,2); (1:10)/3, longformat; // reset to default
  [ 0.33  0.67  1  1.3  1.7  2  2.3  2.7  3  3.3 ]
  >goodformat(6,2); (1:4)'/3, longformat; // reset to default
  0.33
  0.67
  1
  1.3
  
  See: 
Formats (Overview)
function overwrite expformat 
  expformat(n,m) sets the output format to m digits and width n.
  
  Turns zero rounding off and dense output on. This works like
  format, but uses exponential output always. It calls the builtin
  function _expformat.
  
  >expformat(6,2); (1:10)/3, longformat; // reset to default
  [ 3.33e-001  6.67e-001  1.00e+000  1.33e+000  1.67e+000  2.00e+000
  2.33e+000  2.67e+000  3.00e+000  3.33e+000 ]
  
  See: 
Formats (Overview)
function overwrite fixedformat 
  fixedformat(n,m) sets the output format to m digits and width n.
  
  This works like expformat, but always uses fixed point format. It
  calls the builtin function _fixedformat.
  
  Turns zero rounding on. Zero rounding is used to round very small
  numbers to 0.
  
  See: 
Formats (Overview)
function longestformat 
  Sets a very long format for numbers.
  
  Turns zero rounding and dense output off. Uses a format, that
  allows to see the internal accuracy of IEEE double precision.
  
  See: 
Formats (Overview)
function longformat (all=0)
  Sets a long format for numbers
  
  This is the default format for Euler with 12 digits precision.
  Turns zero rounding and dense output on, and uses a good format,
  which does not show a decimal dot if possible.
  
  See: 
Formats (Overview)
function defformat 
  Sets the default format for Euler
  
  Turns zero rounding and dense output on, and uses a good format,
  which does not show a decimal dot if possible.
  
  See: 
Formats (Overview)
function shortformat (all=0)
  Sets a short format for numbers.
  
  See: 
Formats (Overview)
function shortestformat (all=0)
  Sets a very short format for numbers.
  
  See: 
Formats (Overview)

Fractional Output

function overwrite fracformat (n:integer=0, eps=1e-10)
  Sets the fractional format.
  
  Turns zero rounding on. If n>0 it turns dense output off. A
  continued fraction is used to approximate the numbers with
  fractions. The accuracy can be set with eps.
  
  >fracformat; (1:10)/3, longformat;
  [ 1/3  2/3  1  4/3  5/3  2  7/3  8/3  3  10/3 ]
  >fracformat(10); (1:4)'/3, longformat;
  1/3
  2/3
  1
  4/3
  
  See: 
frac (Basic Utilities)
function fracprint (x:numerical, n:integer=10, eps=1e-10)
  Prints x in fractional format with n places.
  
  Uses a temporary format to print a value in fractional format. The
  format is then reset to the default longformat.
  
  >fracprint(pi,eps=0.01)
  22/7
  
  See: 
frac (Basic Utilities)
function overwrite frac (x:numerical, mixed:integer=0)
  Returns a string containing the fractional representation of x.
  
  This can be used to convert a number to a fraction contained in a
  string. If mixed, then the integer part is separated from the
  fractional part. The function uses the builtin function _frac to
  find a continued fraction, which approximates the number.
  
  The function can also be used for vectors and matrices to convert
  decimals into good fractions, e.g. for Maxima.
  
  >frac(2/3+5/4,>mixed)
  1+11/12
  
  >(1:4)/3; &%
  [0.33333333333333, 0.66666666666667, 1, 1.333333333333333]
  >frac((1:4)/3); &%
  1  2     4
  [-, -, 1, -]
  3  3     3
  
  See: 
fracformat (Output Formats),
fracformat (Basic Utilities)
function prefix short (x)
  Print x in short format
  
  >short pi^2
function prefix shortest (x)
  Print x in shortest format
  
  >shortest pi^2
function prefix long (x)
  Print x in long format
  
  >long pi^2
function prefix longest (x)
  Print x in the longest format
  
  >longest pi^2
function prefix cformat (x)
  Print x in currency format
  
  >long pi^2
function prefix fraction (x)
  Print x in fractional format
  
  >longest pi^2
function printeuro (x,n=0)
  The value in Euro rounded to cent
function printdollar (x,n=0)
  The value in Euro rounded to cent
function prefix uprint (x)
  Print in the format in userformat$.
  
  >userformat$="%10.2f Yen";
  >uprint 119569*119%
  142287.11 Yen
  

Documentation Homepage