Difference between revisions of "Type Coercion"

From MiniScript Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by one other user not shown)
Line 3: Line 3:
 
Known type coercion rules:
 
Known type coercion rules:
  
<c>null * 3 == #@!$</c>
+
* <c>null * 3 == #@!$</c> &mdash; Any statement that begins with `null` is a compiler error, but this may change in the future.
Any statement that begins with `null` is a compiler error, but this may change in the future.
+
<c>(null)</c> is okay though.
`(null)` is okay though.
 
  
<c>3 * null == 0</c>
+
* <c>3 * null == 0</c> &mdash; Multiplying by null yields <c>0</c>.
Multiplying by null yields 0.
 
  
<c>3 / null == Infinity</c>
+
* <c>3 / null == Infinity</c> &mdash; In division, null acts a lot like <c>0</c>.
In division, null acts a lot like `0`.
 
  
<c>3 + "3" == "33"</c>
+
* <c>3 + "3" == "33"</c> &mdash; If an expression contains a string, the entire expression will be coerced into a string.
If an expression contains a string, the entire expression will be coerced into a string.
 
  
<c>"3" * 5 == "33333</c>
+
* <c>"3" * 5 == "33333"</c> &mdash; Multiplying a string by a number will replicate the string.
Multiplying a string by a number will replicate the string.
 
  
<c>"1234" / 2 == "12"</c>
+
* <c>"1234" / 2 == "12"</c> &mdash; Dividing a string by a number will divide the length, then take a substring.
Dividing a string by a number will divide the length, then take a substring.
 
  
<c>1/0 == "INF" | "Infinity"</c>
+
* <c>1/0 == "INF" | "Infinity"</c> &mdash; All numerical math is done according to standard IEEE floating-point rules, including well-defined behavior for Inf and NaN.  However, conversion of Inf and NaN to a string is undefined (implementation-dependent).
All numerical math is done according to standard IEEE floating-point rules, including well-defined behavior for Inf and NaN.  However, conversion of Inf and NaN to a string is undefined (implementation-dependent).
 

Latest revision as of 04:54, 21 February 2024

WIP

Known type coercion rules:

  • null * 3 == #@!$ — Any statement that begins with `null` is a compiler error, but this may change in the future.

(null) is okay though.

  • 3 * null == 0 — Multiplying by null yields 0.
  • 3 / null == Infinity — In division, null acts a lot like 0.
  • 3 + "3" == "33" — If an expression contains a string, the entire expression will be coerced into a string.
  • "3" * 5 == "33333" — Multiplying a string by a number will replicate the string.
  • "1234" / 2 == "12" — Dividing a string by a number will divide the length, then take a substring.
  • 1/0 == "INF" | "Infinity" — All numerical math is done according to standard IEEE floating-point rules, including well-defined behavior for Inf and NaN. However, conversion of Inf and NaN to a string is undefined (implementation-dependent).