此问题涉及C/x86上使用的IEEE标准浮点数.
是否可以将任何数字(即排除特殊值,如NaN)浮点数或双精度表示为十进制字符串,以便将该字符串转换回浮点数/双精度数将始终完全产生原始数字?
如果没有,什么算法告诉我给定的数字是否会出现转换错误?
如果是这样,请考虑这一点:当转换为二进制时,一些小数部分在数值上不会与原始十进制值相同,但反之则不正确(因为二进制具有有界精度,因此任何十进制扩展都是有限的,如果不是则完美截断),所以这是另一个问题......
是否有必要在十进制表示中引入故意错误以欺骗atof(或其他)函数产生确切的原始数字,或者一个天真的非截断toString函数是否足够(假设一般可以进行精确转换)?
如何让awk识别字符类?
例如,这个:
echo "a\n1\nb\n2\nc" | awk '/1/'
Run Code Online (Sandbox Code Playgroud)
1按预期输出,但这个:
echo "a\n1\nb\n2\nc" | awk '/\d/'
Run Code Online (Sandbox Code Playgroud)
没有输出任何我期望的东西,1并2在过滤器中存活.
我认为这可能与shell转义(zsh)有关,但awk '/\\d/'也无效.
这是一个简单的程序,说明了这个问题.
#include <string.h>
#include <iostream>
int main () {
char buf [30];
strerror_r (0, buf, sizeof (buf));
std :: cout << "strerror_r(0): " << buf << std :: endl;
std :: cout << "strerror(0): " << strerror (0) << std :: endl;
}
Run Code Online (Sandbox Code Playgroud)
这是输出.
strerror_r(0):
strerror(0): Success
Run Code Online (Sandbox Code Playgroud)
为什么没有buf?
(使用gcc在Ubuntu上编译.)
我正在尝试调试第三方HTML/Javascript页面,但我无法轻松找到脚本入口点以在它们上设置断点.
我希望调试器在任何元素的onclick事件处理程序上中断.目前,如果页面设置类似的东西
document.getElementById("foo").onclick = bar;
Run Code Online (Sandbox Code Playgroud)
那么一般来说,确定foo和bar是否连接并不容易.
所以,我想打破所有的onclicks,无论它们在哪里.
我可以在Chrome或Firefox中执行此操作吗?
我正在编写一个 Perl 脚本来监视文件的更改。
#!/usr/bin/perl
use strict;
use Linux::Inotify2;
my $inotify = new Linux::Inotify2 or die $!;
my $filename = "/tmp/foo";
my $counter = 0;
$inotify->watch (
$filename,
IN_MODIFY,
sub {
++$counter;
print "changed: $counter\n";
}
) or die $!;
1 while $inotify->poll;
Run Code Online (Sandbox Code Playgroud)
如果我像这样测试它,每次 /tmp/foo 发生变化时,该处理程序都会被调用两次(增加 $counter 两次):
echo abc > /tmp/foo
Run Code Online (Sandbox Code Playgroud)
为什么?
我想在 QWidget 上渲染场景,并且需要定义从世界坐标到屏幕坐标的转换。QPainter::setWindow似乎是正确使用的函数,但它将其逻辑坐标定义为int,而不是float。
我的逻辑坐标不仅是浮点数,而且还非常小。逻辑坐标窗口类似于(1.5,1.5)..(1.54,1.53)。
我无法使用,因为路由错误完全破坏了我的坐标,那么当矩形具有任意浮点值时,setWindow如何设置转换QPainter以便渲染矩形将完全填充小部件?(x,y)..(x+width,y+height)
(矩形已被选择为具有正确的长宽比以适合小部件。)
class Parent {};
class Child : public Parent {};
class Foo
{
public:
Foo (Parent &) {};
template <typename T>
Foo (const T &);
};
int main ()
{
Child c;
Foo foo (c);
}
Run Code Online (Sandbox Code Playgroud)
这将产生一个链接错误,因为构造函数foo选template<typename T>Foo::Foo(const T &)来代替Foo::Foo(Parent&)。
如果c类型Parent为Child,则使用非模板构造函数,并且链接没有问题。
我可以解决这个问题
Foo foo ((Parent&) c);
Run Code Online (Sandbox Code Playgroud)
但是我不想那样做。
为什么C ++更喜欢使用模板而不是隐式转换c为Parent&?
我可以将类更改为偏向于铸造而不是模板,因此不需要解决方法吗?
namespace Foo
{
namespace Inner
{
void func (int *);
}
}
Run Code Online (Sandbox Code Playgroud)
#include <Foo.h>
namespace Bar
{
namespace Inner
{
void func (float *);
}
}
Run Code Online (Sandbox Code Playgroud)
#include <Bar.h>
using namespace Bar;
int main ()
{
int i;
float f;
Inner::func (&i);
Inner::func (&f);
}
Run Code Online (Sandbox Code Playgroud)
的main重载无需命名空间限定符即可使用,但重载需要命名float *空间限定符。funcBar::int *Foo::
我知道我可以
using namespace Foo::Inner;
using namespace Bar::Inner;
int main ()
{
int i;
float f;
func (&i);
func (&f);
}
Run Code Online (Sandbox Code Playgroud)
我不希望 …
当我启动 gdb 时,我通常想要break my_function. 我可以添加这个命令,.gdbinit但我得到
Function "my_function" not defined.
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]
Run Code Online (Sandbox Code Playgroud)
(这是因为my_function是动态链接的。)
我如何让它以非交互方式对这个问题做出肯定的回答?
我有一个调用其他程序的Perl脚本,即调用system和/或exec和/或open使用管道和/或使用反引号运算符.
我是否可以运行此脚本,以便打印出上述每个参数的参数,以便我可以看到它调用的是什么?
例如像我这样的程序,我无法修改
#!/usr/bin/perl
sub get_arg {return "argument$_[0]";}
system "./foo", get_arg(1), get_arg(2);
print `./foo abc def`;
Run Code Online (Sandbox Code Playgroud)
调用了类似这样的东西
perl --shell-trace-on ./myscript.pl
在这种情况下输出
./foo argument1 argument2
./foo abc def
Run Code Online (Sandbox Code Playgroud)
抛弃myscript.pl的正常输出或将其与此跟踪混合是可以接受的.
非常感谢.
c++ ×2
debugging ×2
perl ×2
awk ×1
c ×1
casting ×1
coordinates ×1
firefox ×1
gcc ×1
gdb ×1
inotify ×1
javascript ×1
linux ×1
namespaces ×1
qt ×1
regex ×1
shell ×1
shellexecute ×1
string ×1
system-calls ×1
templates ×1