[fpc-pascal] Possible bug in Numeric test
Bart
bartjunk64 at gmail.com
Thu Feb 25 00:56:04 CET 2016
On 2/24/16, steveg <steveg at nevets.com.au> wrote:
> Not sure if this is considered a bug or not :)
Fully compatible with Delphi 7.
{$apptype console}
{$ifdef fpc}
{$mode objfpc}
{$h+}
{$codepage utf8}
{$endif}
{$R+}
uses
classes,sysutils;
function IsNum( const sSrc :string ) :boolean;
var
Code :integer;
Num :real;
begin
Val(sSrc, Num, Code);
Result := ( Code = 0 );
end;
var
R: Real;
Code: Integer;
begin
Val('E1',R,Code);
writeln('E1 : Code = ',Code,#32, IsNum('E1'));
Val('E',R,Code);
writeln('E : Code = ',Code,#32, IsNum('E'));
Val('1E',R,Code);
writeln('1E : Code = ',Code,#32, IsNum('1E'));
Val('1E1',R,Code);
writeln('1E1: Code = ',Code,#32, IsNum('1E1'));
Val('E1/E2/etc',r,Code);
writeln('etc: Code = ',Code,#32, IsNum('E1/E2/etc'));
end.
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>dcc32 test.pas
Borland Delphi Version 15.0
Copyright (c) 1983,2002 Borland Software Corporation
test.pas(19) Hint: Value assigned to 'Num' never used
test.pas(36) Hint: Value assigned to 'R' never used
test.pas(34) Hint: Value assigned to 'R' never used
test.pas(32) Hint: Value assigned to 'R' never used
test.pas(30) Hint: Value assigned to 'R' never used
test.pas(28) Hint: Value assigned to 'R' never used
test.pas(39)
40 lines, 0.20 seconds, 71676 bytes code, 4097 bytes data.
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test
E1 : Code = 0 TRUE
E : Code = 2 FALSE
1E : Code = 3 FALSE
1E1: Code = 0 TRUE
etc: Code = 3 FALSE
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc test.pas
Free Pascal Compiler version 3.0.0 [2015/11/16] for i386
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
test.pas(17,3) Note: Local variable "Num" is assigned but never used
test.pas(25,3) Note: Local variable "R" is assigned but never used
Linking test.exe
38 lines compiled, 2.6 sec, 133856 bytes code, 5828 bytes data
2 note(s) issued
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test
E1 : Code = 0 TRUE
E : Code = 2 FALSE
1E : Code = 3 FALSE
1E1: Code = 0 TRUE
etc: Code = 3 FALSE
Bart
More information about the fpc-pascal
mailing list