All computations deal with the internal representations of the numbers.
Every number has an external representation as a sequence of ASCII characters. Several external representations may denote the same number, for example, "20.0" and "20.000".
Converting an internal to an external representation is called "printing",
converting an external to an internal representation is called "reading".
In CLN, it is always true that conversion of an internal to an external
representation and then back to an internal representation will yield the
same internal representation. Symbolically: read(print(x)) == x
.
This is called "print-read consistency".
Different types of numbers have different external representations (case is insignificant):
.
with a trailing dot
for decimal integers
and the #nR
, #b
, #o
, #x
prefixes.
/
{digit}+.
The #nR
, #b
, #o
, #x
prefixes are allowed
here as well.
.
{digit}*exponent or
sign{digit}*.
{digit}+. A precision specifier
of the form _prec may be appended. There must be at least
one digit in the non-exponent part. The exponent has the syntax
expmarker expsign {digit}+.
The exponent marker is
realpart+imagparti
. Of course,
if imagpart is negative, its printed representation begins with
a `-', and the `+' between realpart and imagpart
may be omitted. Note that this notation cannot be used when the imagpart
is rational and the rational number's base is >18, because the `i'
is then read as a digit.
#C(realpart imagpart)
.
Including <cl_io.h>
defines a type cl_istream
, which is
the type of the first argument to all input functions. Unless you build
and use CLN with the macro CL_IO_STDIO being defined, cl_istream
is the same as istream&
.
The variable
cl_istream cl_stdin
contains the standard input stream.
These are the simple input functions:
int freadchar (cl_istream stream)
stream
. Returns cl_EOF
(not a `char'!)
if the end of stream was encountered or an error occurred.
int funreadchar (cl_istream stream, int c)
c
onto stream
. c
must be the result of the
last freadchar
operation on stream
.
Each of the classes cl_N
, cl_R
, cl_RA
, cl_I
,
cl_F
, cl_SF
, cl_FF
, cl_DF
, cl_LF
defines, in <cl_type_io.h>
, the following input function:
cl_istream operator>> (cl_istream stream, type& result)
stream
and stores it in the result
.
The most flexible input functions, defined in <cl_type_io.h>
,
are the following:
cl_N read_complex (cl_istream stream, const cl_read_flags& flags)
cl_R read_real (cl_istream stream, const cl_read_flags& flags)
cl_F read_float (cl_istream stream, const cl_read_flags& flags)
cl_RA read_rational (cl_istream stream, const cl_read_flags& flags)
cl_I read_integer (cl_istream stream, const cl_read_flags& flags)
stream
. The flags
are parameters which
affect the input syntax. Whitespace before the number is silently skipped.
cl_N read_complex (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)
cl_R read_real (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)
cl_F read_float (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)
cl_RA read_rational (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)
cl_I read_integer (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)
flags
are parameters which
affect the input syntax. The string starts at string
and ends at
string_limit
(exclusive limit). string_limit
may also be
NULL
, denoting the entire string, i.e. equivalent to
string_limit = string + strlen(string)
. If end_of_parse
is
NULL
, the string in memory must contain exactly one number and nothing
more, else a fatal error will be signalled. If end_of_parse
is not NULL
, *end_of_parse
will be assigned a pointer past
the last parsed character (i.e. string_limit
if nothing came after
the number). Whitespace is not allowed.
The structure cl_read_flags
contains the following fields:
cl_read_syntax_t syntax
syntax_number
, syntax_real
, syntax_rational
,
syntax_integer
, syntax_float
, syntax_sfloat
,
syntax_ffloat
, syntax_dfloat
, syntax_lfloat
.
cl_read_lsyntax_t lsyntax
lsyntax_standard
lsyntax_algebraic
x+yi
for complex numbers,
lsyntax_commonlisp
#b
, #o
, #x
syntaxes for binary, octal,
hexadecimal numbers,
#baseR
for rational numbers in a given base,
#c(realpart imagpart)
for complex numbers,
lsyntax_all
unsigned int rational_base
cl_float_format_t float_flags.default_float_format
cl_float_format_t float_flags.default_lfloat_format
cl_boolean float_flags.mantissa_dependent_float_format
Including <cl_io.h>
defines a type cl_ostream
, which is
the type of the first argument to all output functions. Unless you build
and use CLN with the macro CL_IO_STDIO being defined, cl_ostream
is the same as ostream&
.
The variable
cl_ostream cl_stdout
contains the standard output stream.
The variable
cl_ostream cl_stderr
contains the standard error output stream.
These are the simple output functions:
void fprintchar (cl_ostream stream, char c)
x
literally on the stream
.
void fprint (cl_ostream stream, const char * string)
string
literally on the stream
.
void fprintdecimal (cl_ostream stream, int x)
void fprintdecimal (cl_ostream stream, const cl_I& x)
x
in decimal on the stream
.
void fprintbinary (cl_ostream stream, const cl_I& x)
x
in binary (base 2, without prefix)
on the stream
.
void fprintoctal (cl_ostream stream, const cl_I& x)
x
in octal (base 8, without prefix)
on the stream
.
void fprinthexadecimal (cl_ostream stream, const cl_I& x)
x
in hexadecimal (base 16, without prefix)
on the stream
.
Each of the classes cl_N
, cl_R
, cl_RA
, cl_I
,
cl_F
, cl_SF
, cl_FF
, cl_DF
, cl_LF
defines, in <cl_type_io.h>
, the following output functions:
void fprint (cl_ostream stream, const type& x)
cl_ostream operator<< (cl_ostream stream, const type& x)
x
on the stream
. The output may depend
on the global printer settings in the variable cl_default_print_flags
.
The ostream
flags and settings (flags, width and locale) are
ignored.
The most flexible output function, defined in <cl_type_io.h>
,
are the following:
void print_complex (cl_ostream stream, const cl_print_flags& flags, const cl_N& z); void print_real (cl_ostream stream, const cl_print_flags& flags, const cl_R& z); void print_float (cl_ostream stream, const cl_print_flags& flags, const cl_F& z); void print_rational (cl_ostream stream, const cl_print_flags& flags, const cl_RA& z); void print_integer (cl_ostream stream, const cl_print_flags& flags, const cl_I& z);
Prints the number x
on the stream
. The flags
are
parameters which affect the output.
The structure type cl_print_flags
contains the following fields:
unsigned int rational_base
10
.
cl_boolean rational_readably
#nR
or #b
or #o
or #x
prefixes, trailing dot). Default is false.
cl_boolean float_readably
cl_float_format_t default_float_format
cl_float_format_ffloat
.
cl_boolean complex_readably
#C(realpart imagpart)
. Default is false.
cl_string univpoly_varname
"x"
.
The global variable cl_default_print_flags
contains the default values,
used by the function fprint
.
Go to the first, previous, next, last section, table of contents.