求助 i128
  • 板块学术版
  • 楼主qczrz6v4nhp6u
  • 当前回复7
  • 已保存回复7
  • 发布时间2024/8/22 11:42
  • 上次更新2024/8/22 14:57:03
查看原帖
求助 i128
654546
qczrz6v4nhp6u楼主2024/8/22 11:42

本人在做一道需要使用 __int128 的题,为方便输出写了如下的输出函数:

inline ostream& operator <<(ostream &ouf,i128 x){
	static char sta[1024];static int top;top=0;
	if(x<0)ouf<<'-',x=-x;
	do sta[++top]=x%10^48,x/=10; while(x);
	while(top)ouf<<sta[top--];
	return ouf;
}

然而我在使用它生成数据时,却发现它有时候会输出乱码,经过调试发现输出了负数的 char 值,但在 do-while 部分 assert x>=0、x%10>=0、(x%10^48)>=0 均无果,同时如果尝试在 do-while 部分输出 x 会 RE,在 while(top) 部分 assert sta[top]>=0 会 Assertion Failed。

求问这是什么原因。

2024/8/22 11:42
加载中...