MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / parse_i64

Function parse_i64

cranelift/codegen/src/ir/immediates.rs:163–182  ·  view source on GitHub ↗

Parse a 64-bit signed number.

(s: &str)

Source from the content-addressed store, hash-verified

161
162/// Parse a 64-bit signed number.
163fn parse_i64(s: &str) -> Result<i64, &'static str> {
164 let negative = s.starts_with('-');
165 let s2 = if negative || s.starts_with('+') {
166 &s[1..]
167 } else {
168 s
169 };
170
171 let mut value = parse_u64(s2)?;
172
173 // We support the range-and-a-half from -2^63 .. 2^64-1.
174 if negative {
175 value = value.wrapping_neg();
176 // Don't allow large negative values to wrap around and become positive.
177 if value as i64 > 0 {
178 return Err("Negative number too small");
179 }
180 }
181 Ok(value as i64)
182}
183
184impl FromStr for Imm64 {
185 type Err = &'static str;

Callers 1

from_strMethod · 0.85

Calls 3

parse_u64Function · 0.85
OkFunction · 0.85
wrapping_negMethod · 0.80

Tested by

no test coverage detected