boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Question in C++ complex number implementation
相关主题
写惯了C++ code,再写C code真不习惯
What problem can occur when dynamically allocated classes
C++缘何厚deque薄queue?
what's wrong with this C++ code?
谁来解释一下这个是compiler问题吗?
请教什么时候变量会被load进stack,什么时候进入heap呢?
请教一个const pointer的问题
在c中如果一个function return 一个字符串
java main的疑问
C puzzle 一日一题
相关话题的讨论汇总
话题: complex话题: c++话题: literal话题: question话题: struct
进入Programming版参与讨论
1 (共1页)
r***e
发帖数: 2000
1
I was reading the system library of complex number
and have some questions:
1) Should it be a class or a struc?
the system makes it a struc;
2) Although it is a struct, the system library provides
accessor functions such as real(), etc. why?
3) Why it is implemented as a template?
I would assume make it two doubles and type conversion
can take care of int and float, etc.
Thanks.
N***m
发帖数: 4460
2

Struct works well in legacy code, and it may cause less trouble in
transfering data.
Isn't it natural to have such a function?
Template was designed to solve such problems. But you still think
in the same old way.

【在 r***e 的大作中提到】
: I was reading the system library of complex number
: and have some questions:
: 1) Should it be a class or a struc?
: the system makes it a struc;
: 2) Although it is a struct, the system library provides
: accessor functions such as real(), etc. why?
: 3) Why it is implemented as a template?
: I would assume make it two doubles and type conversion
: can take care of int and float, etc.
: Thanks.

t****t
发帖数: 6806
3
1 class or struct doesn't matter. only difference is default accessibility.
what matters is, complex<> are "literal types". i assume this is for
compatibility and implementation convenience.
2 the default accessibility is for backward compatibility.
3 for floating point calculation, precision matters. why system provides
float, instead of letting everyone use double?

【在 r***e 的大作中提到】
: I was reading the system library of complex number
: and have some questions:
: 1) Should it be a class or a struc?
: the system makes it a struc;
: 2) Although it is a struct, the system library provides
: accessor functions such as real(), etc. why?
: 3) Why it is implemented as a template?
: I would assume make it two doubles and type conversion
: can take care of int and float, etc.
: Thanks.

r***e
发帖数: 2000
4

.
What is a 'literal type'? What is the common practice for
a 'literal type', a class or a struct?
I see.
I see, thank you.

【在 t****t 的大作中提到】
: 1 class or struct doesn't matter. only difference is default accessibility.
: what matters is, complex<> are "literal types". i assume this is for
: compatibility and implementation convenience.
: 2 the default accessibility is for backward compatibility.
: 3 for floating point calculation, precision matters. why system provides
: float, instead of letting everyone use double?

t****t
发帖数: 6806
5
google is your friend.

【在 r***e 的大作中提到】
:
: .
: What is a 'literal type'? What is the common practice for
: a 'literal type', a class or a struct?
: I see.
: I see, thank you.

N***m
发帖数: 4460
6
大侠你很空啊,呵呵。

【在 t****t 的大作中提到】
: google is your friend.
r*******m
发帖数: 109
7
once you start get used to template, its really the wonderful thing in C++.

【在 r***e 的大作中提到】
: I was reading the system library of complex number
: and have some questions:
: 1) Should it be a class or a struc?
: the system makes it a struc;
: 2) Although it is a struct, the system library provides
: accessor functions such as real(), etc. why?
: 3) Why it is implemented as a template?
: I would assume make it two doubles and type conversion
: can take care of int and float, etc.
: Thanks.

h*******s
发帖数: 8454
8
google得结果似乎都是在说c++0x里面规定了可以有user defined literal,没找到哪
里说complex是literal type啊
大牛有空多解释一下?

【在 t****t 的大作中提到】
: google is your friend.
t****t
发帖数: 6806
9
literal type is not user defined literal.

【在 h*******s 的大作中提到】
: google得结果似乎都是在说c++0x里面规定了可以有user defined literal,没找到哪
: 里说complex是literal type啊
: 大牛有空多解释一下?

1 (共1页)
进入Programming版参与讨论
相关主题
C puzzle 一日一题
请教C++里面这个表达
Literate programming
考,为什么multi-line string literal Java 还没有?
问个指针array 的简单问题
问两个C++语法问题
请教C#里property的意义
Getter and setter methods are evil
char *p = "string literal"; 和 char a[] = "string liter (转载)
expression in Java
相关话题的讨论汇总
话题: complex话题: c++话题: literal话题: question话题: struct