faker1
V2EX  ›  问与答

简单数学问题求助

  •  
  •   faker1 · Jan 16, 2019 · 1150 views
    This topic created in 2687 days ago, the information mentioned may be changed or developed.
    
    /***
     有一段 go 代码如下, 这个 ```result ```值 在某个区间是一样的?
    ***/
    package main
    
    import (
    	"time"
    	"log"
    )
    
    
    func PrevSlot(now int64) int64 {
    	// now = time.Now().Unix()
    	var blockInterval = int64(10)
    
    	result := int64((now-1)/blockInterval) * blockInterval //  这个值在咋一样呢?弄了半天不懂
    	log.Println("PrevSlot:", int64(result), int64((now-1)/blockInterval), now)
    	return result
    }
    
    
    func main() {
    	//fmt.Println(15 /2)
    	ticker := time.NewTicker(1 * time.Second)
    	for {
    		<-ticker.C
    
    		now := time.Now().Unix()
    		PrevSlot(now)
    	}
    
    }
    
    /**
    output:
    2019-01-16 10:58:31.668597 I | dpos.go: PrevSlot: 1547607510 154760751 1547607511
    2019-01-16 10:58:32.668649 I | dpos.go: PrevSlot: 1547607510 154760751 1547607512
    2019-01-16 10:58:33.668568 I | dpos.go: PrevSlot: 1547607510 154760751 1547607513
    2019-01-16 10:58:34.668572 I | dpos.go: PrevSlot: 1547607510 154760751 1547607514
    2019-01-16 10:58:35.668547 I | dpos.go: PrevSlot: 1547607510 154760751 1547607515
    
     */
    
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5696 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 02:43 · PVG 10:43 · LAX 19:43 · JFK 22:43
    ♥ Do have faith in what you're doing.