ora icon indicating copy to clipboard operation
ora copied to clipboard

float64 question

Open vsdutka opened this issue 9 years ago • 1 comments

Code:

v0 := float64(0.123)
s := fmt.Sprintf("SELECT %v FROM DUAL", v0)
fmt.Println(s)
rset, err := ses.PrepAndQry(s)
if err != nil {
	fmt.Println("1 - ", err)
	return
}
for rset.Next() {
	v1 := rset.Row[0]
	fmt.Printf("v0 - %v (type - %T)\n", v0, v0)
	fmt.Printf("v1 - %v (type - %T)\n", v1, v1)
	fmt.Printf("v0 internal: %064s\n", strconv.FormatUint((*(*uint64)(unsafe.Pointer(&v0))), 2))
	fmt.Printf("v1 internal: %064s\n", strconv.FormatUint((*(*uint64)(unsafe.Pointer(&v1))), 2))
	fmt.Printf("v1 == v0: %v\n", v1 == v0)
}

Result:

SELECT 0.123 FROM DUAL
v0 - 0.123 (type - float64)
v1 - 0.12300000000000001 (type - float64)
v0 internal: 0011111110111111011111001110110110010001011010000111001010110000
v1 internal: 0000000000000000000000000000000000000000010110000011000110100000
v1 == v0: false

vsdutka avatar Apr 14 '17 10:04 vsdutka

That's what OCINumberToReal returns.

The strange is that ora._Ctype_struct_OCINumber{OCINumberPart:[22]ora._Ctype_ub1{0x3, 0xc0, 0xd, 0x1f, 0x0, 0x0, 0x0, 0x0, 0x50, 0xc1, 0x2d, 0x2, 0x0, 0x0, 0x0, 0x0, 0x92, 0x0, 0x0, 0x0, 0x18, 0x0}} = 0.12300000000000001 ora._Ctype_struct_OCINumber{OCINumberPart:[22]ora._Ctype_ub1{0xa, 0xc0, 0xd, 0x1f, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}} = 0.123

SELECT DUMP(0.123), DUMP(0.12300000000000001) FROM dual Typ=2 Len=3: 192,13,31 Typ=2 Len=10: 192,13,31,1,1,1,1,1,1,11

Just as if OCINumberToReal choose the other neighbouring float as Go does: https://play.golang.org/p/WfrLFtJ0pP

Maybe we have to resort to using Go's strconv.ParseFloat64 ?

vsdutka [email protected] ezt írta (időpont: 2017. ápr. 14., P, 12:06):

Code:

v0 := float64(0.123) s := fmt.Sprintf("SELECT %v FROM DUAL", v0) fmt.Println(s) rset, err := ses.PrepAndQry(s) if err != nil { fmt.Println("1 - ", err) return } for rset.Next() { v1 := rset.Row[0] fmt.Printf("v0 - %v (type - %T)\n", v0, v0) fmt.Printf("v1 - %v (type - %T)\n", v1, v1)

fmt.Printf("v0 internal: %064s\n", strconv.FormatUint((*(uint64)(unsafe.Pointer(&v0))), 2)) fmt.Printf("v1 internal: %064s\n", strconv.FormatUint(((*uint64)(unsafe.Pointer(&v1))), 2)) fmt.Printf("v1 == v0: %v\n", v1 == v0) }

Result:

SELECT 0.123 FROM DUAL v0 - 0.123 (type - float64) v1 - 0.12300000000000001 (type - float64) v0 internal: 0011111110111111011111001110110110010001011010000111001010110000 v1 internal: 0000000000000000000000000000000000000000010110000011000110100000 v1 == v0: false

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rana/ora/issues/186, or mute the thread https://github.com/notifications/unsubscribe-auth/AAPoSpzF0KeCE-nK37VxXQZPl_7fxCLsks5rv0U3gaJpZM4M9oNA .

tgulacsi avatar Apr 14 '17 13:04 tgulacsi