小编Val*_*rie的帖子

去 - 划分big.Float

我正在处理需要big.Float类型的数字,我需要将它们分开.我知道big.Int有一个.Div()函数,但是如果我是正确的,那会截断值并失去我使用的精度big.Float.

相关代码

func e(prec int64) (res *big.Float) {
    res = big.NewFloat(float64(1.0))
    base := big.NewInt(prec)

    for i := base; i.Cmp(big.NewInt(int64(0))) == 1; _ = i.Sub(i, big.NewInt(1)) {
        d := big.NewFloat(float64(1.0))
        _ = d.Div(fact(i)) // error here
        res.Add(d)
    }

    return
}
Run Code Online (Sandbox Code Playgroud)

math go

10
推荐指数
1
解决办法
3610
查看次数

Rails初始化校验和错误

我正在尝试在Windows上初始化一个新的rails应用程序,并且运行rails new <appname>生成所有内容vendor/assets/stylesheets/.keep,但是当bundle install运行时,rails会生成此错误:

Checksum of /versions does not match the checksum provided by server! Something is wrong.
Run Code Online (Sandbox Code Playgroud)

我不确定是什么导致了这一点,因为我没有做任何事情.任何帮助表示赞赏.

编辑:如果这是由于窗口挑剔引起的错误,我可以选择转移到Linux,但我想先知道出了什么问题.

ruby ruby-on-rails ruby-on-rails-4

9
推荐指数
1
解决办法
8374
查看次数

通过LAN托管Socket.io服务器

我建立Socket.IO的例子聊天项目(含部分变更)和我一直试图让人们既连接localhost:3000127.0.0.1:3000,但也都在工作.我错过了什么吗?(如果有一个明显的明显问题,抱歉.我很糟糕.)

index.js:

var app=require('express')();
var http=require('http').Server(app);
var io=require('socket.io')(http);
var chalk=require('chalk');

var online=0;
var prt=process.argv[2]===undefined?3000:process.argv[2];

process.stdin.on('data',function(){
    var str=String(process.stdin.read());
    if(str.search("!quit")){
        io.emit('chat message','Console: stopping server.');
        process.exit();
    }
});

app.get('/',function(req,res){
    res.sendFile(__dirname+'/index.html');
});

io.on('connection',function(socket){
    online++;
    console.log(chalk.green('joined  |',chalk.cyan(online),'online'));

    socket.on('chat message',function(msg){
        io.emit('chat message',msg);
        console.log(chalk.magenta('message |',msg));
    });

    socket.on('disconnect',function(){
        online--;
        console.log(chalk.red('left    |',chalk.cyan(online),'online'));
    });
});

http.listen(prt,function(){
    console.log(chalk.yellow('SIOChat listening on',chalk.cyan(prt)));
});
Run Code Online (Sandbox Code Playgroud)

index.html(为了便于阅读,省略了css):

<html>
    <head>
        <title>SIOChat</title>
    </head>
    <body>
        <ul id='messages'></ul>
        <form action=''>
            <input id='m' autocomplete='off'/><button>Send</button>
        </form>
        <script src='https://cdn.socket.io/socket.io-1.2.0.js'></script>
        <script src='http://code.jquery.com/jquery-1.11.1.js'></script>
        <script>
            var socket=io();

            var name=prompt('Enter a nickname','Guest');

            $('form').submit(function(){ …
Run Code Online (Sandbox Code Playgroud)

javascript node.js socket.io

2
推荐指数
1
解决办法
1082
查看次数

为什么评价为假?

为什么将显式调用的String构造函数与隐式字符串求值进行比较true,但是添加new关键字使得它false在深度等于上进行求值,但是true在浅等于?

> "hello"===String("hello")
true
> "hello"==new String("hello")
true
> "hello"===new String("hello")
false
Run Code Online (Sandbox Code Playgroud)

编辑:在进一步测试之后,这似乎发生在具有隐式构造函数的所有类型中.

编辑2:澄清,这不是一个问题=====,但隐与显式的构造之一.

javascript node.js

1
推荐指数
1
解决办法
66
查看次数