1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v2: short struct init syntax; .xxx enum checks; unions; assert

This commit is contained in:
Alexander Medvednikov
2020-02-26 15:51:05 +01:00
parent c26016b132
commit 857cbfb0d2
10 changed files with 128 additions and 67 deletions

View File

@@ -1,6 +1,6 @@
/**********************************************************************
*
* f32 to string
* f32 to string
*
* Copyright (c) 2019-2020 Dario Deledda. All rights reserved.
* Use of this source code is governed by an MIT license
@@ -9,11 +9,11 @@
* This file contains the f32 to string functions
*
* These functions are based on the work of:
* Publication:PLDI 2018: Proceedings of the 39th ACM SIGPLAN
* Conference on Programming Language Design and ImplementationJune 2018
* Publication:PLDI 2018: Proceedings of the 39th ACM SIGPLAN
* Conference on Programming Language Design and ImplementationJune 2018
* Pages 270282 https://doi.org/10.1145/3192366.3192369
*
* inspired by the Go version here:
* inspired by the Go version here:
* https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea
*
**********************************************************************/
@@ -72,7 +72,7 @@ fn (d Dec32) get_string_32(neg bool, n_digit int) string {
mut x := 0
for x < (out_len-disp-1) {
buf[y - x] = `0` + byte(out%10)
out /= 10
out /= 10
i++
x++
}
@@ -170,7 +170,7 @@ pub fn f32_to_decimal(mant u32, exp u32) Dec32 {
mm_shift := bool_to_u32(mant != 0 || exp <= 1)
mm := u32(4 * m2 - 1 - mm_shift)
mut vr := u32(0)
mut vr := u32(0)
mut vp := u32(0)
mut vm := u32(0)
mut e10 := 0
@@ -291,7 +291,7 @@ pub fn f32_to_decimal(mant u32, exp u32) Dec32 {
out = vr + bool_to_u32(vr == vm || last_removed_digit >= 5)
}
return Dec32{m: out, e: e10 + removed}
return Dec32{m: out e: e10 + removed}
}
// f32_to_str return a string in scientific notation with max n_digit after the dot
@@ -316,7 +316,7 @@ pub fn f32_to_str(f f32, n_digit int) string {
//println("with exp form")
d = f32_to_decimal(mant, exp)
}
//println("${d.m} ${d.e}")
return d.get_string_32(neg, n_digit)
}

View File

@@ -28,7 +28,7 @@ powers_of_10 = [
// We only need to find the length of at most 17 digit numbers.
]
pow5_split_32 = [
pow5_split_32 = [
1152921504606846976, 1441151880758558720, 1801439850948198400, 2251799813685248000,
1407374883553280000, 1759218604441600000, 2199023255552000000, 1374389534720000000,
1717986918400000000, 2147483648000000000, 1342177280000000000, 1677721600000000000,
@@ -55,8 +55,8 @@ pow5_inv_split_32 = [
]
pow5_split_64 =[
Uint128{u64(0), 72057594037927936},
Uint128{u64(0), 90071992547409920},
Uint128{0, 72057594037927936},
Uint128{0, 90071992547409920},
Uint128{u64(0), 112589990684262400},
Uint128{u64(0), 140737488355328000},
Uint128{u64(0), 87960930222080000},
@@ -677,4 +677,4 @@ pow5_inv_split_64 = [
Uint128{8599192303405213841, 224711641857789488},
Uint128{14258051472207991719, 179769313486231590}
]
)
)