- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想将浮点变量的值打印到屏幕上。我在 LLVM IR 代码中声明了 printf()
函数,它正在成功链接。
每当我打印整数或字符数据类型或字符串时,printf()
都会像在 C 代码中一样将它们正常打印到屏幕上。但是,如果我将 float
传递给 printf()
,它不会打印 float ,而是打印 0.000000
。我多次检查了源代码,似乎语法是正确的。它应该打印 2.75
!我正在查看这段代码,但我完全不明白代码与我编写的代码有何不同的行为。
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@obj1 = global {i32, float, i8} zeroinitializer
@format_string = constant [10 x i8] c"%i %f %c\0A\00"
declare i32 @printf(i8*, ...)
define i32 @main() {
entry:
%obj1 = load {i32, float, i8}, {i32, float, i8}* @obj1
%obj2 = insertvalue {i32, float, i8} %obj1, i32 44, 0
%obj3 = insertvalue {i32, float, i8} %obj2, float 2.75, 1
%obj4 = insertvalue {i32, float, i8} %obj3, i8 36, 2
store {i32, float, i8} %obj4, {i32, float, i8}* @obj1
%ptr.i32 = getelementptr {i32, float, i8}, {i32, float, i8}* @obj1, i32 0, i32 0
%0 = load i32, i32* %ptr.i32
%ptr.float = getelementptr {i32, float, i8}, {i32, float, i8}* @obj1, i32 0, i32 1
%1 = load float, float* %ptr.float
%ptr.i8 = getelementptr {i32, float, i8}, {i32, float, i8}* @obj1, i32 0, i32 2
%2 = load i8, i8* %ptr.i8
%format_ptr = getelementptr [10 x i8], [10 x i8]* @format_string, i64 0, i64 0
call i32 (i8*, ...) @printf(i8* %format_ptr, i32 %0, float %1, i8 %2)
ret i32 0
}
当我编译 LLVM IR 代码时,这是输出:
$ llvm-as code.ll -o code.bc
$ lli code.bc
44 0.000000 $
它成功打印了整数和字符,但没有打印 float !
最佳答案
原因是 printf
是可变参数函数,可变参数函数将 float
参数提升为 double
。参见 Why does printf() promote a float to a double?
因此,您应该先将 %1
转换为 double,然后再将其传递给 printf
,这就是 clang 所做的。例如
void f() {
float a = 1;
printf("%f", a);
}
给予
@.str = private unnamed_addr constant [3 x i8] c"%f\00", align 1
define void @f() {
%1 = alloca float, align 4
store float 1.000000e+00, float* %1, align 4
%2 = load float, float* %1, align 4
%3 = fpext float %2 to double
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x
i8], [3 x i8]* @.str, i64 0, i64 0), double %3)
ret void
}
注意fpext
的使用
关于floating-point - printf 不适用于 LLVM IR 中的 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63144506/
为什么这不返回每个社区(边界框)中的点数? import geopandas as gpd def radius(points_neighbour, points_center, new_field_
嘿! 我有一张图片,我想在该图片上选择一个点并告诉它应该变换到哪个坐标。我想为一些数字点做这个。当我完成时,整个图像会发生变化,因此会考虑局部性。 最重要的是,我可以选择任意多的点,并且所选的点会转换
我有代码: class Point3D{ protected: float x; float y; float z; public:
我正在开发我的第一个 Spring Boot + Spring Data JPA + Hibernate 5,在 PostgreSQL 上工作数据库。 我在尝试映射具有 point 作为数据类型的字段
当我尝试编译这个简单的代码时,我在构造函数中遇到了两个错误:“类型值不能用作默认参数”我该如何解决这个问题? public class PointerArgs { public P
当我尝试编译这个简单的代码时,我在构造函数中遇到了两个错误:“类型值不能用作默认参数”我该如何解决这个问题? public class PointerArgs { public P
目前我正在实现一项提供集体旅行的交通服务,但我遇到了一个问题: 假设我在下图中得到了点 G = {A,B,C,D,F,R,W} =>。 当用户选择 from(A) -> to(W) 时,它们之间有点:
我有一个名为 Shop 的实体,它有一个名为 Position 的 DBGeorgpraphy 列 数据库中的示例商店的位置值为 POINT (145.034242 -37.825519) 我正在尝试
我看了几个类似的帖子,但我要么不明白他们提供的是什么,要么他们似乎不适用。我是新来的,我会尽力遵守规则。 我们在类(class)的最后 2 周学习 c++,期末学习 40 小时 :),所以我是初学者。
我正在使用 tf2 将点从源帧转换为目标帧。下面是代码片段: import tf2_ros import tf2_geometry_msgs transform = tf_buffer.lookup_
我需要找到一种算法,根据给定的一组大小为 n 的点 S 计算凸包。我知道 S 正好有 6 个点 构成了凸包。 最好和最有效的方法是什么? 我想从 S 生成所有可能的点组合(这将是 n 选择 6 个点)
我有一个在屏幕坐标中的 CGPoint。我还有一个应用了变换矩阵(缩放、旋转和平移)的 CALayer。 如何将屏幕坐标中的点转换为图层的局部坐标? 最佳答案 CALayer 有执行此操作的方法,请在
我正在创建自定义控件,它将从点列表(或数组)中绘制形状。我已经完成了基本的绘图功能,但现在我正在为 Visual Studio 中的设计时支持而苦苦挣扎。 我创建了两个属性: private Poin
此函数是从“JavaScript:权威指南”复制的,但由于某种原因它不起作用... **points.dist = function () { ^ ReferenceError: 点未定义**我对此很
我有一个像这样的自定义适配器: private List items = new ArrayList<>(); private Context context; public UserSpinnerA
代码: UPDATE tbl_name SET points = points + 1 WHERE 'GAME 1' LIKE "%Vikes%" GAME 1 列包含包含 Vikes
我有一个点。我正在尝试将 x 作为 int。如果我使用 Point.x,我将得到 x 作为 int。但我的印象是我应该尽可能使用 setter/getter ( Why use getters and
我正在开发一个小型信誉系统,但遇到了一个问题。 因此,在我的示例中,我想为 4 种不同类型的用户创建一个图片网站;我们称他们为:业余、好、非常好、专业。 每个用户可以上传一张图片,这张图片可以被其他用
我有一个关于事件形状模型的问题。我正在使用 T. Coots 的论文(可以找到 here 。) 我已经完成了所有初始步骤(Procrustes 分析计算平均形状,PCA 减少尺寸)但仍停留在拟合上。
Android moving Image one point (0,0) to another point (30,400). using animation or normal looping co
我是一名优秀的程序员,十分优秀!