•  Back 
  •  Main 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  Help 
  •  Show info about hypertext 
  •  View a new file 
Topic       : The GFA-Basic Compendium
Author      : GFA Systemtechnik GmbH
Version     : GFABasic.HYP v2.98 (12/31/2023)
Subject     : Documentation/Programming
Nodes       : 899
Index Size  : 28056
HCP-Version : 3
Compiled on : Atari
@charset    : atarist
@lang       : 
@default    : Document not found
@help       : Help
@options    : +g -i -s +z
@width      : 75
@hostname   : STRNGSRV
@hostname   : CAB     
@hostname   : HIGHWIRE
@hostname   : THING   
View Ref-FileThe compiler options $%0 and $%3 influence the division of integer variables
(longwords). If the $%0 option is active, the variables to be divided are made
into floating point variables and then divided. The result of such a division
is a floating point variable.

If the $%3 option is enabled, the two integer variables are not made into
floating point variables. The result of the integer division will then be
interpreted as an integer value.

Example: Once compiled, the program

    $%0
    x%=5
    y%=2
    PRINT x%/y%

produces the output 2.5. The fact that the digit behind the decimal point was
output indicates that x% and y% have been converted into floating point numbers
before the division took place. Compiler option $%3 will produce 2 as a result,
since x% and y% are interpreted as integers without decimal points and
therefore only an integer division is carried out. This option has no effect in
the interpreter, of course, where you will get 2.5 in both cases.

The code generated by the two options will illustrate the difference once
again.

The lines

    $%0
    a%=x%/y%/z%

will generate the code:

    move.l  -$7ffc(a5),d0
    bsr     FITOF
    move.l  d0,-(a7)
    move.w  d2,-(a7)
    move.w  d1,-(a7)
    move.l  -$7ff8(a5),d0
    bsr     FITOF
    move.w  (a7)+,d4
    move.w  (a7)+,d5
    move.l  (a7)+,d3
    bsr     FXDIV
    move.l  d0,-(a7)
    move.w  d2,-(a7)
    move.w  d1,-(a7)
    move.l  -$7ff4(a5),d0
    bsr     FITOF
    move.w  (a7)+,d4
    move.w  (a7)+,d5
    move.l  (a7)+,d3
    bsr     FXDIV
    bsr     FFTOI
    move.l  d0,-$8000(a5)

In this listing, you will notice that the subroutine FITOF (integer to float),
which converts the integers into floating point numbers, is called three times.
Since the result is returned to an integer variable, the routine FFTOI (float
to integer) is also required. The division is carried out with (FXDIV), a
division routine producing floating point results.

By contrast, the program

    $%3
    a%=x%/y%/z%

generates the assembler listing

    move.l  -$7ffc(a5),d0
    move.l  -$7ff8(a5),d1
    bsr     LDIV
    move.l  -$7ff4(a5),d0
    bsr     LDIV
    move.l  d0,-$8000

This short listing simply calls a fairly straight forward subroutine to divide
two longwords (LDIV) and can therefore be processed much faster than under the
$%0 option. The difference in speed is of a factor around 10 to 11.

If two integer variables are divided and the result is returned to an integer
variable without any further processing, the compiler option %0 is of no
consequence. In that case, only pure integer arithmetic is being used.

In the event of two-byte variables being defined, the Motorola 68000
processor's div command is used instead of the LDIV routine (see the section on
division in the Program Optimization chapter).

Memo: $%0 is the default.