Difference between revisions of "SHIP:Sail:ltod"

From Serious Documentation
Jump to: navigation, search
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
{{SailFuncTableStart|}}<onlyinclude>
 
{{SailFuncTableStart|}}<onlyinclude>
|{{SailFunc|ltod}}||{{DataType|Long}}||style="text-align:center;"|v5.1.0||Explicitly casts an {{DataType|Long}} to a {{DataType|Double}} {{v5}}</onlyinclude>
+
|{{SailFunc|ltod}}||{{DataType|Long}}||style="text-align:center;"|v5.1.0||Explicitly casts an {{DataType|Long}} to a {{DataType|Double}}</onlyinclude>
 
|}
 
|}
 
== See Also: ==
 
== See Also: ==

Revision as of 17:41, 13 October 2016

Function Returns Introduced Description
ltod Long v5.1.0 Explicitly casts an Long to a Double

See Also:

Prototype

Double ltod(Long n);

Parameters/Return Value

Parameter Data Type Description
n Long the number to cast
Return Double the floating point version of the supplied number

Detailed Description

The ltod() function explicitly casts the supplied Long to a Double. You may want to use this in mathematical expressions around items so that the expression evaluation is moved into the floating point domain. For example:

lngValue = 5/4*10;

will return 10 since the whole expression is evaluated at run-time in the Long domain, and 5/4 will be evaluated using integer math resulting in 1. However,

intValue = 5/ltod(4)*10;

will return 11 since the 5/4 will be evaluated using floating point math. Obviously, this is equivalent to:

lngValue = 5/4.0*10;

However,this methodology becomes more useful when a function that returns a Double is used:

lngValue = 5/itof(strlen(s))*10;

Examples

Example Result Notes
ltod(-5); -5.0
ltod(5); 5.0