我今天才注意到Math.fma(a, b, c)Java 9 的存在,它计算a*b + c
(for double和floatvalues).
返回三个参数的融合乘法加法; 也就是说,返回与第三个参数相加的前两个参数的精确乘积,然后将其舍入一次到最近的float.使用舍入到最近的偶数舍入模式完成舍入.相反,如果a*b + c被评估为常规浮点表达式,则涉及两个舍入误差,第一个用于乘法运算,第二个用于加法运算.
因此看起来它通过进行1舍入而不是2来提高准确性.这是正确的吗?那是有条件的CPU的能力,或者我们可以指望的是始终?
我猜它可能是使用特殊的CPU指令实现的.是这样的吗?如果是这样,我们还可以期待性能优势吗?我有兴趣了解当前平台/ CPU的实际好处,以及假设的未来收益.
编辑(试图让它变得不那么宽泛):我不是在寻找非常详细的答案:是/否对于纠正/确认我的理解的几个项目,加上一些指示,对我来说就足以标记答案了被接受了.我对准确性和性能方面都非常感兴趣,我认为它们在一起......
我正在努力实现一个DateConverter持久的日期.它非常通用,但我一直得到:
无法弄清楚如何将此字段保存到数据库中.您可以考虑为其添加类型转换器.
我仔细检查并在数据库级别和字段级别定义了注释,它仍然无法解决为字段定义的类型转换器.
我的成绩文件依赖项:
compile('android.arch.persistence.room:runtime:1.0.0-alpha3') {
exclude group: 'com.google.code.gson'
}
compile('android.arch.persistence.room:rxjava2:1.0.0-alpha3') {
exclude group: 'com.google.code.gson'
}
testCompile('android.arch.persistence.room:testing:1.0.0-alpha3') {
exclude group: 'com.google.code.gson'
}
annotationProcessor('android.arch.persistence.room:compiler:1.0.0-alpha3') {
exclude group: 'com.google.code.gson'
}
Run Code Online (Sandbox Code Playgroud)
在我的AppDatabase中:
@Database(entities = {Location.class, Room.class, Amenity.class, UserModel.class, EventModel.class}, version =1, exportSchema = false)
@TypeConverters({DateConverter.class})
public abstract class AppDatabase extends RoomDatabase {
public abstract RoomDao getRoomDao();
public abstract LocationDao getLocationDao();
public abstract AmenityDao getAmenityDao();
public abstract UserDao getUserDao();
public abstract EventDao getEventDao();
}
Run Code Online (Sandbox Code Playgroud)
然后我的DateConverter班级看起来像这样:
public class DateConverter {
@TypeConverter …Run Code Online (Sandbox Code Playgroud) 我正在使用tomcat 8.0.15,spring 4.1.5.
我实现了3个强制函数来使用websocket,如下所示.这很简单.
private Map<String, WebSocketSession> map_users = new ConcurrentHashMap<>();
private Map<String, String> map_id = new ConcurrentHashMap<>();
public void afterConnectionEstablished(WebSocketSession wss) throws Exception {
map_users.put(wss.getId(), wss);
}
public void afterConnectionClosed(WebSocketSession wss, CloseStatus cs) throws Exception {
map_users.remove(wss.getId());
// remove user
String username = map_id.get(wss.getId());
if (username != null) {
map_id.remove(wss.getId());
map_id.remove(username);
}
}
public void handleTextMessage(WebSocketSession wss, TextMessage tm) throws Exception {
String str = tm.getPayload();
String username = ...;
// regist user
if (!map_id.get(wss.getId())) {
map_id.put(wss.getId(), username);
map_id.put(username, …Run Code Online (Sandbox Code Playgroud) 我想使用jedis(Redis缓存)和java存储多个具有单值的键.
我有三个按键,例如user_1,driver_10,admin_5和值= this is user,我想用这三个当中的任何一个键获得值.
我有一组用户名(例如['abc','def','ghi'])要添加到图表中的"用户"标签下.
现在我首先要检查用户名是否已经存在(g.V().hasLabel('user').has('username','def')),然后仅添加"用户"标签下用户名属性不匹配的用户名.
此外,这可以在单个gremlin查询或groovy脚本中完成吗?
我正在使用titan graph数据库,tinkerpop3和gremlin REST服务器.
我有一个Controller类,其中包含以下两种查找医生的方法(上下文已更改)。获取 质量分配:两种方法上的不安全的活页夹配置(API滥用,结构化)错误。
@Controller
@RequestMapping(value = "/findDocSearch")
public class Controller {
@Autowired
private IFindDocService findDocService;
@RequestMapping(value = "/byName", method = RequestMethod.GET)
@ResponseBody
public List<FindDocDTO> findDocByName(FindDocBean bean) {
return findDocService.retrieveDocByName(bean.getName());
}
@RequestMapping(value = "/byLoc", method = RequestMethod.GET)
@ResponseBody
public List<FindDocDTO> findDocByLocation(FindDocBean bean) {
return findDocService.retrieveDocByZipCode(bean.getZipcode(),
bean.getDistance());
}
}
Run Code Online (Sandbox Code Playgroud)
我的豆是:
public class FindDocBean implements Serializable {
private static final long serialVersionUID = -1212xxxL;
private String name;
private String zipcode;
private int distance;
@Override
public String toString() {
return String.format("FindDocBean[name: %s, …Run Code Online (Sandbox Code Playgroud) 我有一些 json 数据,已使用 $.ajax 发布到 API,但我想更新它以使用 fetch API。不过,我似乎设置了 Fetch API 请求最终返回 403,所以我一定错过了一些东西,但我无法解决。
阿贾克斯请求:
$.ajax({
type: 'POST',
url: url,
data: {
'title': data.title,
'body': data.body,
'csrfmiddlewaretoken': csrf_token,
'request_json': true
},
success: function (data) {
console.log(data)
}
});
Run Code Online (Sandbox Code Playgroud)
获取尝试(众多尝试之一):
let payload = {
'title': data.title,
'body': data.body,
'csrfmiddlewaretoken': csrf_token,
'request_json': true
}
let request = new Request(url, {
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: JSON.stringify( payload )
});
fetch(request)
.then((response) => {
if (!response.ok) {
throw Error(response.statusText);
}
return response; …Run Code Online (Sandbox Code Playgroud) 我目前正在使用Roaster生成接口,但我的接口具有绑定到它的泛型类型.
以下是我尝试生成它们的内容:
String entityName = "SimpleEntity";
JavaInterfaceSource repository = Roaster.create(JavaInterfaceSource.class)
.setName(entityName + "Repository");
JavaInterfaceSource jpaInterface = repository.addInterface(JpaRepository.class);
jpaInterface.addTypeVariable(entityName);
jpaInterface.addTypeVariable("String");
Run Code Online (Sandbox Code Playgroud)
但上面的结果是生成的代码看起来像这样(某事):
public interface SimpleEntityRepository<SimpleEntity>
extends
org.springframework.data.jpa.repository.JpaRepository {
}
Run Code Online (Sandbox Code Playgroud)
我真正想要的是通用绑定JpaRepository.我该如何做到这一点?
Nim中的模数运算符是多少?
tile % 9 == 0 导致未声明的标识符:'%'
谷歌搜索或搜索SO没有提出答案.
我有一个文件名向量,我想提取部分名称.矢量是:
vect <- c("Z:/zoe/test2/H1.fusion.txt", "Z:/zoe/test2/H1_1.fusion.txt",
"Z:/zoe/test2/H2.fusion.txt", "Z:/zoe/test2/H3.fusion.txt",
"Z:/zoe/test2/H4.fusion.txt", "Z:/zoe/test2/H5.fusion.txt")
Run Code Online (Sandbox Code Playgroud)
我想循环遍历向量并提取H名称的一部分,因此在第三个/和第一个之间.
理想情况下我不想计算子字符串的字符数量,因为目录名称和文件名将更改.
也因为有不止一个/和.,我不能用s.indexOf?
这可能吗?
java ×6
spring ×2
ajax ×1
android ×1
android-room ×1
caching ×1
fetch-api ×1
fortify ×1
gremlin ×1
groovy ×1
java-9 ×1
javascript ×1
modulus ×1
nim-lang ×1
r ×1
redis ×1
roaster ×1
spring-mvc ×1
tinkerpop3 ×1
titan ×1