Skip to content

Commit fb8d4dc

Browse files
committed
Improve readme
1 parent 0e6fb1f commit fb8d4dc

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,15 @@ There's a good case to be made that a panic is an unidiomatic but proper respons
115115

116116
### Performance considerations
117117

118-
Compared with the integer type safety libraries of other languages (such as C++), this library uses some seemingly slow operations, such as division. But this does not mean that these methods will be slow, on the contrary, it will be faster than complex implementations in other languages. The reason is that Go does not allow forced inlining, and any complex functions will be abandoned for inlining, resulting in additional calling overhead. Short functions are lightning fast due to automatic inlining. For example, for unsigned 64-bit integer multiplication overflow detection, when inlining is disabled, division takes five times as long as long multiplication, but after automatic inlining is allowed, division takes 1/5 of long multiplication.
118+
Compared to integer safe libraries in other languages (e.g. C++), this library uses some seemingly slow operations, such as division. But that doesn't mean these methods will be slow. In fact, because of Go's automatic inlining strategy for short functions and compiler optimizations, these operations are actually very fast in benchmark tests, lightning fast.
119+
120+
In addition, Go defines the overflow behavior of signed integers, making the detection of signed integer overflow simple and efficient.
119121

120122
Note that using `//go:noinline` in your business function will not affect the inlining of the library function. Only disabling global inlining through `-gcflags="-l"` will affect the inlining of this library function.
121123

122124
### Basis and dependencies
123125

124-
This library is based on Go's official compiler implementation and language specification, which defines the behavior when integer overflow occurs.
126+
The library is developed based on Go's official compiler implementation (gc) and language specifications.
125127

126128
### License
127129

README.zh_CN.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func main() {
102102
fmt.Println(overflow.Abs64(k2))
103103
}
104104
```
105-
yields the output
105+
输出
106106
```go
107107
9007199254740992 // Mantissa overflow, precision lost
108108
9007199254740993
@@ -120,13 +120,15 @@ yields the output
120120

121121
### 性能考虑
122122

123-
与其他语言(例如C++)的整数类型安全库相比,该库使用了一些看似缓慢的操作,例如除法。 但这并不意味着这些方法会很慢,相反,它会比其他语言中的复杂实现更快。 原因是Go不允许强制内联,任何复杂的函数都会被抛弃内联,导致额外的调用开销。 而短函数由于自动内联将快如闪电。 例如,对于无符号64位整数乘法溢出检测,当禁用内联时,除法所需的时间是长乘法的5倍,但允许自动内联后,除法所需的时间是长乘法的1/5。
123+
与其他语言(例如C++)的整数类型安全库相比,该库使用了一些看似缓慢的操作,例如除法。 但这并不意味着这些方法会很慢,实际上,因为Go为短函数自动内联的策略以及编译器优化,这些操作实际上在基准测试里非常快,快如闪电。
124+
125+
此外,Go定义了有符号整数的溢出行为,使得对于有符号整数溢出的检测简单而高效。
124126

125127
请注意,在业务函数中使用 `//go:noinline` 不会影响本库函数的内联。 只有通过 `-gcflags="-l"` 禁用全局内联才会影响该本库函数的内联。
126128

127129
### 基于和依赖
128130

129-
该库基于Go的官方编译器实现和语言规范,其定义了整数溢出发生时的行为
131+
该库基于Go的官方编译器实现(gc)和语言规范开发
130132

131133
### 许可
132134

0 commit comments

Comments
 (0)