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

165
Visualizações
Switch statement with closed-ranges covering full Float range

I am expecting the code below to cover the full Float range of which I use only a very small part just above 0.

My app however sometimes crashes in the field because it hits default: fatalError().

What could possibly be wrong here?

var value: Float // Between a little above 0 and about 15.

...

switch value
{
case ...3: return 0
case 3...10: return 1
case 10...: return 2
default: fatalError()
}
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

This switch will fall all the way through default for example if value is Float.nan or Float.signalingNaN, so it's technically possible for the app to legitimately crash at that point.

Consider adding some logging before crashing to check which value causes it to crash.

over 4 years ago · Santiago Trujillo Relatório

0

You have covered all cases except for the values whose eight exponent bits are all 1s. None of these are "Between a little above 0 and about 15", so your assumption is currently incorrect.

https://en.wikipedia.org/wiki/Single-precision_floating-point_format#Exponent_encoding

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