Recent

Author Topic: Alias for Int64  (Read 12135 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 19273
  • Glad to be alive.
Re: Alias for Int64
« Reply #15 on: April 14, 2019, 08:40:15 am »
Also note I get correct output for 3.3.1, except nativeint:
Code: Bash  [Select][+][-]
  1. Types         Size - SizeOf : MinValue - MaxValue
  2. -----------   ----------------------------------------------
  3. Boolean    : 1 - 1 : should be 0 - 1 or false - true but currently not exist
  4. Char       :  - 1 : no size should be #0 - #255 not exists
  5. Byte       : 1 - 1 : 0 - 255
  6. UInt8      : 1 - 1 : 0 - 255
  7. UInt16     : 2 - 2 : 0 - 65535
  8. UInt32     : 4 - 4 : 0 - 4294967295
  9. UInt64     : 8 - 8 : 0 - 18446744073709551615
  10. NativeUInt : 8 - 8 : 0 - 18446744073709551615
  11. Int8       : 1 - 1 : -128 - 127
  12. Int16      : 2 - 2 : -32768 - 32767
  13. Int32      : 4 - 4 : -2147483648 - 2147483647
  14. Int64      : 8 - 8 : -9223372036854775808 - 9223372036854775807
  15. NativeInt  : 8 - 8 : 0 - 9223372036854775807
  16. Single     : 4 - 4 : -3.402823466E+38 -  3.402823466E+38
  17. Double     : 8 - 8 : -1.7976931348623157E+308 -  1.7976931348623157E+308
  18. Extended   : 8 - 8 : -1.7976931348623157E+308 -  1.7976931348623157E+308
  19. Currency   :  dont have helper yet but should be -922337203685477.5808 - 922337203685477.5807
  20. TDateTime  :  no size no MinValue and MaxValue should be 0001-01-01 00:00:00.000 - 9999-12-31 23:59:59.999
  21. TGuid      :  none
  22. String     :  none
  23. Pointer    : nil none
  24.  
And globals are always initialized.
The extended value is also correct in this case: win64 aliases extended to double. That's the ABI, not fpc.
« Last Edit: April 14, 2019, 08:57:19 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

Thaddy

  • Hero Member
  • *****
  • Posts: 19273
  • Glad to be alive.
Re: Alias for Int64
« Reply #16 on: April 14, 2019, 09:19:06 am »
I reported this as bug 0035378
Code: Pascal  [Select][+][-]
  1. program Testhelpers;
  2. {$mode objfpc}
  3. uses sysutils;
  4. begin
  5.   writeln(NativeInt.MinValue); // 0 wrong
  6.   writeln(Low(NativeInt)); // -9223372036854775808  correct
  7. end.
I also added the fix. It is a simple typo in syshelph.inc

Furthermore this is correct:
Char       :  - 1 : no size should be #0 - #255 not exists
You make the wrong assumption here: char is initialized to empty and it is not a range.
The size is 1. A byte .
« Last Edit: April 14, 2019, 10:05:50 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: Alias for Int64
« Reply #17 on: April 14, 2019, 11:29:09 am »
@Thaddy,  me still using Free Pascal Compiler version 3.0.4 [2018/10/29] for x86_64 :)
ok then should wait for bug update

I mean TChar.Size = 1 TWideChar.Size = 2
For TChar.MinValue = #0   and TChar.MaxValue #255  I just think its value from ASCII table,  ya maybe you right
Should be treat like string  TChar.Empty = '';

Add Currency Helper and DateTime Helper

TDateTime.ToString  = 1899-12-30 00:00:00:000  (zero base )  just because of Lotus  ?

Should we have Type.DefaultValue ?

For Boolean.ToString  -1   ?  why not FALSE and TRUE or 1

Can we get along between Tradition and Modern way?

SysUtils, StrUtils, DateUtils -> SysHelper, StrHelper, DateHelper




Types        Size = SizeOf : MinValue .. MaxValue : Low .. High
-----------  ----------------------------------------------
Boolean    : 1 = 1 :  0 - 1 : FALSE .. TRUE
Char       : 1 = 1 :  .. � :  .. �
Byte       : 1 = 1 : 0 .. 255 : 0 .. 255
UInt8      : 1 = 1 : 0 .. 255 : 0 .. 255
UInt16     : 2 = 2 : 0 .. 65535 : 0 .. 65535
UInt32     : 4 = 4 : 0 .. 4294967295 : 0 .. 4294967295
UInt64     : 8 = 8 : 0 .. 4294967295 : 0 .. 18446744073709551615
NativeUInt : 8 = 8 : 0 .. 4294967295 : 0 .. 18446744073709551615
Int8       : 1 = 1 : -128 .. 127 : -128 .. 127
Int16      : 2 = 2 : -32768 .. 32767 : -32768 .. 32767
Int32      : 4 = 4 : -2147483648 .. 2147483647 : -2147483648 .. 2147483647
Int64      : 8 = 8 : -2147483648 .. 2147483647 : -9223372036854775808 .. 9223372036854775807
NativeInt  : 8 = 8 : -2147483648 .. 2147483647 : -9223372036854775808 .. 9223372036854775807
Single     : 4 = 4 : -3.402823466E+38 ..  3.402823466E+38 : type mismatch
Double     : 8 = 8 : -1.7976931348623157E+308 ..  1.7976931348623157E+308 : type mismatch
Extended   : 10 = 10 : -1.18973149535723176502E+4932 ..  1.18973149535723176502E+4932 : type mismatch
Currency   : 8 = 8 : -9.223372036854775808E+14 ..  9.223372036854775807E+14 : type mismatch
TDateTime  : 8 = 8 : -6.9359300000000000E+005 ..  2.9584659999999884E+006 : 0001-01-01 00:00:00:000 - 9999-12-31 23:59:59:999
TGuid      :  none
String     :  none
Pointer    : nil none

Types        ToString Not Initialize
-----------  ----------------------------------------------
Boolean    : 0
Char       :
Byte       : 0
UInt8      : 0
UInt16     : 0
UInt32     : 0
UInt64     : 0
NativeUInt : 0
Int8       : 0
Int16      : 0
Int32      : 0
Int64      : 0
NativeInt  : 0
Single     : 0
Double     : 0
Extended   : 0
Currency   : 0.0000
TDateTime  : 1899-12-30 00:00:00:000
TGuid      : {00000000-0000-0000-0000-000000000000}
String     :
Pointer    : 0000000000000000

Types        ToString MinValue
-----------  ----------------------------------------------
Boolean    : 0
Char       :
Byte       : 0
UInt8      : 0
UInt16     : 0
UInt32     : 0
UInt64     : 0
NativeUInt : 0
Int8       : -128
Int16      : -32768
Int32      : -2147483648
Int64      : -2147483648
NativeInt  : -2147483648
Single     : -3.402823466E38
Double     : -1.79769313486232E308
Extended   : -1.18973149535723E4932
Currency   : -922,337,203,685,477.5808
TDateTime  : 0001-01-01 00:00:00:000
TGuid      : {00000000-0000-0000-0000-000000000000}
String     :
Pointer    : 0000000000000000

Types        ToString MaxValue
-----------  ----------------------------------------------
Boolean    : -1
Char       : �
Byte       : 255
UInt8      : 255
UInt16     : 65535
UInt32     : 4294967295
UInt64     : 4294967295
NativeUInt : 4294967295
Int8       : 127
Int16      : 32767
Int32      : 2147483647
Int64      : 2147483647
NativeInt  : 2147483647
Single     : 3.402823466E38
Double     : 1.79769313486232E308
Extended   : 1.18973149535723E4932
Currency   : 922,337,203,685,477.5807
TDateTime  : 9999-12-31 23:59:59:999
TGuid      : {FDB6EBE5-77B1-43E3-BB70-70714B9C1865}
String     : abc
Pointer    : 000000000067EA60
Now        : 2019-4-14 15:48:57.515 = 2019-04-14 15:48:57:515



Code: Pascal  [Select][+][-]
  1.  
  2. {$MODE OBJFPC}
  3. {$MODESWITCH TYPEHELPERS}
  4. program TestHelper;
  5.  
  6. uses SysUtils, DateUtils;
  7.  
  8. type
  9.  
  10.    TCharHelper = type helper for Char
  11.    public
  12.       const
  13.       Size     = SizeOf( Char );
  14.       MinValue = Char(  Low( Char ) );
  15.       MaxValue = Char( High( Char ) );
  16.    public
  17.       function    ToString :String;
  18.       // IsSymbol, IsControl, IsDigit, IsNumber, IsPunctuation, IsSeparator
  19.       // IsLowSurrogate, IsHighSurrogate, IsSurrogate, IsSurrogatePair
  20.       // IsLetter, IsLetterOrDigit, IsWhiteSpace, IsLower, IsUpper
  21.       // ToLower, ToUpper
  22.    end;
  23.  
  24.    TCurrencyHelper = type helper for Currency
  25.    public
  26.       const
  27.       Size     = SizeOf( Currency );
  28.       MinValue = Currency( -922337203685477.5808 );   // Low  ?
  29.       MaxValue = Currency(  922337203685477.5807 );   // High ?
  30.    public
  31.       function    ToString :String;
  32.    end;
  33.  
  34.    TDateHelper = type helper for TDateTime
  35.    public
  36.       const
  37.       Size     = SizeOf( TDateTime );
  38.       MinValue = TDateTime( -6.9359300000000000E+005 ); // EncodeDate(    1,  1,  1 ) + EncodeTime(  0,  0,  0,   0 );
  39.       MaxValue = TDateTime(  2.9584659999999884E+006 ); // EncodeDate( 9999, 12, 31 ) + EncodeTime( 23, 59, 59, 999 ); // predicted end of the world
  40.    public
  41.       function    ToString       :String;
  42.       function    Year           :Word;
  43.       function    Month          :Word;
  44.       function    Week           :Word;
  45.       function    Day            :Word;
  46.       function    Hour           :Word;
  47.       function    Minute         :Word;
  48.       function    Second         :Word;
  49.       function    MilliSecond    :Word;
  50.    end;
  51.  
  52. function    TCharHelper.ToString :String;
  53.    begin
  54.       result := self;
  55.    end;
  56.  
  57. function    TCurrencyHelper.ToString :String;
  58.    begin
  59.       result := FormatFloat( '#,##0.0000', self );
  60.    end;
  61.  
  62. function    TDateHelper.ToString :String;
  63.    begin
  64.       result := FormatDateTime( 'YYYY-MM-DD HH:mm:ss:zzz', self );
  65.    end;
  66.  
  67. function    TDateHelper.Year :Word;
  68.    begin
  69.       result  := YearOf( self );
  70.    end;
  71.  
  72. function    TDateHelper.Month :Word;
  73.    begin
  74.       result  := MonthOf( self );
  75.    end;
  76.  
  77. function    TDateHelper.Week :Word;
  78.    begin
  79.       result  := WeekOf( self );
  80.    end;
  81.  
  82. function    TDateHelper.Day :Word;
  83.    begin
  84.       result  := DayOf( self );
  85.    end;
  86.  
  87. function    TDateHelper.Hour :Word;
  88.    begin
  89.       result  := HourOf( self );
  90.    end;
  91.  
  92. function    TDateHelper.Minute :Word;
  93.    begin
  94.       result  := MinuteOf( self );
  95.    end;
  96.  
  97. function    TDateHelper.Second :Word;
  98.    begin
  99.       result  := SecondOf( self );
  100.    end;
  101.  
  102. function    TDateHelper.MilliSecond :Word;
  103.    begin
  104.       result  := MilliSecondOf( self );
  105.    end;
  106.  
  107. var
  108.    VBoolean    :Boolean;
  109.    VChar       :Char;
  110.    VByte       :Byte;
  111.  
  112.    VUInt8      :UInt8;
  113.    VUInt16     :UInt16;
  114.    VUInt32     :UInt32;
  115.    VUInt64     :UInt64;
  116.    VNativeUInt :NativeUInt;
  117.  
  118.    VInt8       :Int8;
  119.    VInt16      :Int16;
  120.    VInt32      :Int32;
  121.    VInt64      :Int64;
  122.    VNativeInt  :NativeInt;
  123.  
  124.    VSingle     :Single;
  125.    VDouble     :Double;
  126.    VExtended   :Extended;
  127.  
  128.    VCurrency   :Currency;
  129.    VDateTime   :TDateTime;
  130.    VGuid       :TGuid;
  131.  
  132.    VString     :String;
  133.    VPointer    :Pointer;
  134.  
  135. begin
  136.  
  137.    WriteLn( 'Types        Value Not Initialize = Ordinal Value' );
  138.    WriteLn( '-----------  ----------------------------------------------' );
  139.    WriteLn( 'Boolean    : ', VBoolean,       ' = ', Ord( VBoolean ), ' : ', true, ' = ', Ord( true ) );
  140.    WriteLn( 'Char       : ', VChar,          ' = ', Ord( VChar ) );
  141.    WriteLn( 'Byte       : ', VByte,          ' = ', Ord( VByte ) );
  142.    WriteLn( 'UInt8      : ', VUInt8,         ' = ', Ord( VUInt8 ) );
  143.    WriteLn( 'UInt16     : ', VUInt16,        ' = ', Ord( VUInt16 ) );
  144.    WriteLn( 'UInt32     : ', VUInt32,        ' = ', Ord( VUInt32 ) );
  145.    WriteLn( 'UInt64     : ', VUInt64,        ' = ', Ord( VUInt64 ) );
  146.    WriteLn( 'NativeUInt : ', VNativeUInt,    ' = ', Ord( VNativeUInt ) );
  147.    WriteLn( 'Int8       : ', VInt8,          ' = ', Ord( VInt8 ) );
  148.    WriteLn( 'Int16      : ', VInt16,         ' = ', Ord( VInt16 ) );
  149.    WriteLn( 'Int32      : ', VInt32,         ' = ', Ord( VInt32 ) );
  150.    WriteLn( 'Int64      : ', VInt64,         ' = ', Ord( VInt64) );
  151.    WriteLn( 'NativeInt  : ', VNativeInt,     ' = ', Ord( VNativeInt ) );
  152.    WriteLn( 'Single     : ', VSingle,        ' = none' );
  153.    WriteLn( 'Double     : ', VDouble,        ' = none' );
  154.    WriteLn( 'Extended   : ', VExtended,      ' = none' );
  155.    WriteLn( 'Currency   : ', VCurrency,      ' = none' );
  156.    WriteLn( 'TDateTime  : ', VDateTime,      ' = none' );
  157.    WriteLn( 'TGuid      : ', VGuid.ToString, ' = none' );
  158.    WriteLn( 'String     : ', VString,        ' = none' );
  159.    Write  ( 'Pointer    : ' );
  160.    if VPointer = nil then WriteLn( 'nil = none' );
  161.  
  162.    WriteLn;
  163.    WriteLn( 'Types        Size = SizeOf : MinValue .. MaxValue : Low .. High');
  164.    WriteLn( '-----------  ----------------------------------------------' );
  165.    WriteLn( 'Boolean    : ', Boolean.Size,      ' = ', SizeOf( Boolean ),     ' :  0 - 1',                                                            ' : ', Low( Boolean ),   ' .. ', High( Boolean ) );
  166.    WriteLn( 'Char       : ', Char.Size,         ' = ', SizeOf( Char ),        ' : ', Char.MinValue,         ' .. ', Char.MaxValue,       ' : ', Low( Char ),      ' .. ', High( Char ) );
  167.    WriteLn( 'Byte       : ', Byte.Size,         ' = ', SizeOf( Byte ),        ' : ', Byte.MinValue,         ' .. ', Byte.MaxValue,       ' : ', Low( Byte ),      ' .. ', High( Byte ) );
  168.    WriteLn( 'UInt8      : ', UInt8.Size,        ' = ', SizeOf( UInt8 ),       ' : ', UInt8.MinValue,        ' .. ', UInt8.MaxValue,      ' : ', Low( UInt8 ),     ' .. ', High( UInt8 ) );
  169.    WriteLn( 'UInt16     : ', UInt16.Size,       ' = ', SizeOf( UInt16 ),      ' : ', UInt16.MinValue,       ' .. ', UInt16.MaxValue,     ' : ', Low( UInt16 ),    ' .. ', High( UInt16 ) );
  170.    WriteLn( 'UInt32     : ', UInt32.Size,       ' = ', SizeOf( UInt32 ),      ' : ', UInt32.MinValue,       ' .. ', UInt32.MaxValue,     ' : ', Low( UInt32 ),    ' .. ', High( UInt32 ) );
  171.    WriteLn( 'UInt64     : ', UInt64.Size,       ' = ', SizeOf( UInt64 ),      ' : ', UInt64.MinValue,       ' .. ', UInt64.MaxValue,     ' : ', Low( UInt64 ),    ' .. ', High( UInt64 ) );
  172.    WriteLn( 'NativeUInt : ', NativeUInt.Size,   ' = ', SizeOf( NativeUint ),  ' : ', NativeUInt.MinValue,   ' .. ', NativeUInt.MaxValue, ' : ', Low( NativeUInt ),' .. ', High( NativeUInt ) );
  173.    WriteLn( 'Int8       : ', Int8.Size,         ' = ', SizeOf( Int8 ),        ' : ', Int8.MinValue,         ' .. ', Int8.MaxValue,       ' : ', Low( Int8 ),      ' .. ', High( Int8 ) );
  174.    WriteLn( 'Int16      : ', Int16.Size,        ' = ', SizeOf( Int16 ),       ' : ', Int16.MinValue,        ' .. ', Int16.MaxValue,      ' : ', Low( Int16 ),     ' .. ', High( Int16 ) );
  175.    WriteLn( 'Int32      : ', Int32.Size,        ' = ', SizeOf( Int32 ),       ' : ', Int32.MinValue,        ' .. ', Int32.MaxValue,      ' : ', Low( Int32 ),     ' .. ', High( Int32 ) );
  176.    WriteLn( 'Int64      : ', Int64.Size,        ' = ', SizeOf( Int64 ),       ' : ', Int64.MinValue,        ' .. ', Int64.MaxValue,      ' : ', Low( Int64 ),     ' .. ', High( Int64 ) );
  177.    WriteLn( 'NativeInt  : ', NativeInt.Size,    ' = ', SizeOf( NativeInt ),   ' : ', NativeInt.MinValue,    ' .. ', NativeInt.MaxValue,  ' : ', Low( NativeInt ), ' .. ', High( NativeInt ) );
  178.    WriteLn( 'Single     : ', Single.Size,       ' = ', SizeOf( Single ),      ' : ', Single.MinValue,       ' .. ', Single.MaxValue,     ' : type mismatch ' );
  179.    WriteLn( 'Double     : ', Double.Size,       ' = ', SizeOf( Double ),      ' : ', Double.MinValue,       ' .. ', Double.MaxValue,     ' : type mismatch ' );
  180.    WriteLn( 'Extended   : ', Extended.Size,     ' = ', SizeOf( Extended ),    ' : ', Extended.MinValue,     ' .. ', Extended.MaxValue,   ' : type mismatch ' );
  181.    WriteLn( 'Currency   : ', Currency.Size,     ' = ', SizeOf( Currency ),    ' : ', Currency.MinValue,     ' .. ', Currency.MaxValue,   ' : type mismatch ' );
  182.    WriteLn( 'TDateTime  : ', TDateTime.Size,    ' = ', SizeOf( TDateTime ),   ' : ', TDateTime.MinValue,    ' .. ', TDateTime.MaxValue,  ' : ', TDateTime.MinValue.ToString, ' - ', TDateTime.MaxValue.ToString );
  183.    WriteLn( 'TGuid      : ', ' none ' );
  184.    WriteLn( 'String     : ', ' none' );
  185.    Write  ( 'Pointer    : ' );
  186.    if VPointer = nil then WriteLn( 'nil none' );
  187.  
  188.    WriteLn;
  189.    WriteLn( 'Types        ToString Not Initialize' );
  190.    WriteLn( '-----------  ----------------------------------------------' );
  191.    WriteLn( 'Boolean    : ', VBoolean.ToString );
  192.    WriteLn( 'Char       : ', VChar.ToString );
  193.    WriteLn( 'Byte       : ', VByte.ToString );
  194.    WriteLn( 'UInt8      : ', VUInt8.ToString );
  195.    WriteLn( 'UInt16     : ', VUInt16.ToString );
  196.    WriteLn( 'UInt32     : ', VUInt32.ToString );
  197.    WriteLn( 'UInt64     : ', VUInt64.ToString );
  198.    WriteLn( 'NativeUInt : ', VNativeUInt.ToString );
  199.    WriteLn( 'Int8       : ', VInt8.ToString );
  200.    WriteLn( 'Int16      : ', VInt16.ToString );
  201.    WriteLn( 'Int32      : ', VInt32.ToString );
  202.    WriteLn( 'Int64      : ', VInt64.ToString );
  203.    WriteLn( 'NativeInt  : ', VNativeInt.ToString );
  204.    WriteLn( 'Single     : ', VSingle.ToString );
  205.    WriteLn( 'Double     : ', VDouble.ToString );
  206.    WriteLn( 'Extended   : ', VExtended.ToString );
  207.    WriteLn( 'Currency   : ', VCurrency.ToString );
  208.    WriteLn( 'TDateTime  : ', VDateTime.ToString );
  209.    WriteLn( 'TGuid      : ', VGuid.ToString );
  210.    WriteLn( 'String     : ', VString );
  211.    WriteLn( 'Pointer    : ', HexStr( VPointer ) );
  212.  
  213.    VBoolean    := Low( Boolean );
  214.    VChar       := Char.MinValue;
  215.    VByte       := Byte.MinValue;
  216.    VUInt8      := UInt8.MinValue;
  217.    VUInt16     := UInt16.MinValue;
  218.    VUInt32     := UInt32.MinValue;
  219.    VUInt64     := UInt64.MinValue;
  220.    VNativeUInt := NativeUInt.MinValue;
  221.    VInt8       := Int8.MinValue;
  222.    VInt16      := Int16.MinValue;
  223.    VInt32      := Int32.MinValue;
  224.    VInt64      := Int64.MinValue;
  225.    VNativeInt  := NativeInt.MinValue;
  226.    VSingle     := Single.MinValue;
  227.    VDouble     := Double.MinValue;
  228.    VExtended   := Extended.MinValue;
  229.    VCurrency   := Currency.MinValue;
  230.    VDateTime   := TDateTime.MinValue;
  231.    VGuid       := GUID_NULL;     // TGUID.NullGuid ?
  232.    VString     := '';            // TString.Empty ?
  233.    VPointer    := nil;
  234.  
  235.    WriteLn;
  236.    WriteLn( 'Types        ToString MinValue' );
  237.    WriteLn( '-----------  ----------------------------------------------' );
  238.    WriteLn( 'Boolean    : ', VBoolean.ToString );
  239.    WriteLn( 'Char       : ', VChar.ToString );
  240.    WriteLn( 'Byte       : ', VByte.ToString );
  241.    WriteLn( 'UInt8      : ', VUInt8.ToString );
  242.    WriteLn( 'UInt16     : ', VUInt16.ToString );
  243.    WriteLn( 'UInt32     : ', VUInt32.ToString );
  244.    WriteLn( 'UInt64     : ', VUInt64.ToString );
  245.    WriteLn( 'NativeUInt : ', VNativeUInt.ToString );
  246.    WriteLn( 'Int8       : ', VInt8.ToString );
  247.    WriteLn( 'Int16      : ', VInt16.ToString );
  248.    WriteLn( 'Int32      : ', VInt32.ToString );
  249.    WriteLn( 'Int64      : ', VInt64.ToString );
  250.    WriteLn( 'NativeInt  : ', VNativeInt.ToString );
  251.    WriteLn( 'Single     : ', VSingle.ToString );
  252.    WriteLn( 'Double     : ', VDouble.ToString );
  253.    WriteLn( 'Extended   : ', VExtended.ToString );
  254.    WriteLn( 'Currency   : ', VCurrency.ToString );
  255.    WriteLn( 'TDateTime  : ', VDateTime.ToString );
  256.    WriteLn( 'TGuid      : ', VGuid.ToString );
  257.    WriteLn( 'String     : ', VString );
  258.    WriteLn( 'Pointer    : ', HexStr( VPointer ) );
  259.  
  260.    VBoolean    := High( Boolean );
  261.    VChar       := Char.MaxValue;
  262.    VByte       := Byte.MaxValue;
  263.    VUInt8      := UInt8.MaxValue;
  264.    VUInt16     := UInt16.MaxValue;
  265.    VUInt32     := UInt32.MaxValue;
  266.    VUInt64     := UInt64.MaxValue;
  267.    VNativeUInt := NativeUInt.MaxValue;
  268.    VInt8       := Int8.MaxValue;
  269.    VInt16      := Int16.MaxValue;
  270.    VInt32      := Int32.MaxValue;
  271.    VInt64      := Int64.MaxValue;
  272.    VNativeInt  := NativeInt.MaxValue;
  273.    VSingle     := Single.MaxValue;
  274.    VDouble     := Double.MaxValue;
  275.    VExtended   := Extended.MaxValue;
  276.    VCurrency   := Currency.MaxValue;
  277.    VDateTime   := TDateTime.MaxValue;
  278.    VGuid       := TGuid.NewGuid;
  279.    VString     := 'abc';         // add TString.ToBase64 and TString.ToHexString and other encoding ...
  280.    VPointer    := Addr( VGuid );
  281.  
  282.    WriteLn;
  283.    WriteLn( 'Types        ToString MaxValue' );
  284.    WriteLn( '-----------  ----------------------------------------------' );
  285.    WriteLn( 'Boolean    : ', VBoolean.ToString );
  286.    WriteLn( 'Char       : ', VChar.ToString );
  287.    WriteLn( 'Byte       : ', VByte.ToString );
  288.    WriteLn( 'UInt8      : ', VUInt8.ToString );
  289.    WriteLn( 'UInt16     : ', VUInt16.ToString );
  290.    WriteLn( 'UInt32     : ', VUInt32.ToString );
  291.    WriteLn( 'UInt64     : ', VUInt64.ToString );
  292.    WriteLn( 'NativeUInt : ', VNativeUInt.ToString );
  293.    WriteLn( 'Int8       : ', VInt8.ToString );
  294.    WriteLn( 'Int16      : ', VInt16.ToString );
  295.    WriteLn( 'Int32      : ', VInt32.ToString );
  296.    WriteLn( 'Int64      : ', VInt64.ToString );
  297.    WriteLn( 'NativeInt  : ', VNativeInt.ToString );
  298.    WriteLn( 'Single     : ', VSingle.ToString );
  299.    WriteLn( 'Double     : ', VDouble.ToString );
  300.    WriteLn( 'Extended   : ', VExtended.ToString );
  301.    WriteLn( 'Currency   : ', VCurrency.ToString );
  302.    WriteLn( 'TDateTime  : ', VDateTime.ToString );
  303.    WriteLn( 'TGuid      : ', VGuid.ToString );
  304.    WriteLn( 'String     : ', VString );
  305.    WriteLn( 'Pointer    : ', HexStr( VPointer ) );
  306.  
  307.  
  308.    VDateTime := Now;
  309.    WriteLn( 'Now        : ', VDateTime.Year, '-', VDateTime.Month, '-', VDateTime.Day, ' ',
  310.                              VDateTime.Hour, ':', VDateTime.Minute, ':', VDateTime.Second, '.', VDateTime.MilliSecond, ' = ',
  311.                              VDateTime.ToString );
  312.  
  313. end.
  314.  
  315.  

Thaddy

  • Hero Member
  • *****
  • Posts: 19273
  • Glad to be alive.
Re: Alias for Int64
« Reply #18 on: April 14, 2019, 11:38:18 am »
Quote
TDateTime.ToString  = 1899-12-30 00:00:00:000  (zero base )  just because of Lotus  ?
No because of Windows, Lotus, Excel, Delphi etc. Originally caused by Lotus of course.
To complicate things further C# handles that date as a NULL value and handles the zero date correctly.
« Last Edit: April 14, 2019, 12:32:00 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: Alias for Int64
« Reply #19 on: April 14, 2019, 07:46:19 pm »
I cross cek syshelph.inc

look at code snippets seems ok


  TInt64Helper = Type Helper for Int64
  public
    const
      MaxValue = 9223372036854775807;
      MinValue = -9223372036854775808;

  TQWordHelper = Type Helper for QWord
  public
    const
      MaxValue = 18446744073709551615;
      MinValue = 0;

  TNativeIntHelper = Type Helper for NativeInt
  public
    const
{$IFDEF CPU64BITS}
      MaxValue = 9223372036854775807;
      MinValue = -9223372036854775808;
{$ELSE !CPU64BITS}
      MaxValue = 2147483647;
      MinValue = -2147483648;
{$ENDIF CPU64BITS}

  TNativeUIntHelper = Type Helper for NativeUInt
  public
    const
{$IFDEF CPU64BITS}
      MaxValue = 18446744073709551615;
{$ELSE !CPU64BITS}
      MaxValue = 4294967295;
{$ENDIF CPU64BITS}
      MinValue = 0;



currently I am using debian so I double check with redhat, same result.


could it be the binary compiled with 32bit ?   

for Native CPU64BITS is not define may be

or const should be cast

      MaxValue = Int64( 9223372036854775807 );
      MinValue = Int64( -9223372036854775808 );

      MaxValue = QWord( 18446744073709551615 );

strange.

for 32 bit cannot test yet.

debian source  fpc-laz_3.0.4-1_amd64.deb fpc-src_3.0.4-2_amd64.deb
redhat source  fpc-3.0.4-1.x86_64.rpm fpc-src-3.0.4-1.x86_64.rpm

Thaddy

  • Hero Member
  • *****
  • Posts: 19273
  • Glad to be alive.
Re: Alias for Int64
« Reply #20 on: April 14, 2019, 07:54:56 pm »
You must not directly hardcode the value, butdo ot like the compiler does: define the min/max values as Low(IntType) and High(IntType) as is done in syshelph.inc.
Directly hard-coding the value can easily cause bugs when the compiler determined value is out-of-sync with what you hard-coded. In fact fairly recently a bug was discovered in the RTL exactly because of that.
objects are fine constructs. You can even initialize them with constructors.

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: Alias for Int64
« Reply #21 on: April 15, 2019, 02:42:00 am »
That snippets is from the source  fpc-src_3.0.4-2_amd64.deb,  while seems ok but implementation   fpc-laz_3.0.4-1_amd64.deb test different.

for ordinal type yes, should be

const
      MaxValue = High( Int64 );
      MinValue = Low( Int64 );

so the source should be update.

Thaddy

  • Hero Member
  • *****
  • Posts: 19273
  • Glad to be alive.
Re: Alias for Int64
« Reply #22 on: April 15, 2019, 07:57:40 am »
Testing features should always be done with the latest release version (3.0.4), a release candidate (3.2.0) or trunk (3.3.1).
There is no way 3.0.2 would be uodated unless a major calamity should warrant that.
The fact the implementation changed was for exactly the reason I described: at least one of the const literals was off-by-one leading to range check errors.
« Last Edit: April 15, 2019, 08:00:24 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

Thaddy

  • Hero Member
  • *****
  • Posts: 19273
  • Glad to be alive.
Re: Alias for Int64
« Reply #23 on: April 16, 2019, 09:11:24 pm »
My patch is applied, (Thx Sven) so it should work as advertised now in trunk.
Your helper code is incomplete, may be we can work together and bring it forward.
objects are fine constructs. You can even initialize them with constructors.

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: Alias for Int64
« Reply #24 on: April 20, 2019, 12:45:17 pm »
Just a bit progress, still learn for string


Table 3.3 Boolean types

Name        Size  Ord(True)
----------  ----  ---------
Boolean     1     1                    // Our true boolean

Boolean8    1     1
Boolean16   3     1                    // @lucamar yes typo implemented to class function and call SizeOf
Boolean32   4     1
Boolean64   8     1

ByteBool    1     Any nonzero value    // oh no imported c bool
WordBool    2     Any nonzero value
LongBool    4     Any nonzero value
QWordBool   8     Any nonzero value



if define as subrange type

Boolean     Ord( false ) .. Ord( true )

Boolean8    0 .. 1
Boolean16   0 .. 1
Boolean32   0 .. 1
Boolean64   0 .. 1

ByteBool    0 .. > 0    Unsigned 255   Signed -1  ToString -1
WordBool    0 .. > 0
LongBool    0 .. > 0
QWordBool   0 .. > 0

for sanity of Pascal, I would suggest our export is always high quality true,
the C family always accepted our product.

ByteBool    0 .. 1
WordBool    0 .. 1
LongBool    0 .. 1
QWordBool   0 .. 1

when importing we have to protect our happy world

Boolean := not ( bool = 0 );  // guard from variable and also function

Because Boolean is ordinal type too, we can also define for MinValue and MaxValue

for Size

in http://wiki.freepascal.org/SizeOf
dynamic arrays and alike Since dynamic arrays are realized as pointers to a block on the heap,
sizeOf evaluates to the pointer's size. <------ !!!
In order to determine the array's size – of its data –
sizeOf has to be used in conjunction with the function length.
  ex:    writeLn(format(totalData, [length(f) * sizeOf(f[0])]));

my preference is to rename to ByteSize ( smallest unit size with length equal one ) also add Length

   TBooleanHelperEx = type Helper( TBooleanHelper ) for Boolean
   public
      const
         MaxValue =    High( Boolean );
         MinValue =     Low( Boolean );
         ByteSize =  SizeOf( Boolean );
         Length   = SizeInt( 1 );
   end;

   TypeHelper.Size := Length * ByteSize;

   BooleanSize := Length( ABoolean ) * SizeOf( ABoolean );  // type mismatch on Length
   BooleanSize := LengthBoolean      * SizeOf(  Boolean );  // replace with constant or just 1
   BooleanSize := ABoolean.Length    * ABoolean.ByteSize;   // var
   BooleanSize :=  Boolean.Length    *  Boolean.ByteSize;   // type

while Length is just nice to have for base type (length always one),
for consistency of type helper would be better.

so currently we have MaxValue, MinValue, ByteSize, Length,
and usefulness of ToString, while pair with Parse, why my mind always connect to word from ?

type.FromString   |  type.FromBytes    |  type.Decode    |  type.Import
type.ToString     |  type.ToBytes      |  type.Encode    |  type.Export

may be our port harbour should be type of string only

ABoolean          := true;

// using function
ABoolean          := ABoolean.FromString( 'true' );
AString           := ABoolean.ToString;

// using properties
ABoolean.AsString := 'true';
AString           := ABoolean.AsString;

AString.AsBytes   := from socket or byte stream;


For extension I would rather choose simple get set function
so we can define our own format string

   TBooleanHelperEx = type Helper( TBooleanHelper ) for Boolean
   public
      const
         MaxValue =    High( Boolean );
         MinValue =     Low( Boolean );
         ByteSize =  SizeOf( Boolean );
         Length   = SizeInt( 1 );
   private                                 // protect for standarization format
      function    GetString :TAnsiString;
      procedure   SetString( const AString :TAnsiString );
   public
      property    AsString :TAnsiString read GetString write SetString;
   end;


some still wait for update cause using fpc version 3.0.4


for size


Types               type.ByteSize = var.ByteSize = SizeOf( type ) = SizeOf( var ) : Size = Length * ByteSize
-----------         ----------------------------------------------
Byte              : 1 = 1 = 1 = 1 : 1 = 1 * 1
AnsiChar          : 1 = 1 = 1 = 1 : 1 = 1 * 1
UnicodeChar       : 2 = 2 = 2 = 2 : 2 = 1 * 2
TBytes            : 1 = 1 = 8 = 8 : 0 = 0 * 1 SizeOf( pointer )
AnsiString        : 1 = 1 = 8 = 8 : 0 = 0 * 1 SizeOf( pointer )
UnicodeString     : 2 = 2 = 8 = 8 : 0 = 0 * 2 SizeOf( pointer )

SetLength( 10 )
TBytes            : 1 = 1 = 8 = 8 : 10 = 10 * 1
AnsiString        : 1 = 1 = 8 = 8 : 10 = 10 * 1
UnicodeString     : 2 = 2 = 8 = 8 : 20 = 10 * 2


prefer to use ToString( TUseBoolStrs.True ) else can print true -1

Types               var = type.MinValue = var.MinValue = Low( type ) = Low( var ) = ToString
-----------         ----------------------------------------------
ByteBool          : FALSE = FALSE = FALSE = TRUE = TRUE = False      Low ???
WordBool          : FALSE = FALSE = FALSE = TRUE = TRUE = False
LongBool          : FALSE = FALSE = FALSE = TRUE = TRUE = False
QWordBool         : FALSE = FALSE = FALSE = TRUE = TRUE = False


hex and oct result ?
Types               hexstring | octstring | binstring | string | var
Int8              : 00000000FFFFFF80 | 0000000000037777777600 | 0000000000000000000000000000000011111111111111111111111110000000 | -128 | -128
Int16             : 00000000FFFF8000 | 0000000000037777700000 | 0000000000000000000000000000000011111111111111111000000000000000 | -32768 | -32768



attach source code program and unit

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: Alias for Int64
« Reply #25 on: April 20, 2019, 12:45:56 pm »
forget the unit

Thaddy

  • Hero Member
  • *****
  • Posts: 19273
  • Glad to be alive.
Re: Alias for Int64
« Reply #26 on: April 20, 2019, 01:26:32 pm »
You are re-decxlaring all boolean types from system? Serious?
But the rest is useful. I 'll have a better look later.
« Last Edit: April 20, 2019, 01:55:55 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12905
  • FPC developer.
Re: Alias for Int64
« Reply #27 on: April 20, 2019, 01:38:43 pm »
Forgetting about the _WHY?_, reuse already defined "array of" in system/objpas and types as much as possible.

Declaring your own makes them incompatible with routines already declared with one of the predefined types.

Thaddy

  • Hero Member
  • *****
  • Posts: 19273
  • Glad to be alive.
Re: Alias for Int64
« Reply #28 on: April 20, 2019, 01:56:56 pm »
Yup. But the helpers as such are very useful.
objects are fine constructs. You can even initialize them with constructors.

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: Alias for Int64
« Reply #29 on: April 20, 2019, 07:14:04 pm »
dont worry :D the code just for test, 

I found naming array like arraybyte arraystring  that can be static and dynamic array
TBooleanDynArray,  TByteDynArray this should be make different

but for me naming just combing T + array of + type is easier for me. 

not using template, I just fill the code is just there, bit redundant of course.

btw for hexstring and octstring

Code: Pascal  [Select][+][-]
  1. program hexstr; // from sstrings.inc
  2.  
  3. const HexTbl :array[ 0 .. 15 ] of char = '0123456789ABCDEF';
  4.  
  5. function hexstr( val :longint; cnt :byte ) :shortstring;
  6.         var i :longint;
  7.         begin
  8.                 hexstr[ 0 ] := char( cnt );
  9.                 for i := cnt downto 1 do
  10.                 begin
  11.                         hexstr[ i ] := hextbl[ val and $f ];
  12.                         val := val shr 4;               // bit sign ?
  13.                 end;
  14.         end;
  15.  
  16. function hexstrdiv( val :longint; cnt :byte ) :shortstring;
  17.         var i :longint;
  18.         begin
  19.                 hexstrdiv[ 0 ] := char( cnt );
  20.                 for i := cnt downto 1 do
  21.                 begin
  22.                         hexstrdiv[ i ] := hextbl[ val and $f ];
  23.                         val := val div 16;      // performance over shr        
  24.                 end;
  25.         end;
  26.  
  27. begin
  28.         WriteLn( hexstr(   -128, 16 ), ' ', hexstrdiv(   -128, 16 ) );
  29.         WriteLn( hexstr( -32768, 16 ), ' ', hexstrdiv( -32768, 16 ) );
  30. end.
  31.  
  32.  

 

TinyPortal © 2005-2018