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

Thiago Glauco Sanchez thiagoglauco at ticursos.net
Mon May 31 16:15:47 PDT 2010


Cool, there is just what I need...

Valeu Bruno Buss.

Em 31/05/2010 18:09, Bruno Buss escreveu:
> Tem o Math::BigFloat[1] também.
>
> [1]http://search.cpan.org/~tels/Math-BigInt-1.89/lib/Math/BigFloat.pm 
> <http://search.cpan.org/%7Etels/Math-BigInt-1.89/lib/Math/BigFloat.pm>
>
> 2010/5/31 Alexei Znamensky <russoz em gmail.com <mailto:russoz em gmail.com>>
>
>     tente
>
>     POSIX::modf
>
>     2010/5/31 <thiagoglauco em ticursos.net
>     <mailto:thiagoglauco em 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 em pm.org <mailto:SaoPaulo-pm em pm.org>
>         http://mail.pm.org/mailman/listinfo/saopaulo-pm
>
>
>
>
>     -- 
>     Alexei Znamensky [russoz_gmail_com] [russoz.wordpress.com
>     <http://russoz.wordpress.com>] [www.flickr.com/photos/alexeiz
>     <http://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 em pm.org <mailto:SaoPaulo-pm em pm.org>
>     http://mail.pm.org/mailman/listinfo/saopaulo-pm
>
>
>
>
> -- 
> Bruno C. Buss
> http://brunobuss.wordpress.com/
> http://www.dcc.ufrj.br/~brunobuss/ <http://www.dcc.ufrj.br/%7Ebrunobuss/>
>
>
> _______________________________________________
> SaoPaulo-pm mailing list
> SaoPaulo-pm em pm.org
> http://mail.pm.org/mailman/listinfo/saopaulo-pm


-------------- Pr?xima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://mail.pm.org/pipermail/saopaulo-pm/attachments/20100531/d274836a/attachment.html>


More information about the SaoPaulo-pm mailing list