Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adding test and fix for ^uint64(0) -> float #8

Merged
merged 7 commits into from
Sep 19, 2024
Merged

Conversation

ldemailly
Copy link
Member

@ldemailly ldemailly commented Sep 18, 2024

Also reduce API surface. removed Negative() and SameSign()

=== RUN   TestFloatBounds
    safecast_test.go:24: bits 64: 1111111111111111111111111111111111111111111111111111111111111111 : 18446744073709551615 -> float32 18446744073709551616 true
    safecast_test.go:24: bits 63: 111111111111111111111111111111111111111111111111111111111111111 : 9223372036854775807 -> float32 9223372036854775808 false
    safecast_test.go:24: bits 62: 11111111111111111111111111111111111111111111111111111111111111 : 4611686018427387903 -> float32 4611686018427387904 false
    safecast_test.go:24: bits 61: 1111111111111111111111111111111111111111111111111111111111111 : 2305843009213693951 -> float32 2305843009213693952 false
    safecast_test.go:24: bits 60: 111111111111111111111111111111111111111111111111111111111111 : 1152921504606846975 -> float32 1152921504606846976 false
    safecast_test.go:24: bits 59: 11111111111111111111111111111111111111111111111111111111111 : 576460752303423487 -> float32 576460752303423488 false
    safecast_test.go:24: bits 58: 1111111111111111111111111111111111111111111111111111111111 : 288230376151711743 -> float32 288230376151711744 false
    safecast_test.go:24: bits 57: 111111111111111111111111111111111111111111111111111111111 : 144115188075855871 -> float32 144115188075855872 false
    safecast_test.go:24: bits 56: 11111111111111111111111111111111111111111111111111111111 : 72057594037927935 -> float32 72057594037927936 false
    safecast_test.go:24: bits 55: 1111111111111111111111111111111111111111111111111111111 : 36028797018963967 -> float32 36028797018963968 false
    safecast_test.go:24: bits 54: 111111111111111111111111111111111111111111111111111111 : 18014398509481983 -> float32 18014398509481984 false
    safecast_test.go:24: bits 53: 11111111111111111111111111111111111111111111111111111 : 9007199254740991 -> float32 9007199254740992 false
    safecast_test.go:24: bits 52: 1111111111111111111111111111111111111111111111111111 : 4503599627370495 -> float32 4503599627370496 false
    safecast_test.go:24: bits 51: 111111111111111111111111111111111111111111111111111 : 2251799813685247 -> float32 2251799813685248 false
    safecast_test.go:24: bits 50: 11111111111111111111111111111111111111111111111111 : 1125899906842623 -> float32 1125899906842624 false
    safecast_test.go:24: bits 49: 1111111111111111111111111111111111111111111111111 : 562949953421311 -> float32 562949953421312 false
    safecast_test.go:24: bits 48: 111111111111111111111111111111111111111111111111 : 281474976710655 -> float32 281474976710656 false
    safecast_test.go:24: bits 47: 11111111111111111111111111111111111111111111111 : 140737488355327 -> float32 140737488355328 false
    safecast_test.go:24: bits 46: 1111111111111111111111111111111111111111111111 : 70368744177663 -> float32 70368744177664 false
    safecast_test.go:24: bits 45: 111111111111111111111111111111111111111111111 : 35184372088831 -> float32 35184372088832 false
    safecast_test.go:24: bits 44: 11111111111111111111111111111111111111111111 : 17592186044415 -> float32 17592186044416 false
    safecast_test.go:24: bits 43: 1111111111111111111111111111111111111111111 : 8796093022207 -> float32 8796093022208 false
    safecast_test.go:24: bits 42: 111111111111111111111111111111111111111111 : 4398046511103 -> float32 4398046511104 false
    safecast_test.go:24: bits 41: 11111111111111111111111111111111111111111 : 2199023255551 -> float32 2199023255552 false
    safecast_test.go:24: bits 40: 1111111111111111111111111111111111111111 : 1099511627775 -> float32 1099511627776 false
    safecast_test.go:24: bits 39: 111111111111111111111111111111111111111 : 549755813887 -> float32 549755813888 false
    safecast_test.go:24: bits 38: 11111111111111111111111111111111111111 : 274877906943 -> float32 274877906944 false
    safecast_test.go:24: bits 37: 1111111111111111111111111111111111111 : 137438953471 -> float32 137438953472 false
    safecast_test.go:24: bits 36: 111111111111111111111111111111111111 : 68719476735 -> float32 68719476736 false
    safecast_test.go:24: bits 35: 11111111111111111111111111111111111 : 34359738367 -> float32 34359738368 false
    safecast_test.go:24: bits 34: 1111111111111111111111111111111111 : 17179869183 -> float32 17179869184 false
    safecast_test.go:24: bits 33: 111111111111111111111111111111111 : 8589934591 -> float32 8589934592 false
    safecast_test.go:24: bits 32: 11111111111111111111111111111111 : 4294967295 -> float32 4294967296 false
    safecast_test.go:24: bits 31: 1111111111111111111111111111111 : 2147483647 -> float32 2147483648 false
    safecast_test.go:24: bits 30: 111111111111111111111111111111 : 1073741823 -> float32 1073741824 false
    safecast_test.go:24: bits 29: 11111111111111111111111111111 : 536870911 -> float32 536870912 false
    safecast_test.go:24: bits 28: 1111111111111111111111111111 : 268435455 -> float32 268435456 false
    safecast_test.go:24: bits 27: 111111111111111111111111111 : 134217727 -> float32 134217728 false
    safecast_test.go:24: bits 26: 11111111111111111111111111 : 67108863 -> float32 67108864 false
    safecast_test.go:24: bits 25: 1111111111111111111111111 : 33554431 -> float32 33554432 false
    safecast_test.go:24: bits 24: 111111111111111111111111 : 16777215 -> float32 16777215 true
    safecast_test.go:34: float32: 24 bits
    safecast_test.go:24: bits 64: 1111111111111111111111111111111111111111111111111111111111111111 : 18446744073709551615 -> float64 18446744073709551616 true
    safecast_test.go:24: bits 63: 111111111111111111111111111111111111111111111111111111111111111 : 9223372036854775807 -> float64 9223372036854775808 false
    safecast_test.go:24: bits 62: 11111111111111111111111111111111111111111111111111111111111111 : 4611686018427387903 -> float64 4611686018427387904 false
    safecast_test.go:24: bits 61: 1111111111111111111111111111111111111111111111111111111111111 : 2305843009213693951 -> float64 2305843009213693952 false
    safecast_test.go:24: bits 60: 111111111111111111111111111111111111111111111111111111111111 : 1152921504606846975 -> float64 1152921504606846976 false
    safecast_test.go:24: bits 59: 11111111111111111111111111111111111111111111111111111111111 : 576460752303423487 -> float64 576460752303423488 false
    safecast_test.go:24: bits 58: 1111111111111111111111111111111111111111111111111111111111 : 288230376151711743 -> float64 288230376151711744 false
    safecast_test.go:24: bits 57: 111111111111111111111111111111111111111111111111111111111 : 144115188075855871 -> float64 144115188075855872 false
    safecast_test.go:24: bits 56: 11111111111111111111111111111111111111111111111111111111 : 72057594037927935 -> float64 72057594037927936 false
    safecast_test.go:24: bits 55: 1111111111111111111111111111111111111111111111111111111 : 36028797018963967 -> float64 36028797018963968 false
    safecast_test.go:24: bits 54: 111111111111111111111111111111111111111111111111111111 : 18014398509481983 -> float64 18014398509481984 false
    safecast_test.go:24: bits 53: 11111111111111111111111111111111111111111111111111111 : 9007199254740991 -> float64 9007199254740991 true
    safecast_test.go:36: float64: 53 bits
    safecast_test.go:46: minInt64p1 -111111111111111111111111111111111111111111111111111111111111111 -9223372036854775807
    safecast_test.go:50: minInt64p1 -> -9223372036854775808 -9223372036854775808
--- PASS: TestFloatBounds (0.00s)

Copy link

codecov bot commented Sep 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (6f51d68) to head (4d8752c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #8   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           33        33           
=========================================
  Hits            33        33           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ldemailly ldemailly changed the title Adding failing test for ^uint64(0) -> float (should fail, by some definition) Adding test and fix for ^uint64(0) -> float Sep 19, 2024
@ldemailly ldemailly marked this pull request as ready for review September 19, 2024 00:11
@ldemailly
Copy link
Member Author

@ccoVeille are you aware of any bug with this minimal/generic version? if so I'd love to know. If not I might make this 1.0.0

Thanks!

@ccoVeille
Copy link

@ccoVeille are you aware of any bug with this minimal/generic version? if so I'd love to know. If not I might make this 1.0.0

I talked about on Slack, but for anyone interested

https://go.dev/play/p/wscNTE997We

@ldemailly
Copy link
Member Author

ldemailly commented Sep 19, 2024

yes that's not a bug that's indeed loosing .1 of 1.1 thus an error. if it's ok to truncate or round that's why we have Truncate and Round, but Convert alone shouldn't silently remove precision (and that's exactly what the new test verifies)

@ldemailly ldemailly merged commit c7f9f39 into main Sep 19, 2024
8 checks passed
@ldemailly ldemailly deleted the float_boundaries branch September 19, 2024 14:42
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants