当前位置: 首页 > news >正文

Unity Mono和.Net平台浮点算法的区别

        static void TestFloat(){{//float speed=2.0f/20;float speed = 0.1f;float distance = 2.0f;long needTime = (long)(distance / speed);Log.Debug($"needTime={needTime}");
#if UNITY_EDITORif (needTime != 19)
#elseif (needTime != 20)//.Net服务器和安卓手机
#endifLog.Warning("平台浮点算法变了");}}static void TestFixInt(){{FixInt fi2 = 20000;FixInt fi1 = 10000;if (fi1 / fi2 != 0.5f){Log.Warning($"TestFixInt,{fi2}/{fi1} != 0.5");}}{FixInt fi2 = 20000;FixInt fi1 = 10000;if (fi2 / fi1 != 2){Log.Warning($"TestFixInt,{fi2}/{fi1} != 2");}}{const long l = 20000;FixInt fi = new(6000);if (l < fi){Log.Warning($"TestFixInt,{l} < {fi}");}}{FixInt fi3 = new(3);FixInt fi5 = new(5);if (fi3 + 1000 < fi5){Log.Warning($"TestFixInt,{fi3} , {fi5}");}}{const long l = 3000;FixInt fi = l;if (fi.RawLong != l){Log.Warning($"TestFixInt,{fi.RawLong} != {l}");}}}static void TestGetPolygonFormation(){var points = TeamFormationComponentSystem.GetPolygonFormation(new(),new() { x = 230.33540344238281f, y = -0.0000019073486328125f, z = 62.280677795410156f },new() { x = -6.1755828857421875f, y = -0.045724689960479736f, z = 9.5355415344238281f },4,2);List<float3> list = new(){new(){x = 230.429f, y = 0.0f, z = 62.135f },new(){ x = 233.077f, y = 0.0f, z = 60.689f },new(){ x = 233.317f, y = 0.0f, z = 57.679f },new(){ x = 230.669f, y = 0.0f, z = 59.125f },};if (points.Count != list.Count){Log.Warning($"TestGetPolygonFormation,{points} != {list}");}for (int i = 0; i <points.Count; ++i){var cal = points[i];var want = list[i];if (!cal.Equals(want)){Log.Warning($"TestGetPolygonFormation,{cal} != {want}");}}}static void TestGetPointOnEllipse(){var radius = 2.82842707633972f;var intervalAngle = 90;var radian = -32.9286422729492f + (intervalAngle * 3);var dChangZhouAngle = -45f;var xShaft = 0.5f * radius;var yShaft = 1f * radius;var ptCenter = new float2(231.872909545898f, 59.9066619873047f);var cal = VectorHelper.GetPointOnEllipse(ptCenter,xShaft,yShaft,radian,dChangZhouAngle); //算出旋转后的向量float3 want = new() { x = 230.669f, y = 0.0f, z = 59.125f };if (!cal.Equals(want)){Log.Warning($"TestGetPointOnEllipse,{cal} != {want}");}}static void TestMath(){var radius = 2.82842707633972f;var intervalAngle = 90;var radian = -32.9286422729492f + (intervalAngle * 3);var dChangZhouAngle = -45f;var xShaft = 0.5f * radius;var yShaft = 1f * radius;var ptCenter = new float2(231.872909545898f, 59.9066619873047f);radian -= dChangZhouAngle;dChangZhouAngle *= VectorHelper.Mathf.Deg2Rad;radian *= VectorHelper.Mathf.Deg2Rad;float dLiXin = math.atan2(yShaft * math.sin(radian), xShaft * math.cos(radian)); //离心角if (dLiXin != -1.46427190303802f){Log.Warning($"TestMath,{dLiXin} ");}if (yShaft != 2.8284270763397221f){Log.Warning($"TestMath,{yShaft} ");}if (dLiXin != -1.4642719030380249f){Log.Warning($"TestMath,{dLiXin} ");}if (dChangZhouAngle != -0.78539818525314298f){Log.Warning($"TestMath,{dChangZhouAngle} ");}if (xShaft != 1.4142135381698611f){Log.Warning($"TestMath,{xShaft} ");}var cosLiXin = math.cos(dLiXin);var sinChangZhouAngle = math.sin(dChangZhouAngle);var sinLiXin = math.sin(dLiXin);var cosChangZhouAngle = math.cos(dChangZhouAngle);if (cosLiXin != 0.10632307827472701f){Log.Warning($"TestMath,{xShaft} ");}if (sinChangZhouAngle != -0.70710676908492998f){Log.Warning($"TestMath,{xShaft} ");}if (sinLiXin != -0.99433165788650502f){Log.Warning($"TestMath,{xShaft} ");}if (cosChangZhouAngle != 0.70710676908492998f){Log.Warning($"TestMath,{xShaft} ");}var x = yShaft * cosLiXin * sinChangZhouAngle + xShaft * sinLiXin * cosChangZhouAngle + ptCenter.x;
#if UNITY_EDITORif (x != 230.665939331055f)
#elseif (x != 230.66592407226563f)
#endif{Log.Warning($"平台浮点加法或乘法算法变了,{x} ");}float y = yShaft * math.cos(dLiXin) * math.cos(dChangZhouAngle) - xShaft * math.sin(dLiXin) * math.sin(dChangZhouAngle) + ptCenter.y;}

结论
.Net和安卓手机IL2CPP算法相同
Windows下Unity的Mono算法不同,就它不同

http://www.lryc.cn/news/198869.html

相关文章:

  • 【SA8295P 源码分析 (二)】64 - QNX 与 Android GVM 显示 Dump 图片方法汇总
  • shell命令以及运行原理和lLinux权限
  • 斯坦福JSKarel编程机器人使用介绍
  • SpringBoot中pom.xml不引入依赖, 怎么使用parent父项目的依赖
  • 基于vue3+ts5+vue-router4+pinia2的PC端项目搭建教程
  • 6个无版权、免费、高清图片素材库
  • 什么是响应式设计?响应式设计的基本原理是什么?如何兼容低版本的 IE?
  • LeetCode 2906. 构造乘积矩阵【前后缀分解,数组】中等
  • vue3+koa+axios实现前后端通信
  • Required MultipartFile parameter ‘file‘ is not present
  • vue3后台管理系统之layout组件的搭建
  • Minio 文件上传(后端处理同文件判断,同一文件秒传)
  • 模拟IIC通讯协议(stm32)(硬件iic后面在补)
  • 使用注解读取properties配置文件
  • Python---练习:求世界杯小组赛的总成绩(涉及:布尔类型转换为整型)
  • vue3学习源码笔记(小白入门系列)------KeepAlive 原理
  • 边写代码边学习之mlflow
  • 基于吉萨金字塔建造优化的BP神经网络(分类应用) - 附代码
  • axios的post请求所有传参方式
  • 【c++】向webrtc学比较2: IsNewerSequenceNumber 用于NackTracker及测试
  • PRCV 2023:语言模型与视觉生态如何协同?合合信息瞄准“多模态”技术
  • 深度学习硬件配置推荐(kaggle学习)
  • 1019hw
  • 两分钟搞懂UiAutomator自动化测试框架
  • Fast DDS之Subscriber
  • 测试PySpark
  • C语言- 原子操作
  • 设置hadoop+安装java环境
  • 阿里云新加坡主机服务器选择
  • 21天打卡掌握java基础操作