logo
IRC Archive / Freenode / #c++ / 2010 / February / 02 / 2
TinoDidriksen
{ double x = 4294967296.0; cout << fixed << x; }
geordi
4294967296.000000
TinoDidriksen
Ah, it can hold that precisely.
Baughn
Naturally. It's a power of two.
tomalak
lul.
Baughn
Which also turns the division into a simple subtraction. I wonder if the FPU takes advantage?
armence
So is there any reason the constant won't work if I do it in hex?
TinoDidriksen
armence, hex constants are not double, and C++ doesn't support long long yet.
Baughn
Yeah, laziness on part of the C++ standard writers. :P
armence
TinoDidriksen, OK, I get it
Baughn
It would be nice to have a way of specifying floating-point values directly
..hex would pretty much do that
Cecen
Specifying floating-point values directly? :<
Baughn
Or at least making it easier to see how they're translated
Base-ten stuff is just awful. :/
Cecen
That seems really unsafe
tomalak
<< ETYPE(0x1.0p0)
geordi
rvalue double
tomalak
<< ETYPE(0x100000000.0p0)
geordi
rvalue double
Baughn
Cecen: Floating-point is standardized. C++ may not require that standard, but it's there anyway.
tomalak
{ double x = 0x100000000.0p0; cout << x; }
:)
geordi
4.29497e+09
Eelis
<< numeric_limits<double>::is_iec559
geordi
true
Baughn
..p0?
TinoDidriksen
0th power
tomalak
hexadecimal floating constant exponent suffix
Baughn
Ah
That's what I wanted. Guess we /do/ have it. ^^;
{ double x = 1p1; cout << x; }
geordi
error: invalid suffix "p1" on integer constant
Baughn
{ double x = 0x1p1; cout << x; }
Eelis
no idea if it's C++1x or just C99
geordi
2
tomalak
Baughn: test in #geordi please
Baughn
Roger.
tomalak
no, tomalak
Baughn
(Action) punts tomalak over to a barrel of phun
MikeMc68
What is the best way to put a delay into the code? I am looking at 100ms
Baughn
MikeMc68: Platform?
MikeMc68
osx
tomalak
no standard way
there are various sleep mechanisms in OS APIs
e.g. posix usleep, windows Sleep
tm604
probably one of usleep, microsleep, or nanosleep.
tomalak
ask in the relevant channel for specifics
Baughn
Calling select with no FDs and your timeout is about as portable as it gets
..if you want it to work on really ancient stuff
(Action) thinks even windows manages that one
MikeMc68: Besides that, usleep.
MikeMc68
ok i'll try usleep - thanks
coldpizza72i
hey
http://cimg.sourceforge.net/reference/group__cimg__overview.html ....on the bottom of this page it says you need a quite modern compiler; does this mean code:blocks is not sufficient enough
gparent
code::blocks isn't a compiler.
problem solved
Cecen
How long until we get uint128_t
coldpizza72i
gparent i mean the compilers that are in code:blocks
gparent
I don't know what compiler is in code::blocks
it depends on your computer
TinoDidriksen
C::B on Windows uses ooooold MinGW with g++ 3.4.5
coldpizza72i
linux
TinoDidriksen
Then it uses whatever g++ you have
coldpizza72i
o
MikeMc68
ok microsleeo and nanosleep don't work
usleep does but any number i put in the brackets makes no difference
Cecen
(Action) reminds everyone that MSVS is the only IDE that should be used on Windows.
coldpizza72i
see im trying to run cimg's helloworld but i get a bunch of build messeges
TinoDidriksen
Cecen, Qt Creator will also do.
Cecen
If you need to sleep, grab Boost.Thread
coldpizza72i
that apear to be problems with the header
gparent
Cecen: I suggest a bed myself.
Cecen
Beds are okay too
(Action) builds Boost.Bed
gparent
rof
l
alpha
hi
has anyone tried miniLZO compression lib? i cant find any examples..
TinoDidriksen
alpha, so use a more widely used library.
alpha
TinoDidriksen: for example?
TinoDidriksen
zlib, 7zip
proton23
Hi! sprintf is C, right?
FauxFaux
Yes.
proton23
what is the C++-function for this?
FauxFaux
!give proton23 converting
nolyc
proton23: converting is done with std::stringstream http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.1 http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2 or with boost::lexical_cast http://www.boost.org/libs/conversion/lexical_cast.htm
Xorlev
You can use sprintf if you include cstdio.
proton23
ahhh maybe that's the problem
TinoDidriksen
boost::format is also good.
proton23
but shouldn't I get a compiler error without the headerfile?
Hi Tino! :)
sobber
proton23, In c++ you would usually use std::cout though, instead of printf.
proton23
including cstdio did it
thanks
deathanatos
If I have template<int I> -- can I restrict that I to < something ?
coppro
deathanatos: you can with enable_if
yuriks
Is there any way to do named constructors with non-copyable objects
?
dhrosa
are there such things as unnamed constructors?
yuriks
dhrosa: named constructor idiom =P
chris_
I am trying to learn c++ coming from java, and one place where I am getting hung up is with the stack vs heap
ville
didn't someone already answered this last night
chris_
I am a little confused on how to make an array of objects on the stack
ville
chris_: you can only do it if the number of elements is known at compile time
chris_
ahh... ok
ville
chris_: any C++ book ought to show this.
!give chris_ ac++
nolyc
chris_: Accelerated C++: Practical Programming by Example", Andrew Koenig, Barbara Moo, Addison-Wesley, 2000. ISBN 0-201-70353-X. http://www.acceleratedcpp.com/
chris_
thanks
yuriks
geordi: { Foo init = Foo::makeMe(); } class Foo : noncopyable { Foo& makeMe() { return Foo(); } private: Foo() { } };
geordi
error: expected class-name before '{' token
yuriks
geordi: replace noncopyable by boost::noncopyable
geordi
error: invalid initialization of non-const reference of type 'Foo&' from an rvalue of type 'Foo'
yuriks
ok, this
geordi: remove : boost::noncopyable
geordi
Same error.
yuriks
erm, what
TinoDidriksen
geordi: add & after first Foo
geordi
Same error.
TinoDidriksen
geordi: show
geordi
{ Foo& init = Foo::makeMe(); } class Foo { Foo& makeMe() { return Foo(); } private: Foo() { } };
TinoDidriksen
Oh, it returns a temporary
ville
it would need to be static too or use an instance.
yuriks
oh, right, forgot static
geordi: make Foo::makeMe static
geordi
error: Could not find free declaration of Foo::makeMe.
yuriks
bah XD, let's try again
geordi: { Foo init = Foo::makeMe(); } class Foo : boost::noncopyable { static Foo& makeMe() { return Foo(); } private: Foo() { } };
geordi
error: invalid initialization of non-const reference of type 'Foo&' from an rvalue of type 'Foo'
yuriks
geordi: remove : boost::noncopyable
geordi
Same error.
yuriks
geordi: show
geordi
{ Foo init = Foo::makeMe(); } class Foo { static Foo& makeMe() { return Foo(); } private: Foo() { } };
yuriks
so this still isn't working
TinoDidriksen
{ Foo init = Foo::makeMe(); } class Foo { static Foo makeMe() { return Foo(); } private: Foo() { } };
geordi
error: 'static Foo Foo::makeMe()' is private
TinoDidriksen
{ Foo init = Foo::makeMe(); } struct Foo { static Foo makeMe() { return Foo(); } private: Foo() { } };
geordi
<no output>
jonrafkind
i have 'friend int ::main(int, char**);' inside a class, which itself is inside a namespace, but gcc gives me this error: error: int main(int, char**) should have been declared inside ::
how am I supposed to declare main as a friend to the class?
TinoDidriksen
jonrafkind, why do you need main to be a friend? That sounds wrong design...
jonrafkind
yea yea I know
but do you know how to get around it?
the point is so I can have a singleton where only one instance can be created by main()
TinoDidriksen
...and you want a singleton too!
Double-plus ungood
Anyway, forward declare main()
jonrafkind
ah ok
yuriks
TinoDidriksen: oh, right, I suck at geordi
ok, so that works
geordi: add `: boost::noncopyable` after `struct Foo`
geordi
error: 'noncopyable_::noncopyable::noncopyable(const noncopyable_::noncopyable&)' is private
yuriks
ok, so yeah, that
is there any way to do that?
so, is there any way of doing the named constructor idiom with noncopyable objects?
(except C++0x move constructors)
fernandes-
geordi: show
geordi
{ Foo init = Foo::makeMe(); } struct Foo: boost::noncopyable { static Foo makeMe() { return Foo(); } private: Foo() { } };
fernandes-
geordi: add & before init
geordi
error: 'noncopyable_::noncopyable::noncopyable(const noncopyable_::noncopyable&)' is private
coppro
yuriks: yes
use a different type for the named constructor
oh wait, I see what your issue is :/
just initialize with (), not =
fernandes-
but it has no def constructor?
yuriks
geordi: { Foo init(Foo::makeMe()); } struct Foo : boost::noncopyable { static Foo makeMe() { return Foo(); } private: Foo() { } };
geordi
Same error.
yuriks
it works in msvc++, atually
fernandes-
it's a copy in either case (= or ()) right?
yuriks
shouldn't it RVO?
ville
the C++ standard requires the thing to be copyable, even if no copy occurs.
yuriks
bah
I could return a pointer... but returning a pointer ot a subsystem, meh
to*
ville
why do you need to return a pointer? make a facade.
sleepster
is there an easy way to determine whether an ulong to int conversion is going to overflow?
freeone3000
std::numeric_limits<int>::max will give you the maximum value of the int. Compare the current value of the ulong to that.
sleepster
thanks freeone3000
[o
<< std::numeric_limits<int>::max
geordi
0x80486fd
[o
<< std::numeric_limits<int>::max()
geordi
2147483647
[o
<< std::numeric_limits<unsigned>::max()
geordi
4294967295
[o
<< std::numeric_limits<int64_t>::max()
geordi
9223372036854775807
[o
so huge...
d1zzy
and yet so small
Love4Boobies
can anyone explain to me why in http://en.wikipedia.org/wiki/Operator_overloading they define the parameters of the operator with a & at the end?
Terminus
Love4Boobies: because the parameters are references
Love4Boobies
i see. why so?
braden
Love4Boobies: In that case, because it's cheaper than making a copy.
Terminus
Love4Boobies: for objects, it's more efficient to pass a const reference than to make a copy.
Love4Boobies
ah, i didn't know it'd make a copy
thanks
it's 7:25 AM here btw
braden
Love4Boobies: C passes everything by copy. C++ gives you references.
Love4Boobies
wrong channel
yes, i understand now