diff --git a/vlib/strconv/atof_test.v b/vlib/strconv/atof_test.v index 1ad399c595..6bcc8eee20 100644 --- a/vlib/strconv/atof_test.v +++ b/vlib/strconv/atof_test.v @@ -3,7 +3,11 @@ * String to float Test * **********************************************************************/ -import strconv + +import ( + strconv + strconv.atofq +) fn test_atof() { // @@ -12,11 +16,11 @@ fn test_atof() { // float64 src_num := [ - f64(0.3), - -0.3, - 0.004, - -0.004, - 0.0, + f64(0.3), + -0.3, + 0.004, + -0.004, + 0.0, -0.0, 31234567890123 ] @@ -36,9 +40,9 @@ fn test_atof() { for c,x in src_num { // slow atof assert strconv.atof64(src_num_str[c]).strlong() == x.strlong() - + // quick atof - mut s1 := (strconv.atof_quick(src_num_str[c]).str()) + mut s1 := (atofq.atof_quick(src_num_str[c]).str()) s1 = s1[..src_num_str[c].len] mut s2 := (x.str()) s2 = s2[..src_num_str[c].len] @@ -67,5 +71,4 @@ fn test_atof() { // DOUBLE_MINUS_ZERO f1=-0.0 assert *ptr == u64(0x8000000000000000) - -} \ No newline at end of file +} diff --git a/vlib/strconv/atofq/atofq.v b/vlib/strconv/atofq/atofq.v index dfe925359e..f19b3ea5e5 100644 --- a/vlib/strconv/atofq/atofq.v +++ b/vlib/strconv/atofq/atofq.v @@ -15,7 +15,11 @@ * * **********************************************************************/ -module strconv + +module atofq + +import strconv + // same used in atof, here only for references // const( // DOUBLE_PLUS_ZERO = u64(0x0000000000000000) @@ -45,10 +49,10 @@ pub fn atof_quick(s string) f64 { if s[i] == `i` && i + 2 < s.len && s[i + 1] == `n` && s[i + 2] == `f` { mut d := *u64(&f) if sign > 0.0 { - *d = DOUBLE_PLUS_INFINITY + *d = strconv.DOUBLE_PLUS_INFINITY } else { - *d = DOUBLE_MINUS_INFINITY + *d = strconv.DOUBLE_MINUS_INFINITY } return f } @@ -59,10 +63,10 @@ pub fn atof_quick(s string) f64 { if i >= s.len { mut d := *u64(&f) if sign > 0.0 { - *d = DOUBLE_PLUS_ZERO + *d = strconv.DOUBLE_PLUS_ZERO } else { - *d = DOUBLE_MINUS_ZERO + *d = strconv.DOUBLE_MINUS_ZERO } return f } @@ -111,10 +115,10 @@ pub fn atof_quick(s string) f64 { if exp > pos_exp.len { mut d := *u64(&f) if sign > 0 { - *d = DOUBLE_PLUS_INFINITY + *d = strconv.DOUBLE_PLUS_INFINITY } else { - *d = DOUBLE_MINUS_INFINITY + *d = strconv.DOUBLE_MINUS_INFINITY } return f } @@ -128,10 +132,10 @@ pub fn atof_quick(s string) f64 { if exp > neg_exp.len { mut d := *u64(&f) if (sign > 0) { - *d = DOUBLE_PLUS_ZERO + *d = strconv.DOUBLE_PLUS_ZERO } else { - *d = DOUBLE_MINUS_ZERO + *d = strconv.DOUBLE_MINUS_ZERO } return f } @@ -152,4 +156,3 @@ const ( // negative exp of 10 binary form neg_exp = [0x3ff0000000000000, 0x3fb999999999999a, 0x3f847ae147ae147b, 0x3f50624dd2f1a9fc, 0x3f1a36e2eb1c432d, 0x3ee4f8b588e368f1, 0x3eb0c6f7a0b5ed8d, 0x3e7ad7f29abcaf48, 0x3e45798ee2308c3a, 0x3e112e0be826d695, 0x3ddb7cdfd9d7bdbb, 0x3da5fd7fe1796495, 0x3d719799812dea11, 0x3d3c25c268497682, 0x3d06849b86a12b9b, 0x3cd203af9ee75616, 0x3c9cd2b297d889bc, 0x3c670ef54646d497, 0x3c32725dd1d243ac, 0x3bfd83c94fb6d2ac, 0x3bc79ca10c924223, 0x3b92e3b40a0e9b4f, 0x3b5e392010175ee6, 0x3b282db34012b251, 0x3af357c299a88ea7, 0x3abef2d0f5da7dd9, 0x3a88c240c4aecb14, 0x3a53ce9a36f23c10, 0x3a1fb0f6be506019, 0x39e95a5efea6b347, 0x39b4484bfeebc2a0, 0x398039d665896880, 0x3949f623d5a8a733, 0x3914c4e977ba1f5c, 0x38e09d8792fb4c49, 0x38aa95a5b7f87a0f, 0x38754484932d2e72, 0x3841039d428a8b8f, 0x380b38fb9daa78e4, 0x37d5c72fb1552d83, 0x37a16c262777579c, 0x376be03d0bf225c7, 0x37364cfda3281e39, 0x3701d7314f534b61, 0x36cc8b8218854567, 0x3696d601ad376ab9, 0x366244ce242c5561, 0x362d3ae36d13bbce, 0x35f7624f8a762fd8, 0x35c2b50c6ec4f313, 0x358dee7a4ad4b81f, 0x3557f1fb6f10934c, 0x352327fc58da0f70, 0x34eea6608e29b24d, 0x34b8851a0b548ea4, 0x34839dae6f76d883, 0x344f62b0b257c0d2, 0x34191bc08eac9a41, 0x33e41633a556e1ce, 0x33b011c2eaabe7d8, 0x3379b604aaaca626, 0x3344919d5556eb52, 0x3310747ddddf22a8, 0x32da53fc9631d10d, 0x32a50ffd44f4a73d, 0x3270d9976a5d5297, 0x323af5bf109550f2, 0x32059165a6ddda5b, 0x31d1411e1f17e1e3, 0x319b9b6364f30304, 0x316615e91d8f359d, 0x3131ab20e472914a, 0x30fc45016d841baa, 0x30c69d9abe034955, 0x309217aefe690777, 0x305cf2b1970e7258, 0x3027288e1271f513, 0x2ff286d80ec190dc, 0x2fbda48ce468e7c7, 0x2f87b6d71d20b96c, 0x2f52f8ac174d6123, 0x2f1e5aacf2156838, 0x2ee8488a5b445360, 0x2eb36d3b7c36a91a, 0x2e7f152bf9f10e90, 0x2e48ddbcc7f40ba6, 0x2e13e497065cd61f, 0x2ddfd424d6faf031, 0x2da97683df2f268d, 0x2d745ecfe5bf520b, 0x2d404bd984990e6f, 0x2d0a12f5a0f4e3e5, 0x2cd4dbf7b3f71cb7, 0x2ca0aff95cc5b092, 0x2c6ab328946f80ea, 0x2c355c2076bf9a55, 0x2c0116805effaeaa, 0x2bcb5733cb32b111, 0x2b95df5ca28ef40d, 0x2b617f7d4ed8c33e, 0x2b2bff2ee48e0530, 0x2af665bf1d3e6a8d, 0x2ac1eaff4a98553d, 0x2a8cab3210f3bb95, 0x2a56ef5b40c2fc77, 0x2a225915cd68c9f9, 0x29ed5b561574765b, 0x29b77c44ddf6c516, 0x2982c9d0b1923745, 0x294e0fb44f50586e, 0x29180c903f7379f2, 0x28e33d4032c2c7f5, 0x28aec866b79e0cba, 0x2878a0522c7e7095, 0x2843b374f06526de, 0x280f8587e7083e30, 0x27d9379fec069826, 0x27a42c7ff0054685, 0x277023998cd10537, 0x2739d28f47b4d525, 0x2704a8729fc3ddb7, 0x26d086c219697e2c, 0x269a71368f0f3047, 0x2665275ed8d8f36c, 0x2630ec4be0ad8f89, 0x25fb13ac9aaf4c0f, 0x25c5a956e225d672, 0x2591544581b7dec2, 0x255bba08cf8c979d, 0x25262e6d72d6dfb0, 0x24f1bebdf578b2f4, 0x24bc6463225ab7ec, 0x2486b6b5b5155ff0, 0x24522bc490dde65a, 0x241d12d41afca3c3, 0x23e7424348ca1c9c, 0x23b29b69070816e3, 0x237dc574d80cf16b, 0x2347d12a4670c123, 0x23130dbb6b8d674f, 0x22de7c5f127bd87e, 0x22a8637f41fcad32, 0x227382cc34ca2428, 0x223f37ad21436d0c, 0x2208f9574dcf8a70, 0x21d3faac3e3fa1f3, 0x219ff779fd329cb9, 0x216992c7fdc216fa, 0x2134756ccb01abfb, 0x21005df0a267bcc9, 0x20ca2fe76a3f9475, 0x2094f31f8832dd2a, 0x2060c27fa028b0ef, 0x202ad0cc33744e4b, 0x1ff573d68f903ea2, 0x1fc1297872d9cbb5, 0x1f8b758d848fac55, 0x1f55f7a46a0c89dd, 0x1f2192e9ee706e4b, 0x1eec1e43171a4a11, 0x1eb67e9c127b6e74, 0x1e81fee341fc585d, 0x1e4ccb0536608d61, 0x1e1708d0f84d3de7, 0x1de26d73f9d764b9, 0x1dad7becc2f23ac2, 0x1d779657025b6235, 0x1d42deac01e2b4f7, 0x1d0e3113363787f2, 0x1cd8274291c6065b, 0x1ca3529ba7d19eaf, 0x1c6eea92a61c3118, 0x1c38bba884e35a7a, 0x1c03c9539d82aec8, 0x1bcfa885c8d117a6, 0x1b99539e3a40dfb8, 0x1b6442e4fb671960, 0x1b303583fc527ab3, 0x1af9ef3993b72ab8, 0x1ac4bf6142f8eefa, 0x1a90991a9bfa58c8, 0x1a5a8e90f9908e0d, 0x1a253eda614071a4, 0x19f0ff151a99f483, 0x19bb31bb5dc320d2, 0x1985c162b168e70e, 0x1951678227871f3e, 0x191bd8d03f3e9864, 0x18e6470cff6546b6, 0x18b1d270cc51055f, 0x187c83e7ad4e6efe, 0x1846cfec8aa52598, 0x18123ff06eea847a, 0x17dd331a4b10d3f6, 0x17a75c1508da432b, 0x1772b010d3e1cf56, 0x173de6815302e556, 0x1707eb9aa8cf1dde, 0x16d322e220a5b17e, 0x169e9e369aa2b597, 0x16687e92154ef7ac, 0x16339874ddd8c623, 0x15ff5a549627a36c, 0x15c91510781fb5f0, 0x159410d9f9b2f7f3, 0x15600d7b2e28c65c, 0x1529af2b7d0e0a2d, 0x14f48c22ca71a1bd, 0x14c0701bd527b498, 0x148a4cf9550c5426, 0x14550a6110d6a9b8, 0x1420d51a73deee2d, 0x13eaee90b964b047, 0x13b58ba6fab6f36c, 0x13813c85955f2923, 0x134b9408eefea839, 0x1316100725988694, 0x12e1a66c1e139edd, 0x12ac3d79c9b8fe2e, 0x12769794a160cb58, 0x124212dd4de70913, 0x120ceafbafd80e85, 0x11d72262f3133ed1, 0x11a281e8c275cbda, 0x116d9ca79d89462a, 0x1137b08617a104ee, 0x1102f39e794d9d8b, 0x10ce5297287c2f45, 0x1098421286c9bf6b, 0x1063680ed23aff89, 0x102f0ce4839198db, 0x0ff8d71d360e13e2, 0x0fc3df4a91a4dcb5, 0x0f8fcbaa82a16121, 0x0f596fbb9bb44db4, 0x0f245962e2f6a490, 0x0ef047824f2bb6da, 0x0eba0c03b1df8af6, 0x0e84d6695b193bf8, 0x0e50ab877c142ffa, 0x0e1aac0bf9b9e65c, 0x0de5566ffafb1eb0, 0x0db111f32f2f4bc0, 0x0d7b4feb7eb212cd, 0x0d45d98932280f0a, 0x0d117ad428200c08, 0x0cdbf7b9d9cce00d, 0x0ca65fc7e170b33e, 0x0c71e6398126f5cb, 0x0c3ca38f350b22df, 0x0c06e93f5da2824c, 0x0bd25432b14ecea3, 0x0b9d53844ee47dd1, 0x0b677603725064a8, 0x0b32c4cf8ea6b6ec, 0x0afe07b27dd78b14, 0x0ac8062864ac6f43, 0x0a9338205089f29c, 0x0a5ec033b40fea93, 0x0a2899c2f6732210, 0x09f3ae3591f5b4d9, 0x09bf7d228322baf5, 0x098930e868e89591, 0x0954272053ed4474, 0x09201f4d0ff10390, 0x08e9cbae7fe805b3, 0x08b4a2f1ffecd15c, 0x0880825b3323dab0, 0x084a6a2b85062ab3, 0x081521bc6a6b555c, 0x07e0e7c9eebc444a, 0x07ab0c764ac6d3a9, 0x0775a391d56bdc87, 0x07414fa7ddefe3a0, 0x070bb2a62fe638ff, 0x06d62884f31e93ff, 0x06a1ba03f5b21000, 0x066c5cd322b67fff, 0x0636b0a8e891ffff, 0x060226ed86db3333, 0x05cd0b15a491eb84, 0x05973c115074bc6a, 0x05629674405d6388, 0x052dbd86cd6238d9, 0x04f7cad23de82d7b, 0x04c308a831868ac9, 0x048e74404f3daadb, 0x04585d003f6488af, 0x04237d99cc506d59, 0x03ef2f5c7a1a488e, 0x03b8f2b061aea072, 0x0383f559e7bee6c1, 0x034feef63f97d79c, 0x03198bf832dfdfb0, 0x02e46ff9c24cb2f3, 0x02b059949b708f29, 0x027a28edc580e50e, 0x0244ed8b04671da5, 0x0210be08d0527e1d, 0x01dac9a7b3b7302f, 0x01a56e1fc2f8f359, 0x017124e63593f5e1, 0x013b6e3d22865634, 0x0105f1ca820511c3, 0x00d18e3b9b374169, 0x009c16c5c5253575, 0x0066789e3750f791, 0x0031fa182c40c60d, 0x000730d67819e8d2, 0x0000b8157268fdaf, 0x000012688b70e62b, 0x000001d74124e3d1, 0x0000002f201d49fb, 0x00000004b6695433, 0x0000000078a42205, 0x000000000c1069cd, 0x000000000134d761, 0x00000000001ee257, 0x00000000000316a2, 0x0000000000004f10, 0x00000000000007e8, 0x00000000000000ca, 0x0000000000000014, 0x0000000000000002] ) -