1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
COMMENT:
INTEGER
This is a basic object type of SYMMETRICA. The first step is
the generation of an INTEGERobject. Look at the following
program
#include "def.h"
#include "macro.h"
main()
{
INT b = 5L;
OP a = callocobject();
anfang();
m_i_i(b,a);
println(a);
freeall(a);
ende();
}
Here is a short explanation: SYMMETRICA uses the type INT for
integervalues,
INT is an C type integer, which is always four byte long. It is in
most cases the type long of C. Therefore you must say 5L, in order to
specify an 4-byte integer. This is a problem of C and not of SYMMETRICA.
In that code, you have an emptyp object a, which becomes an INTEGERobject
with value
5. Then the object is printed to the terminal, using the
standard routine println(); The complete description of m_i_i()
now follows.
NAME:
m_i_i
SYNOPSIS:
INT m_i_i(INT integer, OP integerobject)
MACRO:
M_I_I
DESCRIPTION:
builds an integerobject with value integer. First
it is checked whether integerobject is an empty object, if
not it is freed first.
The macro version M_I_I does the same but without a check
on empty object.
RETURN:
the returnvalue is OK, or ERROR if an error
occured.
COMMENT:
If you have an INTEGERobject you sometimes want to select the
INTvalue of the object. Look at the following piece of code.
.
.
.
m_i_i(8L,a);
printf("%d",s_i_i(a)+5);
.
.
.
For that purpose you have the routine s_i_i()
NAME:
s_i_i
SYNOPSIS:
INT s_i_i(OP integerobject)
MACRO:
S_I_I
DESCRIPTION:
selects the INTvalue of integerobject. There is
first a check whether it is an INTEGERobject or not.
The macro version S_I_I does the same but without a
check on INTEGERobject.
RETURN:
the returnvalue is the INTvalue or ERROR if an error occured
COMMENT:
The last problem is to change the value of an existing INTEGERobject.
This is done using the routine c_i_i().
.
.
.
m_i_i(5L,a);println(a);
c_i_i(a,7L);println(a);
.
.
.
will first print a line with the number 5, and then a line with the
number 7.
NAME:
c_i_i
SYNOPSIS:
INT c_i_i(OP integerobject, INT integervalue)
MACRO:
C_I_I
DESCRIPTION:
changes the INTvalue of integerobject. There is
first a check whether it is an INTEGERobject or not.
The version C_I_I does the same but without a check
on INTEGERobject.
RETURN:
the returnvalue is OK or ERROR if an error occured
COMMENT:
For sake of consistency there is also a routine b_i_i(), which means
build_integervalue_integerobject, for the construction of an
INTEGERobject, but because of the input of an INTvalue, there
is no difference between this routine and the routine m_i_i().
These are the basic routines, let us now look at some particular
ones:
NAME:
intlog
SYNOPSIS:
INT intlog(OP integerobject)
DESCRIPTION:
computes the number of digits of the INTEGERobject.
The result is the return value, which is always >0.
COMMENT:
For the generation of random INTEGERobjects, look at
the following codefragment:
.
INT i;
.
.
scan(INTEGER,upperbound);
scan(INTEGER,lowerbound);
for (i=0L;i<1000L;i++)
{
random_integer(result,lowerbound,upperbound);
println(result);freeself(result);
}
.
.
.
which prints 1000 random numbers between the upper and lower
bound. Because this is a lowlevel routine, you have to free
the result object, before you call the routine.
NAME:
random_integer
SYNOPSIS:
INT random_integer(OP result,lowerbound,upperbound)
DESCRIPTION:
computes a random INTEGERobject, between upper and lower
bound. The result is greater equal lowerbond and strictly less then
the upperbound. Both bounds are INTEGER objects.
If lowerbound is NULL, then the default is 0.
if upperbound is NULL, the default is lowerbound+10
It works also if upperbound is of type LONGINT.
RETURN:
the returnvalue is OK or ERROR if an error occured
NAME:
scan_integer
SYNOPSIS:
INT scan_integer(OP a)
DESCRIPTION:
the sub routine for reading interactivly an
INTEGER object. There will be an error message if it was not possible
to interpret the input (e.g. if you enter something, which is no
number). You should use scan(INTEGER,a) instead.
NAME:
test_integer
SYNOPSIS:
INT test_integer()
DESCRIPTION:
tests the implementation
NAME:
mult_integer
SYNOPSIS:
INT mult_integer(OP a,b,c)
DESCRIPTION:
this is a undocumented subroutine of INT mult(OP a,b,c)
You better use this general routine.
NAME:
add_integer
SYNOPSIS:
INT add_integer(OP a,b,c)
DESCRIPTION:
this is a undocumented subroutine of INT add(OP a,b,c)
You better use this general routine.
NAME:
invers_integer
SYNOPSIS:
INT invers_integer(OP a,b)
DESCRIPTION:
this is a undocumented subroutine of INT invers(OP a,b)
You better use this general routine.
NAME:
copy_integer
SYNOPSIS:
INT copy_integer(OP a,b)
DESCRIPTION:
this is a undocumented subroutine of INT copy(OP a,b)
You better use this general routine.
NAME:
dec_integer
SYNOPSIS:
INT dec_integer(OP a)
DESCRIPTION:
this is a undocumented subroutine of INT dec(OP a). The
INTEGER object a is decreased by 1.
You better use the general routine dec.
NAME:
tex_integer
SYNOPSIS:
INT tex_integer(OP a)
DESCRIPTION:
this is a undocumented subroutine of INT tex(OP a). The
INTEGER object a is transformed into tex-source-code.
You better use the general routine tex.
NAME:
inc_integer
SYNOPSIS:
INT inc_integer(OP a)
DESCRIPTION:
this is a undocumented subroutine of INT inc(OP a). The
INTEGER object a is increased by 1.
You better use the general routine inc.
NAME:
ggt_integer
SYNOPSIS:
INT ggt_integer(OP a,b,c)
DESCRIPTION:
this is a undocumented subroutine of INT ggt(OP a,b,c). The
routine computes the greatest common divisor of the two INTEGER
objects a and b.
You better use the general routine ggt.
NAME:
mod_integer
SYNOPSIS:
INT mod_integer(OP a,b,c)
DESCRIPTION:
this is a undocumented subroutine of INT mod(OP a,b,c). The
routine computes the a mod b of the two INTEGER
objects a and b.
You better use the general routine mod.
COMMENT:
GLOBAL CONSTANTS
----------------
as you often need special INTEGER objects, there are some global
INTEGER objects, there are:
OP cons_eins the INTEGER object with value 1
OP cons_null the INTEGER object with value 0
OP cons_zwei the INTEGER object with value 2
OP cons_drei the INTEGER object with value 3
OP cons_negeins the INTEGER object with value -1
so you may use these global variables instead of generating your
own variables containing these often used INTEGER objects. But you
are not allowed to free these variables or changing these
variables. This will generate bad results in all the routines
which trust on the values of these global variables.
NAME:
cons_eins
SYNOPSIS:
OP cons_eins
DESCRIPTION:
the INTEGER object with value 1
NAME:
cons_null
SYNOPSIS:
OP cons_null
DESCRIPTION:
the INTEGER object with value 0
NAME:
cons_zwei
cons_two
SYNOPSIS:
OP cons_zwei
DESCRIPTION:
the INTEGER object with value 2
NAME:
cons_drei
SYNOPSIS:
OP cons_drei
DESCRIPTION:
the INTEGER object with value 3
NAME:
cons_negeins
SYNOPSIS:
OP cons_negeins
DESCRIPTION:
the INTEGER object with value -1
GENERAL ROUTINES
----------------
add()
add_apply()
addinvers()
addinvers_apply()
comp()
copy()
div()
einsp()
fprint()
fprintln()
ganzdiv()
hoch()
invers()
mod()
mult()
mult_apply()
negp()
negeinsp()
nullp()
objectread()
objectwrite()
posp()
print()
println()
scan() input from stdin=terminal
sscan()
tex()
|