我意识到这个问题可能与处理器有关,但希望有人能指出我正确的方向。对于我的一生,我无法弄清楚如何将表示纳秒的 unsigned long long int 转换为 C 中表示秒的双精度(我使用 32 位大端 PowerPC 405 进行此特定测试,以及 GNU C99编译器)。
我试过了:
unsigned long long int nanoseconds = 1234567890LLU;
double nanoseconds_d = nanoseconds*1e-9;
还:
nanoseconds_d = ((double) nanoseconds)*1e-9;
对于这两种情况,我只得到 0。我在这里做错了什么?
编辑添加完整示例
#include <stdio.h>
#include <stdlib.h>
int
main( int argc, char *argv[] )
{
unsigned long long int nanoseconds = 1234567890LLU;
double nanoseconds_d = nanoseconds * 1e-9;
printf("%g\n", nanoseconds_d);
return 0;
}
制作文件
SRCS = simple.c
INCLUDE := -I$(PWD)
CFLAGS := -O0 -g3 -Wall -fmessage-length=0 -mhard-float -fsigned-char -D_REENTRANT
LIBS := -lc
OBJS = $(SRCS:.c=.o)
PROG = $(SRCS:.c=).out
all: $(PROG)
$(PROG): $(OBJS)
@echo "Linking object files with output."
$(CC) -o $(PROG) $(OBJS) $(LIBS)
@echo "Linking complete."
$(OBJS): $(SRCS)
@echo "Starting compilation."
$(CC) $(CFLAGS) $(INCLUDE) -c $<
@echo "Compilation complete."
clean::
@$(RM) *.o *.out