Browse Source

Fix typo in `decimal_to_float_bits`

gingerBill 2 years ago
parent
commit
ea9fe397e5
2 changed files with 5 additions and 6 deletions
  1. 4 4
      core/strconv/generic_float.odin
  2. 1 2
      core/strconv/strconv.odin

+ 4 - 4
core/strconv/generic_float.odin

@@ -287,13 +287,13 @@ round_shortest :: proc(d: ^decimal.Decimal, mant: u64, exp: int, flt: ^Float_Inf
 
 
 @(private)
 @(private)
 decimal_to_float_bits :: proc(d: ^decimal.Decimal, info: ^Float_Info) -> (b: u64, overflow: bool) {
 decimal_to_float_bits :: proc(d: ^decimal.Decimal, info: ^Float_Info) -> (b: u64, overflow: bool) {
-	end :: proc "contextless" (d: ^decimal.Decimal, mant: u64, exp: int, info: ^Float_Info) -> (b: u64) {
-		bits := mant & (u64(1)<<info.mantbits - 1)
+	end :: proc "contextless" (d: ^decimal.Decimal, mant: u64, exp: int, info: ^Float_Info) -> (bits: u64) {
+		bits = mant & (u64(1)<<info.mantbits - 1)
 		bits |= u64((exp-info.bias) & (1<<info.expbits - 1)) << info.mantbits
 		bits |= u64((exp-info.bias) & (1<<info.expbits - 1)) << info.mantbits
 		if d.neg {
 		if d.neg {
 			bits |= 1<< info.mantbits << info.expbits
 			bits |= 1<< info.mantbits << info.expbits
 		}
 		}
-		return bits
+		return
 	}
 	}
 	set_overflow :: proc "contextless" (mant: ^u64, exp: ^int, info: ^Float_Info) -> bool {
 	set_overflow :: proc "contextless" (mant: ^u64, exp: ^int, info: ^Float_Info) -> bool {
 		mant^ = 0
 		mant^ = 0
@@ -303,7 +303,7 @@ decimal_to_float_bits :: proc(d: ^decimal.Decimal, info: ^Float_Info) -> (b: u64
 
 
 	mant: u64
 	mant: u64
 	exp: int
 	exp: int
-	if d.decimal_point == 0 {
+	if d.count == 0 {
 		mant = 0
 		mant = 0
 		exp = info.bias
 		exp = info.bias
 		b = end(d, mant, exp, info)
 		b = end(d, mant, exp, info)

+ 1 - 2
core/strconv/strconv.odin

@@ -819,7 +819,7 @@ parse_f64 :: proc(str: string, n: ^int = nil) -> (value: f64, ok: bool) {
 		}
 		}
 
 
 		if mantissa>>_f64_info.mantbits != 0 {
 		if mantissa>>_f64_info.mantbits != 0 {
-			return
+			break trunc_block
 		}
 		}
 		f := f64(mantissa)
 		f := f64(mantissa)
 		if neg {
 		if neg {
@@ -841,7 +841,6 @@ parse_f64 :: proc(str: string, n: ^int = nil) -> (value: f64, ok: bool) {
 			return f / pow10[-exp], true
 			return f / pow10[-exp], true
 		}
 		}
 	}
 	}
-
 	d: decimal.Decimal
 	d: decimal.Decimal
 	decimal.set(&d, str[:nr])
 	decimal.set(&d, str[:nr])
 	b, overflow := decimal_to_float_bits(&d, &_f64_info)
 	b, overflow := decimal_to_float_bits(&d, &_f64_info)