| 4065 | } |
| 4066 | |
| 4067 | bool HloParserImpl::ParseDouble(double* result) { |
| 4068 | switch (lexer_.GetKind()) { |
| 4069 | case TokKind::kDecimal: { |
| 4070 | double val = lexer_.GetDecimalVal(); |
| 4071 | // If GetDecimalVal returns +/-inf, that means that we overflowed |
| 4072 | // `double`. |
| 4073 | if (std::isinf(val)) { |
| 4074 | return TokenError(StrCat("Constant is out of range for double (+/-", |
| 4075 | std::numeric_limits<double>::max(), |
| 4076 | ") and so is unparsable.")); |
| 4077 | } |
| 4078 | *result = val; |
| 4079 | break; |
| 4080 | } |
| 4081 | case TokKind::kInt: |
| 4082 | *result = static_cast<double>(lexer_.GetInt64Val()); |
| 4083 | break; |
| 4084 | case TokKind::kw_nan: |
| 4085 | *result = std::numeric_limits<double>::quiet_NaN(); |
| 4086 | break; |
| 4087 | case TokKind::kw_inf: |
| 4088 | *result = std::numeric_limits<double>::infinity(); |
| 4089 | break; |
| 4090 | case TokKind::kNegInf: |
| 4091 | *result = -std::numeric_limits<double>::infinity(); |
| 4092 | break; |
| 4093 | default: |
| 4094 | return TokenError("expects decimal or integer"); |
| 4095 | } |
| 4096 | lexer_.Lex(); |
| 4097 | return true; |
| 4098 | } |
| 4099 | |
| 4100 | bool HloParserImpl::ParseComplex(std::complex<double>* result) { |
| 4101 | if (lexer_.GetKind() != TokKind::kLparen) { |
nothing calls this directly
no test coverage detected