forked from Mirrors/openclonk
Add int<->float conversion functions
parent
77b9c47cf8
commit
134f462080
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
|
||||
<!DOCTYPE funcs SYSTEM "../../../clonk.dtd">
|
||||
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
|
||||
<funcs>
|
||||
<func>
|
||||
<title>float<title>
|
||||
<category>Arithmetik</category>
|
||||
<version>4.10.0.0 OC</version>
|
||||
<syntax>
|
||||
<rtype>float</rtype>
|
||||
<params>
|
||||
<param><type>int</type><name>i</name><desc>Die Ganzzahl, die in eine Fließkommazahl konvertiert werden soll.</desc></param>
|
||||
</params>
|
||||
</syntax>
|
||||
<desc>Wandelt eine Ganzzahl in eine Fließkommazahl um. Ist der Wert von <em>i</em> nicht exakt darstellbar, wird der darstellbare Wert zurückgegeben, der die geringste Abweichung vom tatsächlichen Wert hat.</desc>
|
||||
<examples>
|
||||
<example>
|
||||
<code>float(2)</code>
|
||||
<text>Gibt die Zahl 2.0 zurück.</text>
|
||||
</example>
|
||||
</examples>
|
||||
</func>
|
||||
<related>
|
||||
<funclink>int</funclink>
|
||||
<funclink>C4Id</funclink>
|
||||
</related>
|
||||
<author>isilkor</author><date>2010-07-10</date>
|
||||
</funcs>
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
|
||||
<!DOCTYPE funcs SYSTEM "../../../clonk.dtd">
|
||||
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
|
||||
<funcs>
|
||||
<func>
|
||||
<title>int</title>
|
||||
<category>Arithmetik</category>
|
||||
<version>4.10.0.0 OC</version>
|
||||
<syntax>
|
||||
<rtype>int</rtype>
|
||||
<params>
|
||||
<param><type>float</type><name>f</name><desc>Die Fließkommazahl, die in eine Ganzzahl konvertiert werden soll.</desc></param>
|
||||
</params>
|
||||
</syntax>
|
||||
<desc>Wandelt eine Fließkommazahl in eine Ganzzahl um. Dabei wird zur nächsten Ganzzahl gerundet. Liegt ein Wert genau in der Mitte zwischen zwei ganzen Zahlen, wird zur geraden Zahl gerundet. Ist der Wert von <em>f</em> außerhalb des Wertebereichs einer vorzeichenbehafteten 32-bit-Ganzzahl, so ist der Rückgabewert <em>nil</em>.</desc>
|
||||
<examples>
|
||||
<example>
|
||||
<code>int(2.5)</code>
|
||||
<text>Gibt die Zahl 2 zurück.</text>
|
||||
</example>
|
||||
<example>
|
||||
<code>int(3.5)</code>
|
||||
<text>Gibt die Zahl 4 zurück.</text>
|
||||
</example>
|
||||
</examples>
|
||||
</func>
|
||||
<related>
|
||||
<funclink>float</funclink>
|
||||
<funclink>C4Id</funclink>
|
||||
</related>
|
||||
<author>isilkor</author><date>2010-07-10</date>
|
||||
</funcs>
|
|
@ -5883,6 +5883,18 @@ static bool FnSetMeshMaterial(C4AulObjectContext* ctx, C4String* Material, int i
|
|||
return true;
|
||||
}
|
||||
|
||||
static Nillable<int> FnInt(C4AulContext *ctx, C4Real f)
|
||||
{
|
||||
if (f < std::numeric_limits<int>::min() || f > std::numeric_limits<int>::max())
|
||||
return C4VNull;
|
||||
return f;
|
||||
}
|
||||
|
||||
static C4Real FnFloat(C4AulContext *ctx, int i)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
//=========================== C4Script Function Map ===================================
|
||||
|
||||
// defined function class
|
||||
|
@ -6395,6 +6407,8 @@ void InitFunctionMap(C4AulScriptEngine *pEngine)
|
|||
AddFunc(pEngine, "DoNoCollectDelay", FnDoNoCollectDelay);
|
||||
|
||||
AddFunc(pEngine, "Translate", FnTranslate);
|
||||
AddFunc(pEngine, "int", FnInt);
|
||||
AddFunc(pEngine, "float", FnFloat);
|
||||
}
|
||||
|
||||
C4ScriptConstDef C4ScriptConstMap[]=
|
||||
|
|
Loading…
Reference in New Issue