Working with fractions in ASMA
ZXNet echo conference «code.zx»
From Kirill Frolov → To Slavka Kalinin 24 October 2000
Press RESET immediately, Slavka!
24 Oct 00 00:10, Slavka Kalinin wrote to All rulez coders:
SK> Hey super coders where are you... Maybe someone can tell me how
SK> you can work with fractional numbers in ASMA
Simple. So simple that I don’t even quite understand the point
question. You take it and work... In general, read Spectrum-Expert,
there seemed to be something for the spectrum.
SK> operations on these numbers will be as follows: multiplication, division, addition
SK> and there will also be negative numbers
Multiplication and long division, addition and subtraction too.
Remember arithmetic...
SK> and the numbers should be the maximum number in the calculations 768.
This doesn't say anything. How many decimal places?
SK> So if anyone is not too lazy, please help, I really need it.
SK> I’m not asking for ready-made procedures, but at least explain the principle with
SK> simplest examples.
It’s easier to store and process numbers on a computer in binary
system, although sometimes they use binary decimal, but this is necessary
just so that the results of calculations based on who knows what
the standards coincided. It's better to use binary precision
calculations higher and faster. But it’s true that there are problems with input/outputin the decimal system, well, there are all sorts of rounding errors. Usually
use two forms of storing real numbers - floating point
and with a fixed one, the second form of storage allows you to slightly increase
calculation speed for a more limited range of numbers.
Have you seen the calculator? There is a mantissa and an order, i.e. M*10^N.
Well, in the computer there will be M * 2 ^ N, but the essence does not change. In fact
N is a number in the range 0..1, and N is any integer. If the point is fixed,
it’s just that some of the bits in the number are to the right of the point, and some are to the left.
The arithmetic here is simple: when multiplying and dividing, the mantissa is multiplied
or divided, and the order is summed or subtracted. Well, when adding
and subtraction, you first need to reduce the numbers to one N, and then add
and subtract, naturally the order changes for the smaller in absolute
value of the number and accuracy is lost. By the way, after multiplication or division,
and also if during the operation of addition or subtraction there was an overflow or
a loan has occurred, the order will be changed, you need to look here...
And for you, fixed point and bit depth are probably most suitable
numbers need to be chosen appropriately. For example, if you need 8 decimal places,
then you need 18 bits to represent your number.
And if you don’t need extremely high computing speed, take it or
tear a piece out of the hitech-c runtime library or take the whole thing. The code is thereQuite well optimized. Just don't try through RST #28 on
count on the Spectrum - on this "calculator" you can only count money...
Although there is a glitched version, it was included with the ZXEMU emulator, but there
The font in BASIC is crippled.