How to resolve the algorithm Literals/Floating point step by step in the Delphi programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Literals/Floating point step by step in the Delphi programming language
Table of Contents
Problem Statement
Programming languages have different ways of expressing floating-point literals.
Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable formats for your language.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Literals/Floating point step by step in the Delphi programming language
Source code in the delphi programming language
procedure FloatLiterals(Memo: TMemo);
{Delphi has multiple floating number formats}
var R48: Real48; {48-bit real number}
var SI: Single; {32-bit real number}
var D: Double; {64-bit real number}
var E: Extended; {80-bit real number}
var Cmp: Comp; {}
var Cur: Currency; {Fixed point number for currency}
begin
{Various formats that can be used on input or
as constants assigned to various reals.
Pascal automaically converts integer to
reals as long as the real has enough precision
to hold the value. Consequently, all of the
following constants can be assigned to a real.}
D:=1234;
D:=1.234;
D:=1234E-4;
D:=$7F;
{Reals can also be output in various formats.}
D:=123456789.1234;
Memo.Lines.Add(FloatToStrF(D,ffGeneral,18,4));
Memo.Lines.Add(FloatToStrF(D,ffExponent,18,4));
Memo.Lines.Add(FloatToStrF(D,ffFixed,18,4));
Memo.Lines.Add(FloatToStrF(D,ffNumber,18,4));
Memo.Lines.Add(FloatToStrF(D,ffCurrency,18,4));
Memo.Lines.Add(Format('%10.4f',[D]));
end;
You may also check:How to resolve the algorithm Lucas-Lehmer test step by step in the Scilab programming language
You may also check:How to resolve the algorithm Monty Hall problem step by step in the PowerShell programming language
You may also check:How to resolve the algorithm JortSort step by step in the Wren programming language
You may also check:How to resolve the algorithm Call a function step by step in the Rust programming language
You may also check:How to resolve the algorithm Strip comments from a string step by step in the Objeck programming language