小编Chr*_*man的帖子

cos(a)在浮点数上是否可以等于0

鉴于PI/2永远不能在浮点中精确表示,是否可以安全地假设cos(a)永远不能返回精确的零?

如果是这种情况,那么以下伪代码将永远不会进入块(并且可以安全地删除):

...
y = h/cos(a);
if (!isfinite(a))
{
  // handle infinite y
}
Run Code Online (Sandbox Code Playgroud)

floating-point trigonometry

6
推荐指数
2
解决办法
396
查看次数

如何使用AsynchronousFileChannel异步强制文件

AsynchronousFileChannelJava中NIO.2 API包含的void force(boolean)方法.

显然这种方法是阻塞的,因为只有在将更改成功写入设备后才能返回.

我正在寻找一种方法来实现相同的目标,而不会阻塞线程.

正如评论中所提到的,这将等同于标准C库函数aio_fsync:http://pubs.opengroup.org/onlinepubs/009695399/functions/aio_fsync.html

java asynchronous nio nio2

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

隐式别名和扩展scala Seq

我有以下内容:

case class Bar()

trait Foo {
  def bars : Seq[Bar]
}
case class MyFoo(bars : Seq[Bar]) extends Foo

trait Foos extends Seq[Foo] {
  def bars : Seq[Bar] = this.map(_.bars).flatten
}
Run Code Online (Sandbox Code Playgroud)

我想将对象转换Seq[MyFoo]MyFoos,最好隐式.怎么能实现这个目标?

例如.

val foos : Foos = Seq(new MyFoo(Seq(new Bar)))
Run Code Online (Sandbox Code Playgroud)

scala implicit-conversion

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