Sign in Join
Wiki copytemporary

Fractions/fi

English · Suomi

Mikä on Fractions unit?

Fractions on käännösyksikko (unit) joka suorittaa laskuja murtoluvuilla.
Käännösyksikkö syntyi keskustelun pohjalta discussion on the Lazarus forum.

Subversion

Löydät Fractions unitin

text
svn https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr/components/fractions

Tai voit vain katsella sitä viewcv:n avulla

text
http://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/fractions/

Ominaisuudet

TFraction tyyppi

TFraction on niin sanottu "advanced record": eli tietue laajennettuna metodeilla ja ominaisuuksilla (Property) .

TFraction ominaisuudet

TFraction metodit

Murtolukujen tekeminen

Tuetut laskut

Operaattorit (Overloaded operators)

Matemaattiset funktiot

Yleiskäyttöiset funktiot

Muunnos rutiinit

Esimerkkiohjelma

pascal

program example;

{$mode objfpc}{$H+}
{$apptype console}

uses
  Classes, sysutils, fractions, math;

var
  F1, F2: TFraction;
  D, Prec: Double;
  i: Integer;
begin
  F1 := Fraction(1,1,3); // 1 1/3
  F2 := Fraction(4,3);   // 4/3
  writeln('F1.ToString = ',F1.ToString); // '4/3'
  writeln('F1.Resolve  = ',F1.Resolve);  // '1 1/3'
  writeln('F1.ToFloat  = ',F1.ToFloat:16:16); // 1.3333333333333333
  writeln('F2.ToString = ',F2.ToString); // '4/3'
  writeln('(F1 = F2)   = ',F1=F2);         //True

  F1 := Fraction(1,2);
  F2 := Fraction(1,3);
  writeln(F1.ToString,' * ',F2.ToString,'   = ',(F1*F2).Resolve);  // '1/6'
  writeln(F1.ToString,' / ',F2.ToString,'   = ',(F1/F2).Resolve);  // '1 1/2'
  writeln(F1.ToString,' + ',F2.ToString,'   = ',(F1+F2).Resolve);  // '5/6'
  writeln(F1.ToString,' - ',F2.ToString,'   = ',(F1-F2).Resolve);  // '1/6'
  writeln(F1.ToString,' ** 2    = ',(F1**2).Resolve);  // '1/6'

  D := 0.25;
  F1 := FloatToFraction(D, 0.000001);
  writeln('FloatTofraction(0.25) -> ',F1.ToString);   // '1/4'
  writeln;
  writeln('Approximations of Pi:');
  writeln('                                              [Pi = ',Pi:16:16,']');
  Prec := 1.0;
  for i := 1 to 10 do
  begin
    Prec := Prec / 10;
    F2 := FloatTofraction(Pi, Prec);
    writeln('FloatTofraction(Pi,',Prec:10:10,') = ',Format('%-13s',[F2.Resolve]),'   [',F2.ToFloat:16:16,']');
  end;
end.

Ohjelma tulostaa:

pascal
F1.ToString = 4/3
F1.Resolve  = 1 1/3
F1.ToFloat  = 1.3333333333333333
F2.ToString = 4/3
(F1 = F2)   = TRUE
1/2 * 1/3   = 1/6
1/2 / 1/3   = 1 1/2
1/2 + 1/3   = 5/6
1/2 - 1/3   = 1/6
1/2 ** 2    = 1/4
FloatTofraction(0.25) -> 1/4
pascal
Approximations of Pi:
                                              [Pi = 3.1415926535897932]
FloatTofraction(Pi,0.1000000000) = 3 1/7           [3.1428571428571428]
FloatTofraction(Pi,0.0100000000) = 3 1/7           [3.1428571428571428]
FloatTofraction(Pi,0.0010000000) = 3 16/113        [3.1415929203539825]
FloatTofraction(Pi,0.0001000000) = 3 16/113        [3.1415929203539825]
FloatTofraction(Pi,0.0000100000) = 3 16/113        [3.1415929203539825]
FloatTofraction(Pi,0.0000010000) = 3 16/113        [3.1415929203539825]
FloatTofraction(Pi,0.0000001000) = 3 4703/33215    [3.1415926539214212]
FloatTofraction(Pi,0.0000000100) = 3 4703/33215    [3.1415926539214212]
FloatTofraction(Pi,0.0000000010) = 3 4703/33215    [3.1415926539214212]
FloatTofraction(Pi,0.0000000001) = 3 14093/99532   [3.1415926536189365]

From the Free Pascal wiki, page "Fractions/fi", as it stood on 2020-01-24 after a change by Bart, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 5, last changed by WikiArchive .

Edited on wiki.freepascal.org by 2 people, 2015–2020

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
DjzepiCreated page
Djzepi
Djzepi
BartUse pascal highlighter

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.