Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Bart
On Sun, Feb 25, 2018 at 5:34 PM, Michael Van Canneyt wrote: >> So, would it be possible to have an overloaded Abs(V: Variant): >> Variant; function in the variants unit? > > > I advise against it. > > S : String; > > begin > S:='My very nice string'; > S:=Abs(S); > end; > > Will then compile

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Rik van Kekem
On 25/02/18 17:59, Michael Van Canneyt wrote: On Sun, 25 Feb 2018, Bart wrote: On Sun, Feb 25, 2018 at 5:34 PM, Michael Van Canneyt wrote: So, all we can do is let the compiler pick the float version for Abs(Variant)? It seems so. Better yet, don't use variants. They violate what Pascal sta

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Bart
On Sun, Feb 25, 2018 at 5:59 PM, Michael Van Canneyt wrote: >> So, all we can do is let the compiler pick the float version for >> Abs(Variant)? > > > It seems so. OK, for D compatibilty (untill they change that). > Better yet, don't use variants. They violate what Pascal stands > for: type saf

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Michael Van Canneyt
On Sun, 25 Feb 2018, Bart wrote: On Sun, Feb 25, 2018 at 5:34 PM, Michael Van Canneyt wrote: So, would it be possible to have an overloaded Abs(V: Variant): Variant; function in the variants unit? I advise against it. S : String; begin S:='My very nice string'; S:=Abs(S); end; Wil

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Bart
On Sun, Feb 25, 2018 at 5:34 PM, Michael Van Canneyt wrote: >> So, would it be possible to have an overloaded Abs(V: Variant): >> Variant; function in the variants unit? > > > I advise against it. > > S : String; > > begin > S:='My very nice string'; > S:=Abs(S); > end; > > Will then compile

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Michael Van Canneyt
On Sun, 25 Feb 2018, Bart wrote: On Sun, Feb 25, 2018 at 5:01 PM, Jonas Maebe wrote: As Michael said, overloads are selected at compile time. This is true for both FPC and Delphi. We even have over a 100 unit tests that we ran under Delphi to reverse engineer their selection priorities in c

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Bart
On Sun, Feb 25, 2018 at 5:01 PM, Jonas Maebe wrote: > As Michael said, overloads are selected at compile time. This is true for > both FPC and Delphi. We even have over a 100 unit tests that we ran under > Delphi to reverse engineer their selection priorities in case of variants: > https://svn.fr

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Jonas Maebe
On 25/02/18 16:41, Bart wrote: Delphi 10.2 Tokyo: X = -1,5 VarIsFloat : TRUE VarIsNumeric: TRUE VarIsOrdinal: FALSE After Abs() X = 1,5 VarIsFloat : TRUE VarIsNumeric: TRUE VarIsOrdinal: FALSE I asked to test with "X := -1" to see if Delphi always chooses the float overload. As Michael said,

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Bart
Delphi 10.2 Tokyo: X = -1,5 VarIsFloat : TRUE VarIsNumeric: TRUE VarIsOrdinal: FALSE After Abs() X = 1,5 VarIsFloat : TRUE VarIsNumeric: TRUE VarIsOrdinal: FALSE I asked to test with "X := -1" to see if Delphi always chooses the float overload. Bart __

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Jonas Maebe
On 25/02/18 15:59, Bart wrote: I don't know how Delphi behaves, but the official Delphi docs state that Abs() only has overloads for floats, integer and int64. If their compiler behaves as the docs say, Abs(Variant) would be a syntax error. No, because variant can be implicitly converted to all

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Bart
On Sun, Feb 25, 2018 at 3:40 PM, Michael Van Canneyt wrote: > Only if we add an > Abs(Variant) : Variant; which will then make the choice will this work. If the compiler accepts Abs(Variant), it should IMHO have a correct overload for this. (Maybe in the variants unit?) I don't know how Delph

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Michael Van Canneyt
On Sun, 25 Feb 2018, Bart wrote: On Sun, Feb 25, 2018 at 1:01 PM, Michael Van Canneyt wrote: The compiler does not know at compile time what type the variant is, how can you expect it to choose the "right" overloaded version ? I would have expected that it will choose the right one @runti

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Bart
On Sun, Feb 25, 2018 at 1:01 PM, Michael Van Canneyt wrote: > The compiler does not know at compile time what type the variant is, how can > you expect it to choose the "right" overloaded version ? I would have expected that it will choose the right one @runtime . Bart _

Re: [fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Michael Van Canneyt
On Sun, 25 Feb 2018, Bart wrote: Hi, See: http://forum.lazarus.freepascal.org/index.php/topic,40223.msg277657/ This seems rather unexpected. Not really. The abs() function is overloaded for different types. The compiler does not know at compile time what type the variant is, how can you

[fpc-devel] Abs(Variant) unexpected result

2018-02-25 Thread Bart
Hi, See: http://forum.lazarus.freepascal.org/index.php/topic,40223.msg277657/ This seems rather unexpected. Is it a bug? program v; {$ifdef windows} {$apptype console} {$endif} uses variants; var X: Variant; B: Boolean; begin X := -1.5; writeln('X = ',X); B := VarIsFloat(X); wr