Jump to content
Sign in to follow this  
Dartier

Função que inverte positivo e negativo

Recommended Posts

Dartier    0
Dartier

function invertNumber(n)

n = n-n*2

return n

end

 

Bom, essa função ela só inverte de negativo pra positivo e vice-versa por exemplo:

 

a = -100

print(invertNumber(a))

> 100

 

a = 100

print(invertNumber(a))

> -100

 

bem fácil. :coolface:

Share this post


Link to post
Share on other sites
Socket    0
Socket

Não seria melhor simplesmente multiplicar por -1?

 

Mas já tem, só fazer -n, a operação unária (__unm).

 

function inv(n) return -n end

Edited by Mickfern

Share this post


Link to post
Share on other sites
Roku    0
Roku

vei deboa com 10 anos eu aprendi na aula de matematica q multiplicando o numero por -1 se consegue seu simétrico. igual o socket falou

mas fico legal

Share this post


Link to post
Share on other sites
Mock    32
Mock

eu faria:

function q(n)

return n*-1

end

Share this post


Link to post
Share on other sites
Dartier    0
Dartier

uaheuae, nem sabia. mas eu consegui fazer isso na cagada eu fiz um calculo lá e acabo só invertendo dai resolvi faze uma função. :pirate:

Share this post


Link to post
Share on other sites
Conde2    0
Conde2

@Dartier

 

Se andou pulando algumas aulas de matemática (TODAS na verdade)

Sem querer tirar sarro mais eu ri disso dai.

 

Porém por outro lado você achou outro jeito de fazer isso =P

Eu faria assim:

 

 

 

function inverte(n)
if type(n) == "number" then
return n*-1
end
return false
end

 

HUDSAHUASDHUSADHAHUDASDHUAS

Edited by Mickfern

Share this post


Link to post
Share on other sites
Dartier    0
Dartier

seja mais pogger então

FLW

EHSUDHASEIOEASD

Share this post


Link to post
Share on other sites
pejuge2    1
pejuge2

Por favor Dartier, presta mais atenção na aula de matemática

uhahuauhauhauhauhauhauhahuauhauhauhauauhauhau

 

Eu faria assim:

 

function inv(v)
   return type(v) == 'number' and -v or false
end

Share this post


Link to post
Share on other sites
Gpwjhlkdcf    21
Gpwjhlkdcf

eu faria assim:

-valor

ja tem o operador, não tem necessidade de fazer uma função ._.

Share this post


Link to post
Share on other sites
Hauntedy    0
Hauntedy

Como diria o Mock:

gambiarra_escola.jpg

 

Nao sei porque, mas eu pensei igualzinho o Skyen.....

Share this post


Link to post
Share on other sites
Notorious    1
Notorious
function invertNumber(n)

n = n-n*2

return n

end

seja mais pogger então

FLW

EHSUDHASEIOEASD

Ele POGer, bem ele?

Aé? Então tá bom ...

Share this post


Link to post
Share on other sites
Sinister    0
Sinister

/\

aé, mostra um pog seu ai então fodao ;D

eu sei q vc sabe, rlx ;d

 

sobre o script, como todos ja falaram, era só multiplicar por -1 auhauau

Share this post


Link to post
Share on other sites
Gpwjhlkdcf    21
Gpwjhlkdcf
aé, mostra um pog seu ai então fodao ;D

Simplesmente por ele não mostrar um "POG" significa que ele é fodão...

Gambiarra é sinônimo de descuido e, em vários casos, burrice. Se o cara faz isso, ele não é fodão, e sim o contrário.

 

É incrível como vocês competem pra ver quem faz o pior código, e não o melhor...

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×