mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-05 14:51:37 +01:00
150 lines
4.9 KiB
XML
150 lines
4.9 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 1.1 Maintainer: thomasgm Status: ready -->
|
|
<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>Nome do atributo</entry>
|
|
<entry>Tipo</entry>
|
|
<entry>Obrigatório</entry>
|
|
<entry>Padrão</entry>
|
|
<entry>Descrição</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>equation</entry>
|
|
<entry>string</entry>
|
|
<entry>Sim</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>a equação à ser executar</entry>
|
|
</row>
|
|
<row>
|
|
<entry>format</entry>
|
|
<entry>string</entry>
|
|
<entry>Não</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>o formato do resultado (sprintf)</entry>
|
|
</row>
|
|
<row>
|
|
<entry>var</entry>
|
|
<entry>numérico</entry>
|
|
<entry>Sim</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>valor da variável da equação</entry>
|
|
</row>
|
|
<row>
|
|
<entry>assign</entry>
|
|
<entry>string</entry>
|
|
<entry>Não</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>variável de template cuja saída será atribuida</entry>
|
|
</row>
|
|
<row>
|
|
<entry>[var ...]</entry>
|
|
<entry>numérica</entry>
|
|
<entry>Sim</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>valor da variável da equação</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
<para>
|
|
math permite o desenhista de template fazer equações matemáticas no template.
|
|
Qualquer variável de template numérica pode ser usada nas equações, e o resultado
|
|
é exibido no lugar da tag. As variáveis usadas na equação são passadas como parâmetros,
|
|
que podem ser variáveis de template
|
|
ou valores estáticos. +, -, /, *, abs, ceil, cos,
|
|
exp, floor, log, log10, max, min, pi, pow, rand, round, sin, sqrt,
|
|
srans and tan são todos os operadores válidos. Verifique a documentação do PHP para
|
|
mais informações acerca destas funções matemáticas.
|
|
</para>
|
|
<para>
|
|
Se você fornece o atributo especial "assign", a saída da função matemática será
|
|
atribuído para esta variável
|
|
de template ao invés de ser exibida para o template.
|
|
</para>
|
|
<note>
|
|
<title>Nota Técnica</title>
|
|
<para>
|
|
math é uma função de performance cara devido ao uso da função do php eval().
|
|
Fazendo a matemática no PHP é muito mais eficiente, então sempre é possível fazer
|
|
os cálculos matemáticos no PHP e lançar os resultados para o template. Definitivamente
|
|
evite chamadas de funções de
|
|
matemáticas repetitivamente, como dentro de loops de section.
|
|
</para>
|
|
</note>
|
|
<example>
|
|
<title>math</title>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{* $height=4, $width=5 *}
|
|
|
|
{math equation="x + y" x=$height y=$width}
|
|
|
|
MOSTRA:
|
|
|
|
9
|
|
|
|
|
|
{* $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#}
|
|
|
|
MOSTRA:
|
|
|
|
100
|
|
|
|
|
|
{* Você pode usar parenteses *}
|
|
|
|
{math equation="(( x + y ) / z )" x=2 y=10 z=2}
|
|
|
|
MOSTRA:
|
|
|
|
6
|
|
|
|
|
|
{* você pode fornecer um parâmetro de formato em sprintf *}
|
|
|
|
{math equation="x + y" x=4.4444 y=5.0000 format="%.2f"}
|
|
|
|
MOSTRA:
|
|
|
|
9.44
|
|
]]>
|
|
</programlisting>
|
|
</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
|
|
--> |