Revision history for ProPgDataConversion


Revision [21661]

Last edited on 2016-11-04 13:20:27 by fxm [Rewording of integer promotion]
Additions:
byte < ubyte < short < ushort < long < integer < ulong < uinteger < longint < ulongint
byte < ubyte < short < ushort < long < ulong < longint < integer < ulongint < uinteger
First, in accordance to the above ranking, all arguments smaller than Integer are converted to Integer.
Deletions:
byte < ubyte < short < ushort < others
and for the other types:
in 32bit:
long < integer < ulong < uinteger < longint < ulongint
in 64bit:
long < ulong < longint < integer < ulongint < uinteger
First, all arguments smaller than Integer are converted to Integer.


Revision [21656]

Edited on 2016-11-02 11:39:58 by fxm [Formatting]
Additions:
Then, if arguments have different size, the smaller argument is converted to match the bigger one. Next, if arguments have different signedness, the signed argument is converted to unsigned to match the other one.
Deletions:
Then, if arguments have different size, the smaller argument is converted to match the bigger one. If arguments have different signedness, the signed argument is converted to unsigned to match the other one.


Revision [21655]

Edited on 2016-11-02 04:38:29 by fxm [Formatting]
Additions:
First, all arguments smaller than Integer are converted to Integer.
Then, if arguments have different size, the smaller argument is converted to match the bigger one. If arguments have different signedness, the signed argument is converted to unsigned to match the other one.
Deletions:
All arguments smaller than Integer are converted to Integer.
Then if arguments have different size, the smaller argument is converted to match the bigger one. If arguments have different signedness, the signed argument is converted to unsigned to match the other one.


Revision [21654]

Edited on 2016-11-02 03:55:22 by fxm [Formatting]
Additions:
Deletions:


Revision [21653]

Edited on 2016-11-01 02:04:58 by fxm [Formatting]
Additions:
byte < ubyte < short < ushort < others
and for the other types:
in 32bit:
long < integer < ulong < uinteger < longint < ulongint
in 64bit:
long < ulong < longint < integer < ulongint < uinteger
the (U)Long types
the (U)Longint types
Deletions:
byte < ubyte < short < ushort < others
and for the other types:
long < integer < ulong < uinteger < longint < ulongint
long < ulong < longint < integer < ulongint < uinteger
in 32bit:
the (U)Long types
in 64bit:
the (U)Longint types


Revision [21650]

Edited on 2016-10-31 01:49:52 by fxm [Updating of paragraph 'Coercion of Numeric Data Types in Expressions']
Additions:


Revision [21615]

Edited on 2016-10-30 16:16:54 by fxm [Updating of paragraph 'Coercion of Numeric Data Types in Expressions']
Additions:
Finally, the (U)Integer types replace:
in 32bit:
the (U)Long types
in 64bit:
the (U)Longint types
Deletions:
Finally, the (U)Integer types replace the (U)Long types in 32bit, the (U)Integer types replace the (U)Longint types in 64bit.


Revision [21614]

Edited on 2016-10-30 11:05:59 by fxm [Updating of paragraph 'Coercion of Numeric Data Types in Expressions']
Additions:
Finally, the (U)Integer types replace the (U)Long types in 32bit, the (U)Integer types replace the (U)Longint types in 64bit.


Revision [21613]

Edited on 2016-10-30 05:04:07 by fxm [Updating of paragraph 'Coercion of Numeric Data Types in Expressions']
Additions:
==Coercion of Numeric Data Types in Expressions and Arguments==
For the integer types, the rule depends on the following ranking:
byte < ubyte < short < ushort < others
and for the other types:
in 32bit:
long < integer < ulong < uinteger < longint < ulongint
in 64bit:
long < ulong < longint < integer < ulongint < uinteger
All arguments smaller than Integer are converted to Integer.
Then if arguments have different size, the smaller argument is converted to match the bigger one. If arguments have different signedness, the signed argument is converted to unsigned to match the other one.
On the other hand, if one of the arguments is a Single or a Double, both arguments are converted and/or promoted to Double.
Deletions:
==Coercion of Numeric Data Types in Expressions==
When two different data types are used in a binary operation, like ##//+//## (Addition) or ##//=//## (Assignment), the smaller data type is automatically promoted to the larger data type regardless of the order in which the arguments are given.
Promotions are as follows:
- where both arguments are each one of byte, ubyte, short, ushort, or integer: the smaller sized argument is promoted to have the same size as the larger sized argument.
- where one of the arguments is longint or ulongint, and the other argument is of any integer type, the smaller sized argument is promoted to have the same size as the larger sized argument.
- where one of the arguments is a single or a double, both arguments are converted and/or promoted to double
All unsigned integer types are handling like signed integer types for the purpose of promotion, and the most significant bit is extended (sign extension).


Revision [21421]

Edited on 2016-04-28 03:58:26 by fxm [Updated rules for implicit conversions (UDT)]
Additions:
For a construction with implicit initialization, the compiler searches:
(a matched let operator is not searched by compiler on a construction with implicit initialization)
For an implicit assignment, including an implicit return from function by assigning (keyword 'Function ='), the compiler searches:
For an implicit return from function by exiting immediately (keyword 'Return'), the compiler searches:
- Secondly a matched let operator.
u1 = J '' implicit assignment by compiler using the defined "Let(Byval As Integer)" operator
Deletions:
For construction with implicit initialization, the compiler searches:
For implicit assignment, the compiler searches:
u1 = J
Print u1.I '' implicit assignment by compiler using the defined "Let(Byval As Integer)" operator


Revision [21415]

Edited on 2016-04-24 08:31:18 by fxm [Wording]
Additions:
For construction with implicit initialization, the compiler searches:
Dim As UDT u1 = UDT(J) '' construction with explicit initialization using the defined "Constructor(Byval As Integer)" operator
Dim As UDT u2 = J '' construction with implicit initialization by compiler using the defined "Constructor(Byval As Integer)" operator
Deletions:
For implicit copy-construction, the compiler searches:
Dim As UDT u1 = UDT(J) '' explicit copy-construction using the defined "Constructor(Byval As Integer)" operator
Dim As UDT u2 = J '' implicit copy-construction by compiler using the defined "Constructor(Byval As Integer)" operator


Revision [21405]

Edited on 2016-04-19 01:51:11 by fxm [Typo]
Additions:
==Conversions using User Data Type constructors and operators==
Deletions:
==Implicit conversions using User Data Type constructors and operators==


Revision [21398]

Edited on 2016-04-17 06:33:24 by fxm [Wording]
Additions:
A type conversion will occur implicitly when an expression or variable is assigned, passed as a parameter to a procedure, or returned as a result from a procedure. Conversions may also be explicit when using CAST or one of the built-in conversion functions (among standard functions).
For conversion between built-in types (among standard types like between numeric types as above or between string types), the compiler knows what to do without the need for instructions from user.
Deletions:
A type conversion will occur implicitly when an expression or variable is assigned, passed as a parameter to a procedure, or returned as a result from a procedure. Conversions may also be explicit when using CAST or one of the built-in conversion functions.
For conversion between built-in types (between numeric types as above or between string types), the compiler knows what to do without the need for instructions from user.


Revision [21397]

Edited on 2016-04-17 05:23:15 by fxm [Added link to User Defined Types]
Additions:
- [[CatPgUserDefTypes|User Defined Types]]


Revision [21396]

Edited on 2016-04-17 04:00:25 by fxm [Rewording]
Additions:
Transfer the data of a given type variable to a variable of another type requires conversion.
For conversion between built-in types (between numeric types as above or between string types), the compiler knows what to do without the need for instructions from user.
This is called the implicit internal conversion (or coercion).
When one of the two types is at least a UDT (User Defined Type), the user has to code some UDT procedures to define how do the conversion.
Then, the conversion execution can be explicit if the user specifies what UDT procedure must be used, or implicit if the user leaves the choice to compiler.
In the world of UDTs, conversions can be controlled by means of three member procedures:
- Single-argument constructor: allow conversion from a particular type to initialize an object.
- Assignment operator: allow conversion from a particular type on assignment.
- Type-cast operator: allow conversion to a particular type.
Deletions:
In the world of UDTs, implicit conversions can be controlled by means of three member procedures:
- Single-argument constructor: allow implicit conversion from a particular type to initialize an object.
- Assignment operator: allow implicit conversion from a particular type on assignment.
- Type-cast operator: allow implicit conversion to a particular type.


Revision [21377]

Edited on 2016-04-16 01:30:31 by fxm [Added example of explicit/implicit conversions using UDT constructor and two operators]
Additions:
==Implicit conversions using User Data Type constructors and operators==
{{fbdoc item="ex"}}
Very simple syntaxic example highlighting the conversion capabilities by using Cast operator (explicit and implicit), Constructor (explicit and implicit) and Let operator (implicit):
{{fbdoc item="filename" value="examples/manual/casting/opcast-ctor-oplet.bas"}}%%(freebasic)
Type UDT
Dim As Integer I
Declare Operator Cast () As Integer
Declare Constructor (Byval I0 As Integer)
Declare Operator Let (Byval I0 As Integer)
End Type
Operator UDT.Cast () As Integer
Return This.I
End Operator
Constructor UDT (Byval I0 As Integer)
This.I = I0
End Constructor
Operator UDT.Let (Byval I0 As Integer)
This.I = I0
End Operator
Dim As Integer J = 12
Dim As UDT u1 = UDT(J) '' explicit copy-construction using the defined "Constructor(Byval As Integer)" operator
Print u1.I
Dim As UDT u2 = J '' implicit copy-construction by compiler using the defined "Constructor(Byval As Integer)" operator
Print u2.I
Print
u1.I = 34
J = Cast(Integer, u1) '' explicit assignment using the defined "Cast() As Integer" operator
Print J
Dim As Integer K
K = u1 '' implicit assignment by compiler using the defined "Cast() As Integer" operator
Print K
Print
J = 56
u1 = J
Print u1.I '' implicit assignment by compiler using the defined "Let(Byval As Integer)" operator
Print
Sleep
%%
Deletions:
==Implicit conversions using User Data Type operators==


Revision [21376]

Edited on 2016-04-15 16:01:23 by fxm [Added introduction to implicit conversions using User Data Type operators]
Additions:
- Firstly a matched constructor.
Deletions:
- Firstly a matched copy-constructor.


Revision [21343]

Edited on 2016-04-15 01:18:58 by fxm [Added introduction to implicit conversions using User Data Type operators]
Additions:
==Implicit conversions using User Data Type operators==
In the world of UDTs, implicit conversions can be controlled by means of three member procedures:
- Single-argument constructor: allow implicit conversion from a particular type to initialize an object.
- Assignment operator: allow implicit conversion from a particular type on assignment.
- Type-cast operator: allow implicit conversion to a particular type.
For implicit copy-construction, the compiler searches:
- Firstly a matched copy-constructor.
- Then otherwise a matched cast operator.
For implicit assignment, the compiler searches:
- Firstly a matched let operator.
- Then otherwise a matched cast operator.
(a matched constructor is not searched by compiler on an implicit assignment)


Revision [21341]

Edited on 2016-04-14 16:59:41 by fxm [Formatting]
Additions:
==Coercion of Numeric Data Types in Expressions==
Deletions:
Coercion of Numeric Data Types in Expressions.


Revision [20633]

Edited on 2016-02-10 16:12:42 by DkLwikki [Update link format]
Additions:
- [[CatPgStdDataTypes|Standard Data Types]]
- [[TblVarTypes|Variable Types]]
- [[CatPgCasting|Casting and Conversion Functions]]
Deletions:
- [[CatPgStdDataTypes Standard Data Types]]
- [[TblVarTypes Variable Types]]
- [[CatPgCasting Casting and Conversion Functions]]


Revision [11942]

The oldest known version of this page was created on 2007-12-21 14:21:56 by ElSairon [Update link format]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode