Recent

Author Topic: Derive algebra  (Read 3309 times)

Фролов

  • New Member
  • *
  • Posts: 15
Derive algebra
« on: June 24, 2017, 08:49:24 am »
Tell me how you can implement + 0.5 for example double

Code: Pascal  [Select][+][-]
  1.     d := 10;
  2.     for i := 0 to 50000000 - 1 do
  3.     begin
  4.       d := d + 150.5;
  5.     end;
  6.  

Should be - 7525000041,32991, but in fact 7525000010

0.1 = 0.00011001100
0.5 = 0.1
« Last Edit: June 24, 2017, 09:03:22 am by Фролов »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Derive algebra
« Reply #1 on: June 24, 2017, 10:53:15 am »
What is the problem? What is d?

You are adding 50 million times the value 150.5 to 10, i.e. you are calculating 10 + 50E6*150.5 =7975000010. And this is exactly what the following program is printing:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. var
  6.   d: Double;
  7.   i: Integer;
  8. begin
  9.   d := 10;
  10.   for i := 0 to 50000000 - 1 do
  11.   begin
  12.     d := d + 150.5;
  13.   end;
  14.   WriteLn(d:20:1);
  15.  
  16.   d := 50e6*150.5 + 10;
  17.   WriteLn(d:20:1);
  18.  
  19.   ReadLn;
  20. end.

Фролов

  • New Member
  • *
  • Posts: 15
Re: Derive algebra
« Reply #2 on: June 24, 2017, 11:11:07 am »
What is the problem? What is d?

You are adding 50 million times the value 150.5 to 10, i.e. you are calculating 10 + 50E6*150.5 =7975000010. And this is exactly what the following program is printing:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. var
  6.   d: Double;
  7.   i: Integer;
  8. begin
  9.   d := 10;
  10.   for i := 0 to 50000000 - 1 do
  11.   begin
  12.     d := d + 150.5;
  13.   end;
  14.   WriteLn(d:20:1);
  15.  
  16.   d := 50e6*150.5 + 10;
  17.   WriteLn(d:20:1);
  18.  
  19.   ReadLn;
  20. end.


Yes d = Double

I would like to repeat this. For one measure(One line). There is a possibility?

Code: Pascal  [Select][+][-]
  1.     d := 10;
  2.     for i := 0 to 50000000 - 1 do
  3.     begin
  4.       d := d + 150;
  5.       d := d + 0.1;
  6.       d := d + 0.1;
  7.       d := d + 0.1;
  8.       d := d + 0.1;
  9.       d := d + 0.1;
  10.     end;

guest60499

  • Guest
Re: Derive algebra
« Reply #3 on: June 24, 2017, 11:13:59 am »
I think you are running into the issues with floating point numbers as outlined here.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Derive algebra
« Reply #4 on: June 24, 2017, 11:19:11 am »
I still don't understand. I still don't know what you want to achieve and what is wrong. Maybe you should post the question in your native language.

Фролов

  • New Member
  • *
  • Posts: 15
Re: Derive algebra
« Reply #5 on: June 24, 2017, 11:23:35 am »
I still don't understand. I still don't know what you want to achieve and what is wrong. Maybe you should post the question in your native language.

Выполнить за один такт, + 0.5 для типа double  (Run for one clock cycle, + 0.5 for double type)

7.5250000413299112E+009

Code: Pascal  [Select][+][-]
  1.     d := 10;
  2.     for i := 0 to 50000000 - 1 do
  3.     begin
  4.       d := d + 150;
  5.       d := d + 0.1;
  6.       d := d + 0.1;
  7.       d := d + 0.1;
  8.       d := d + 0.1;
  9.       d := d + 0.1;
  10.     end;
  11.     WriteLn(d);  
  12.  


Это отнимает 80% 1.088237 sec Я думаю, это бы занимало порядком 0.203127 sec

(It takes away 80% 1.088237 sec I think it would take about 0.203127 sec)

guest60499

  • Guest
Re: Derive algebra
« Reply #6 on: June 24, 2017, 12:41:43 pm »
Are you trying to create a delay by performing floating point operations?

Фролов

  • New Member
  • *
  • Posts: 15
Re: Derive algebra
« Reply #7 on: June 24, 2017, 01:24:24 pm »
I found what I need. But it generates classes and shits into memory ... But tearing out the right thing is possible

- Я нашёл то, что надо. Но оно порождает классы и гадит в память... Но выдрать нужное возможно

https://github.com/rvelthuis/BigNumbers

Code: Pascal  [Select][+][-]
  1.     d := BigDecimal.Create('10.000');
  2.     d := d + 150.5;
  3.     d := d + 150.5;
  4.     d := d + 150.5;
  5.     d := d + 150.5;
  6.     d := d + 150.5;

 

TinyPortal © 2005-2018