问题标签 [single-precision]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
1296 浏览

c - 如何保持 int64_t = int64_t * float 的精度?

我想在精度约为int64_t的范围内对一个因子进行校正。天真的实现是:[0.01..1.2]0.01

不幸的是,如果我投射factorint32或如果我投射yfloat.

但是,如果我能确保y它的最大值低于1<<56,我可以使用这个技巧:

如果我的输入值可以大于 ,我该如何解决这个问题1<<56

剧情转折:

我在 32 位架构上运行,该架构int64_t是模拟类型,并且我不支持双精度。该架构是 Analog Devices 的 SHARC。

0 投票
1 回答
317 浏览

c - C - 添加两个单精度浮点普通数,不能得到无穷大的结果

我在玩浮点运算,遇到了一些需要解释的东西。

将舍入模式设置为“趋向零”时,又名:

并且添加不同类型的正常正数,我永远无法达到无穷大。

然而,从 ieee 745 可知,溢出到无穷大可能是由添加有限数引起的。

例如:

但是,如果我将舍入模式更改为其他模式,我可能会得到 +INF 作为答案。

有人可以解释一下吗?

0 投票
0 回答
548 浏览

macos - fftw 双精度转单精度

我的系统上已经有 fftw-2.1.5。如何将其从双精度更改为单精度,是否需要重新安装?任何帮助将非常感激。

0 投票
0 回答
82 浏览

floating-point - 当我们在计算器中添加 0.1 和 0.6 时,计算机如何向我们显示 0.7 的结果?


1)据我所知,计算机将十进制数字转换为二进制数字并按其处理。例如,当我们在计算机的计算器中添加像“12”和“37”这样的十进制数字时。这是对的吗?


2)如果我的第一个问题是正确的,CPU如何以单精度解释下面的二进制表达式?(结果如何显示?计算机如何将转换为浮点数的表达式再次转换为十进制?我们如何将转换为浮点数的表达式再次转换为十进制?)

0 ll 01111110 ll 01100110011001100110100

我的意思是我们如何知道这个表达式中的单精度结果是 0.70000005:浮点算术


3) 据我所知,当我们在计算机的计算器中添加十进制0.1 和 0.6 时,计算机执行的交易与我分享的视频中的相同。但是,计算器对我们隐藏了 .0000005二进制部分(如视频结果中所示),并因此向我们显示十进制数字“0.7”,但它如何隐藏或删除该部分?为什么它没有通过四舍五入向我们显示像 0.71 这样的数字,

0 ll 01111110 ll 01100110011001100110100浮点数?


0 投票
1 回答
416 浏览

binary - 单精度浮点数减法是怎么做的?

这是示例(我已提前将它们转换为十进制)。
A 是 01000001000010000000000000000000^2(十进制 8.5)
B 是 01000000000100000000000000000000^2(十进制 2.25)

((+A)-(+B)) 应该是十进制的 6.25。规范化 A 和 B 并匹配指数。

A = 1.00010 * 2^3
B = 0.01001 * 2^3

我可以在纸上减去这个,如下所示。

1.00010 * 2^3
- 0.01001 * 2^3
'---------------
0.11001 * 2^3

这是 110.01^2,十进制是 6.25。

我的问题是 CPU 是如何解决这个问题的?我知道 CPU 会将 B 转换为二进制补码并添加负 B。但每次我尝试这样做时,我都会得到 6.75 作为答案。有人可以告诉我 CPU 如何将 B 转换为两个补码以获得负数,然后添加到 A 以获得 6.25 作为答案。谢谢

0 投票
1 回答
749 浏览

cuda - CUDA C using single precision flop on doubles

The problem

During a project in CUDA C, I came across unexpected behaviour regarding single precision and double precision floating point operations. In the project, I first fill an array with number in a kernel and in another kernel, I do some computation on these numbers. All variables and arrays are double precision, so I would not expect any single precision floating point operation to happen. However, if I analyze the executable of the program using NVPROF, it shows that single precision operations are executed. How is this possible?

Minimal, Complete, and Verifiable example

Here is the smallest program, that shows this behaviour on my architecture: (asserts and error catching has been left out). I use a Nvidia Tesla k40 graphics card.

The output of NVPROF (edited to make it more readable, if you need the full output, just ask in the comments):

What I've found so far

I found that if I delete the division in line 16:

the output is as expected: zero single precision operations and exactly 100 double precision operations are executed. Does anyone know why the division causes the program to use single precision flop and 10 times more double precision floating point operations? I've also tried using intrinsics (__ddiv_rn), but this didn't solve the problem.

Many thanks in advance!

Edit - Working solution

Altough I still haven't figured out why it uses the single precision, I have found a 'solution' to this problem, thanks to @EOF. Replacing the division by multiplication with the reciprocal of rho did the job:

0 投票
0 回答
258 浏览

floating-point - 检测浮点数是否太大(溢出)

我从 MIPS 开始,并被分配了一项作业,我必须在其中找到三角形的斜边(给定它的腿)(它们都是单精度浮点数)。但是,在每一步中,我都必须通过将数字与“无限”的 IEEE754 表示进行比较来检查溢出,但我不知道该怎么做,如果有任何帮助,我将不胜感激。

编辑:到目前为止我只有代码用于输入。

0 投票
1 回答
487 浏览

floating-point - 定点而不是浮点

定点数需要多少位至少与浮点数一样精确?如果我想用定点算术而不是浮点进行计算,我需要多少位才能使计算不那么精确?

单精度(32 位)浮点数可以表示小至 2^-126 和大至 2^127 的数字,是否意味着定点数必须至少为 128.128 格式?(整数部分为 128 位,小数部分为 128 位)。

我知道单精度浮点数一次只能表示约 7 个十进制数字的范围,我在询问所有可能的值。

那么双精度(64 位浮点数)呢,真的需要 1024.1024 格式才能同样精确吗?

0 投票
1 回答
135 浏览

c - 将 float 转换为 double 是如何工作的?

double 可以表示 float 可以表示的每个值。

将 float 转换为 double 是否只需通过添加 0 来扩展尾数并通过填充符号位来扩展指数部分?

我在http://www.binaryconvert.com/index.html测试了一些数据。它以这种方式工作。但是我没有找到转换的任何官方定义。转换是否有任何角落案例不能以这种方式工作?

0 投票
1 回答
470 浏览

floating-point - OCaml 中的 IEEE 64 和 32 位浮点验证

我有一个与以下正则表达式匹配的字符串,\-?[0-9]*\.[0-9]+它应该代表一个 IEEE 浮点数。它可以是单精度或双精度,我提前知道类型。我需要检查它是否可以被解释为给定精度的有效值。就像是:

对于双精度数字,我可以使用解析它float_of_string并捕获异常。我不确定如何处理单精度。