Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
Why Ruby doesn’t provide a `Complexe#modulo` method?

Ruby defines Numeric#%, aka Numeric#modulo to provide the remaining of receiver divided by an other Numeric. However, as the code bellow show, Complex is the only derived type which doesn’t provide a method for it:

ObjectSpace.each_object(Class){p "#{_1}: #{_1.method_defined?(:%)}" if _1.ancestors.include?(Numeric) unless _1 == Numeric}
"Complex: false"
"Rational: true"
"Float: true"
"Integer: true"
"Date::Infinity: true"

Is there a mathematical reason to avoid providing a reminder of complex numbers? In all cases, is there a documented reason for this engineering design choice?

Provision of an implementation of this operator for Complex, highlighting possible pitfall avoided if any, would also be welcome but more marginal for the topic of this question.

Side note: this as nothing to do with the notion of complex modulus, aka norm, which is also absent from Ruby standard library.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Back in 2009, in Bug #1712, Matz says:

I don't think there's natural definition of modulo on complex numbers, so that we should undefine % method.

As a result, Complex doesn't have %, modulo, or divmod. (among others)

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda