M
M
Mushkiter0072017-09-26 19:10:38
Delphi
Mushkiter007, 2017-09-26 19:10:38

How can I write down the final result of the division?

There are two variables of type Real X1:=1 and X2:=0.2. I need the expression frac(X1/X2) to be equal to 0. Is it possible to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2017-09-26
@Mushkiter007

Depending on the origin of the number, you can do this.
1. Work with an error. For example.

q := X1 / X2;
if abs(q - Round(q)) < 1e-5 then ...

I'm mostly now on "si with crosses" and I'm not used to not taking the condition in brackets :)
2. Work in rational numbers.
type
  TRatio = record
    Num, Den : integer;
  end;

I think you can write the operations ±×/ and, if necessary, the abbreviation yourself.
3. Work in a fixed point - for example, convert rubles to kopecks.
var
  X1 : integer = 100;
  X2 : integer = 20;

if X1 mod X2 = 0 then ...

4. Work in decimal long arithmetic. This is already quite a "big gun", and maybe something like
type
  TDecFloat = record
    mantissa : uint64;  // например, от 1e17 до 1e18
    order : integer;
    sign : boolean;
  end;

This is how you can make a calculator that works in the decimal system and converts to extended and vice versa, if, for example, you need to take a sine. Of course, there will be a translation error for transcendental functions, but 0.2 in such a system is exactly 0.2, and this is important for calculators: it will calculate exactly what a person calculates with a pen on paper.
ATTENTION! For methods 2,3,4, you will have to rework the entire chain through which 1 and 0.2 appear. There is no number 0.2 in float/double, period.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question