Git Product home page Git Product logo

Comments (3)

hy05190134 avatar hy05190134 commented on June 10, 2024

@programmerZhou 你的意思不取余反而是正确的?

from gortmp.

programmerZhou avatar programmerZhou commented on June 10, 2024

@hy05190134 强转让其溢出即是取模。

return uint32(time.Now().UnixNano()/int64(1000000))
return uint32(time.Now().UnixNano()/int64(1000000) % 0x100000000)

上面这两行等价。

类似的写法还有

// 对一个数除2 
a := x / 2 
// 也可写成 
a = x >> 1

上面的问题主要是MAX_TIMESTAMP定义的不对,应该是0x100000000, 时间戳是环绕的,达到最大值之后,下一个值为0,即0xffffffff的下一个值为0。

注:位运算一般效率更高。

from gortmp.

zhangpeihao avatar zhangpeihao commented on June 10, 2024

这个需要实测,spec里面写的有些不准确,所以设置了一个最大支持的时间范围。

from gortmp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.