[SP-pm] Alguém tem uma forma melhor de compara números reais ?

Bruno Buss bruno.buss at gmail.com
Mon May 31 14:09:59 PDT 2010


Tem o Math::BigFloat[1] também.

[1]http://search.cpan.org/~tels/Math-BigInt-1.89/lib/Math/BigFloat.pm

2010/5/31 Alexei Znamensky <russoz at gmail.com>

> tente
>
> POSIX::modf
>
> 2010/5/31 <thiagoglauco at ticursos.net>
>
>> Eu tenho o seguinte algoritmo para comparar números reais. Alguém tem uma
>>
>> forma melhor, menor, mais legível ou um módulo?
>>
>> # sao_iguais(NUM1, NUM2, PRECISAO) : Retorna "true" se os valores reais
>> forem #iguais dentro da precisão determinada.
>>
>> sub sao_iguais {
>> my ($num1, $num2, $precisao) = @_;
>> return sprintf("%.${precisao}f", $num1) eq sprintf("%.${precisao}f",
>> $num2);}
>> _______________________________________________
>> SaoPaulo-pm mailing list
>> SaoPaulo-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/saopaulo-pm
>>
>
>
>
> --
> Alexei Znamensky [russoz_gmail_com] [russoz.wordpress.com] [
> www.flickr.com/photos/alexeiz]
> "Though we live in trying times, we're the ones who have to try"
>
> _______________________________________________
> SaoPaulo-pm mailing list
> SaoPaulo-pm at pm.org
> http://mail.pm.org/mailman/listinfo/saopaulo-pm
>



-- 
Bruno C. Buss
http://brunobuss.wordpress.com/
http://www.dcc.ufrj.br/~brunobuss/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/saopaulo-pm/attachments/20100531/1196b515/attachment-0001.html>


More information about the SaoPaulo-pm mailing list