mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-09 16:51:47 +01:00
187 lines
5.7 KiB
XML
187 lines
5.7 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<sect1 id="language.function.math">
|
|
<title>math</title>
|
|
<informaltable frame="all">
|
|
<tgroup cols="5">
|
|
<colspec colname="param" align="center" />
|
|
<colspec colname="type" align="center" />
|
|
<colspec colname="required" align="center" />
|
|
<colspec colname="default" align="center" />
|
|
<colspec colname="desc" />
|
|
<thead>
|
|
<row>
|
|
<entry>Nombre del Atributo</entry>
|
|
<entry>Tipo</entry>
|
|
<entry>Requerido</entry>
|
|
<entry>Default</entry>
|
|
<entry>Descripción</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>equation</entry>
|
|
<entry>string</entry>
|
|
<entry>Si</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>La ecuación a ejecutar</entry>
|
|
</row>
|
|
<row>
|
|
<entry>format</entry>
|
|
<entry>string</entry>
|
|
<entry>No</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>El formato del resultado (sprintf)</entry>
|
|
</row>
|
|
<row>
|
|
<entry>var</entry>
|
|
<entry>numeric</entry>
|
|
<entry>Si</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Valor de la variable de la ecuación</entry>
|
|
</row>
|
|
<row>
|
|
<entry>assign</entry>
|
|
<entry>string</entry>
|
|
<entry>No</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Variable de template cuya salida sera asignada</entry>
|
|
</row>
|
|
<row>
|
|
<entry>[var ...]</entry>
|
|
<entry>numeric</entry>
|
|
<entry>Si</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Valor de la variable de la ecuación</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
<para>
|
|
{math} permite diseñar ecuaciones matemáticas dentro del template.
|
|
Cualquier variable numérica del template puede ser usada en
|
|
ecuaciones, y el resultado es mostrado en lugar de la etiqueta.
|
|
Las variables usadas en ecuaciones son pasadas como parámetros,
|
|
que pueden ser variables de template o valores estáticos.
|
|
+, -, /, *, abs, ceil, cos, exp, floor, log, log10, max, min,
|
|
pi, pow, rand, round, sin, sqrt, srans y tan son todos los
|
|
operadores validos. Verifique la documentación de PHP para mas
|
|
información acerca de estas funciones matemáticas.
|
|
</para>
|
|
<para>
|
|
Si usted proporciona el atributo especial "assign", la salida de la
|
|
función matemática será atribuido a esta variable de template en
|
|
vez de ser mostrada en el template.
|
|
</para>
|
|
<note>
|
|
<title>Nota Técnica</title>
|
|
<para>
|
|
{math} es una función de muy alto rendimiento debido a que se puede
|
|
usar con la función <ulink url="&url.php-manual;eval">eval()</ulink>
|
|
de PHP. Hacer las matemáticas en PHP es mucho mas eficiente, asi en
|
|
cualquier momento es posible hacer calculos matemáticos en PHP asignarlos
|
|
a una variable y lanzar los resultados al template. Defínitivamente evite
|
|
llamadas repetitivas de funciones matemáticas, dentro de los ciclos
|
|
<link linkend="language.function.section">{section}</link>.
|
|
</para>
|
|
</note>
|
|
<example>
|
|
<title>{math}</title>
|
|
<para>
|
|
<emphasis role="bold">Ejemplo a:</emphasis>
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{* $height=4, $width=5 *}
|
|
|
|
{math equation="x + y" x=$height y=$width}
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Salida del ejemplo de arriba:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
9
|
|
]]>
|
|
</screen>
|
|
<para>
|
|
<emphasis role="bold">Ejemplo b:</emphasis>
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{* $row_height = 10, $row_width = 20, #col_div# = 2, assigned in template *}
|
|
|
|
{math equation="height * width / division"
|
|
height=$row_height
|
|
width=$row_width
|
|
division=#col_div#}
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Salida del ejemplo de arriba:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
100
|
|
]]>
|
|
</screen>
|
|
<para>
|
|
<emphasis role="bold">Ejemplo c:</emphasis>
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{* you can use parenthesis *}
|
|
|
|
{math equation="(( x + y ) / z )" x=2 y=10 z=2}
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Salida del ejemplo de arriba:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
6
|
|
]]>
|
|
</screen>
|
|
<para>
|
|
<emphasis role="bold">Ejemplo d:</emphasis>
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{* you can supply a format parameter in sprintf format *}
|
|
|
|
{math equation="x + y" x=4.4444 y=5.0000 format="%.2f"}
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Salida del ejemplo de arriba:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
9.44
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</sect1>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|