Difference between revisions of "SHIP:Data Types:Float"

From Serious Documentation
Jump to: navigation, search
(Created page with "*'''Node Home''' *'''All Data Types''' <onlyinclude>Float Data Types are available in SHIPv5 and onwards, and are single precision floating ...")
 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
== See Also ==
 
*'''[[SHIP:Node|Node Home]]'''
 
*'''[[SHIP:Node|Node Home]]'''
 
*'''[[SHIP:Data_Types|All Data Types]]'''
 
*'''[[SHIP:Data_Types|All Data Types]]'''
 
+
== {{DataType|Float}} ==
<onlyinclude>Float Data Types are available in SHIPv5 and onwards, and are single precision floating point values.
+
<onlyinclude>Float Data Types are available in [[SHIP_Version_5|SHIPv5]] and onwards, and are [http://en.wikipedia.org/wiki/Single_precision_floating-point_format single precision IEEE754] floating point values.
 
{{DataTypeTableStart|}}
 
{{DataTypeTableStart|}}
 
|{{DataType|Float}}||A [http://en.wikipedia.org/wiki/Single_precision_floating-point_format single precision IEEE754] 32-bit floating point value.
 
|{{DataType|Float}}||A [http://en.wikipedia.org/wiki/Single_precision_floating-point_format single precision IEEE754] 32-bit floating point value.
Line 11: Line 12:
 
Examples of {{DataType|Float}} constants:
 
Examples of {{DataType|Float}} constants:
 
* <code>1.0f</code> is 1.0
 
* <code>1.0f</code> is 1.0
</onlyinclude>* * <code>-2.324f</code> is -2.324</code>
+
</onlyinclude>* <code>-2.324f</code> is -2.324
 
+
* <code>.3f</code>  is invalid, since there are no digits in front of the decimal point; add a leading 0
<code>.3f</code>  is invalid, since there are no digits in front of the decimal point; add a leading 0
 
 
* <code>1f</code>  is invalid, since there is no decimal point nor trailing digits after the decimal point
 
* <code>1f</code>  is invalid, since there is no decimal point nor trailing digits after the decimal point
 
* <code>1.f</code>  is invalid, since there are no trailing digits after the decimal point
 
* <code>1.f</code>  is invalid, since there are no trailing digits after the decimal point
  
 +
== Casting Rules ==
  
 +
{| class="wikitable" style="width: 50%; margin: 1em auto 1em auto;"
 +
! width="15%" | From
 +
! width="15%" | To
 +
! width="70%" | Description
 +
|-
 +
|{{DataType|Float}}||{{DataType|Byte}}||fractional elements removed, fit within the {{DataType|Byte}} range
 +
|-
 +
|{{DataType|Float}}||{{DataType|Short}}||fractional elements removed, fit within the {{DataType|Short}} range
 +
|-
 +
|{{DataType|Float}}||{{DataType|Integer}}||fractional elements removed
 +
|-
 +
|{{DataType|Float}}||{{DataType|Boolean}}||a value of {{Reserved|false}} if exactly 0.0f, otherwise {{Reserved|true}}
 +
|-
 +
|{{DataType|Float}}||{{DataType|Byte}}||fractional elements removed, fit within the {{DataType|Byte}} range
 +
|-
 +
|{{DataType|Byte}}||{{DataType|Float}}||simple cast
 +
|-
 +
|{{DataType|Short}}||{{DataType|Float}}||simple cast
  
When {{DataType|Float}} values are assigned from other numeric data types (e.g. {{DataType|Byte}}, {{DataType|Short}}, {{DataType|Integer}}, {{DataType|Boolean}}), the cast is exact if the value is in range of the {{DataType|Float}} capabilities.
+
|-
 
+
|{{DataType|Integer}}||{{DataType|Float}}||simple cast, but limited to maximum and minimum {{DataType|Float}} range which is smaller than {{DataType|Integer}}
a zero value is cast to {{Reserved|false}}, and a non-zero value is cast to {{Reserved|true}}.
+
|-
 
+
|{{DataType|Boolean}}||{{DataType|Float}}||a value of 0.0f for {{Reserved|false}} and 1.0f for {{Reserved|true}}
Conversely, when a {{DataType|Boolean}} value is assigned to another numeric data type (e.g. {{DataType|Byte}}, {{DataType|Short}}, {{DataType|Integer}}, {{DataType|Float}}), a {{Reserved|false}} value is cast to zero, and a {{Reserved|true}} value is cast to 1 (or 1.0f).
+
|}

Latest revision as of 19:12, 14 October 2016

See Also

Float

Float Data Types are available in SHIPv5 and onwards, and are single precision IEEE754 floating point values.

Data Type Description
Float A single precision IEEE754 32-bit floating point value.

Float constants in SHIPTide must be written with a decimal point, at least one digit before and one digit after the decimal point, with a trailing "f".

Examples of Float constants:

  • 1.0f is 1.0
  • -2.324f is -2.324
  • .3f is invalid, since there are no digits in front of the decimal point; add a leading 0
  • 1f is invalid, since there is no decimal point nor trailing digits after the decimal point
  • 1.f is invalid, since there are no trailing digits after the decimal point

Casting Rules

From To Description
Float Byte fractional elements removed, fit within the Byte range
Float Short fractional elements removed, fit within the Short range
Float Integer fractional elements removed
Float Boolean a value of false if exactly 0.0f, otherwise true
Float Byte fractional elements removed, fit within the Byte range
Byte Float simple cast
Short Float simple cast
Integer Float simple cast, but limited to maximum and minimum Float range which is smaller than Integer
Boolean Float a value of 0.0f for false and 1.0f for true