鉴于PI/2永远不能在浮点中精确表示,是否可以安全地假设cos(a)永远不能返回精确的零?
如果是这种情况,那么以下伪代码将永远不会进入块(并且可以安全地删除):
...
y = h/cos(a);
if (!isfinite(a))
{
// handle infinite y
}
Run Code Online (Sandbox Code Playgroud) 在AsynchronousFileChannelJava中NIO.2 API包含的void force(boolean)方法.
显然这种方法是阻塞的,因为只有在将更改成功写入设备后才能返回.
我正在寻找一种方法来实现相同的目标,而不会阻塞线程.
正如评论中所提到的,这将等同于标准C库函数aio_fsync:http://pubs.opengroup.org/onlinepubs/009695399/functions/aio_fsync.html
我有以下内容:
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)