« first day (668 days earlier)      last day (2175 days later) » 
00:00 - 23:0023:00 - 00:00

12:42 AM
Should non-getter const member functions be avoided because if the function isn't modifying the class's member variables, then it is likely some utility function and shouldn't belong in that class in the first place?
 
1:02 AM
@nobism Depends, for example, shape.getBoundingBox() const is a reasonable use of a const member function. I wouldn't call it a getter because you might need to do real computation to get the bounding box.
Things like .toString() also come up
 
1:29 AM
@Mikhail Ah ok, I gotcha. I forgot about that, that you may want to compute something before you return it, good point.
 
 
7 hours later…
8:13 AM
should a returned static value_type& become garbage?
 
nwp
Can you be more specific what you mean?
 
I declare a variable like this: static value_type& foo = some_value', and I pass it to return, whose type should be value_type&`
where value_type is a template's type
when I look at the return value, sometimes it is garbage, sometimes it is not
 
nwp
Well, valuetype is now a reference to some_value. If some_value disappears then you get a dangling reference.
 
so what really confuses me is how it sometimes still exists but at other times it is garbage
 
nwp
Because it's undefined behavior. C++ doesn't check for every object if it may have disappeared in the meantime because that is way too complicated and slow, so it just assumes the object exists without checking. Usually when an object gets destroyed the memory is not changed, so you can still access the same memory. Until some other object needs space and overwrites the old data, in which case you get garbage.
If you are on not-windows sanitizers can help you catch those problems because they do some object lifetime tracking and tell you when you access something you shouldn't have, even though the memory hasn't been re-used yet.
On windows I'm not sure what the best course of action is. VS has a code analysis tool that sometimes finds some problems.
 
8:27 AM
well, here is the thing, I store the value_type values in instances of Node, what my code does is get the stored value of a Node and deletes it, to free up memory. Is this the cause of my issue?
 
nwp
Well, if you delete the thing you are referencing and later accessing then that is a problem.
 
so how do I copy the stored value properly so that I can delete the node?
 
nwp
You make value_type not a reference. Or you make some_value static.
Hard to tell without seeing the code and knowing why you need value_type.
 
Ron
Should I prefer the std::begin(v) for appropriate containers over member fn v.begin()?
 
making some_value static causes two undefined references
 
Ron
8:34 AM
And std::end.
 
nwp
@micsthepick Well, define those variables. But it kinda sounds like you are misunderstanding what static does.
@Ron I don't know. I was told by "effective modern c++" that you should generally use the non-member version because it allows you to add those functions to containers that don't have them, but in practice that has never come up. Maybe they will remove that distinction at the language level some day.
 
Ron
Awesome, thanks.
 
the error looks like this:

GradesDemo.o:GradesDemo.cpp:
(.text$_ZN4NodeIiEC1EiPS0_S1_[__ZN4NodeIiEC1EiPS0_S1_]+0x7): undefined
reference to `Node<int>::stored_value'
GradesDemo.o:GradesDemo.cpp:
(.text$_ZN4NodeIiE9get_valueEv[__ZN4NodeIiE9get_valueEv]+0x4): undefined
reference to `Node<int>::stored_value'
collect2: error: ld returned 1 exit status
 
nwp
10 mins ago, by nwp
@micsthepick Well, define those variables. But it kinda sounds like you are misunderstanding what static does.
 
so I have no idea what the problem is
static makes the variable have a fixed address
 
nwp
8:47 AM
Yes, but you only have a declaration for that variable. You still need a definition. Something like template <class T> Type Node<T>::stored_value;.
 
I thought I programmed it so that the variables are defined in the constructor?
does that not work for static?
 
nwp
It looks like you have a static variable in a class. That is one per class. Constructors work per object, not per class, so they can't initialize static class objects.
 
i.e. per instance?
 
nwp
The constructor is per instance of the class, yes. The static variable is global for the whole class, so it can't be in the instances.
 
so can I just create a new copy of the value_type, if so, how do I get a static reference to it?
 
nwp
9:01 AM
Can you show the code you have so far? Ideally only the piece that has the undefined reference issue.
 
the undefined reference issue only occurs when I make the stored_value of Node static
what I wan't to do is static value_type& return_value = value_type(tail->get_value())
but I can't go straight from the rvalue into the variable
 
@Ron It's the usual "genericness over convenience" thing.
Similarly how &x is less generic than std::addressof(x) which itself is less generic than ::std::addressof(x)
You have v.begin() which is less generic than std::begin(v), which is less generic than using std::begin; begin(v)
 
nwp
@micsthepick Well yeah, the right side is a temporary that will disappear immediately, so a reference to it would immediately become invalid. You can either make it store the value using static value_type return_value or use the lifetime extension and do static const value_type& return_value which has essentially the same effect, except you cannot change return_value anymore.
 
I tend to avoid the more generic forms unless I need to, because they're annoying to write
 
what if I define duplicate (as static value_type), and then pass duplicate to return_value?
(or maybe I could even bypass the variable return value, and feed it straight to return)
 
nwp
9:14 AM
I still feel you don't actually want any static variables and references. Try if it just works out without them.
 
waffles
great, now it just straight up segfaults
 
nwp
That's not so bad. Debuggers are pretty good at stopping at those and letting you check the call stack and variable states to see how it happened.
 
I don't have an IDE or a debugger :/
 
nwp
Get one. They are useful.
 
right now, I am compiling and running under cygwin
with g++
 
nwp
9:24 AM
It probably comes with gdb.
 
maybe if I had known to install it, I could have got gbd when I installed cygwin, but right now it does not have dgb
 
nwp
You could try onlinegdb.com but it's much less convenient than doing it locally.
 
9:47 AM
this is so weird
the code crashes on a return statement where I just return a variable
but including a cout statement somehow makes the code run longer, and then it crashes on that new statement
 
nwp
The cout statement happens to prevent the deleted variables being overwritten for a little while. That's a bad thing because it hides a bug. You really want it to crash as early as an error happens.
 
so this is without static or references
the crash occurs when trying to access a node's value
this time, before it is deleted
 
nwp
You are probably accessing that value through a pointer and the pointer got invalid somehow.
 
wait, this is equal to null?
how on earth?
 
which is the best and simple library for graphics in c++?
 
nwp
9:56 AM
What kind of graphics? User interfaces, 2D shapes, 3D shapes?
 
I want 3D shapes.
 
nwp
Then you basically gave up simple already.
Unity is probably worth looking at.
At least if you want to make a game.
 
so I think the reason the cout statement showed more output is as it added newline characters?
 
Ron
@milleniumbug I see.
Going through the core guidelines. Chances are I will speed up the process.
Quite difficult reading. Not due to complexity but the writing style. Bjarne comes to mind.
 
 
1 hour later…
11:30 AM
so how do I make a variable so that I can replace a class object's attribute with that variable, and it does not get deleted?
 
11:49 AM
@micsthepick have you asked on Stackoverflow showing what you've tried so far?
 
nope
but I did just find a way to do what I wanted to do
 
 
2 hours later…
Ron
1:41 PM
Here goes nothing: how to keep pressing on in the C++ direction?
After getting the basics right, dos and donts, few books, IsoCPP super faq etc, then what?
What would you guys do? Or have done?
 
start a project
 
Ron
That sounds great.
 
one option would be getting to do standardization effort, interacting with other people on mailing groups (std-proposals and like), becoming a committee member or stuff like that
 
heh, like few books, e.g. stroustrup, sutter, alexandrescu, williams, vandevoorde
And the isocpp thing
There's few to know about C++ above all of this to my mind :)
 
another one would be to just write code
 
Ron
1:49 PM
Sounds good. Appreciate it.
 
Guys
Before I make myself dig further into cppreference and such matters, can someone easily explain what's the crux of deduction guides?
I mean, I've read something about them, but for now, they only seem to be a disambiguation for a template parameter of the "constructor return type"
Are they useful for anything else? :)
 
nwp
2:03 PM
The basic usage is Type(Parameters) -> Type<TemplateArgs>; to deduce the TemplateArgs from the type of the Parameters so you don't need to do std::mutex m; std::lock_guard<std::mutex> lg{m}; anymore.
Because it really should be std::lock_guard lg{m};. But that didn't compile previously because std::lock_guard is a template and requires template parameters.
 
2:19 PM
Can it help deduce anything other than 'TemplateArgs'?
 
nwp
What else can you deduce besides template arguments?
 
overloads
 
nwp
You can't change the arguments that will be passed to the constructor.
 
well.. ok, I can't come up with anything besides the straight TemplateArgs of the Type<TemplateArgs>
thanks
 
Ron
2:37 PM
Where to keep freestanding functions in terms of working with multiple headers and source files?
Put the entire definition inside some namespace in a separate source file or be normal and separate into declarations and definitions?
 
 
3 hours later…
5:14 PM
@Ron What do you mean? Usually, if the declaration and definition can be separated (i.e. not a template or trivial inline function), I'd split them, to help with compile times (reduce what has to be recompiled when I make a change)
 
In this example, the std::swap does its job, but I can't see how, I thought std::swap calls move constructor of A, but here, -as "A move ctor" isnt printed- I guess, it doesnt. What is happening here?
 
@MuhamedCicak because you're swapping the vectors, not the elements
 
@Mgetz How come it still works then? They actually get swaped (the elements).
Oh wait, so v2 only takes v1's elements without actually touching anything in those elements? And vice versa.
 
@MuhamedCicak Because when you swap the vectors they trade internal state
they don't need to recreate it, just... swap
 
@Mgetz If so, the type of the elements doesn't matter?
 
5:26 PM
you can only swap two vectors of the same type
 
@Mgetz Sorry, let me clarify the question, I meant the same types, there is no difference if I do it for A or B, no matter how more complex B is. If those two were vectors containing B's I mean. The swap would still work, no matter how more complex B type is, right?
 
@MuhamedCicak correct, the type of the vector is irrelevant AFAIK.
 
@Mgetz Okay. Thank you :)
 
@MuhamedCicak think about what a vector is internally... it is a pointer and a size. All that's happening is you're swapping the pointers and the sizes
(it's actually more complex than that but fundamentally it's close enough)
 
@Mgetz Yeah. I thought so, but just wanted to make sure.
 
5:31 PM
std::string is more complex because it uses the small buffer optimization
and there are vector implementations (non-stdlib) that do that
for example LLVM has a vector implementation they use internal to the compiler they do that with
 
5:48 PM
@Mgetz is there something in the standard prohibiting small buffer optimization for vector?
 
> Because the copy deduction candidate is typically more specialized than a wrapping constructor, this rule means that copying is generally preferred over wrapping.
WTF is a wrapping constructor?
46
Q: May std::vector make use of small buffer optimization?

Johannes Schaub - litbI was wondering with my colleague today whether std::vector can be implemented to make use of small buffer optimization. By looking into the C++11 draft, I read at 23.3.1p8 The expression a.swap(b), for containers a and b of a standard container type other than array, shall exchange the valu...

probably this
However LLVM has SmallString as well, they just want to make sure I guess
 
one line to save/ruin the day
 
@Incomputable vector has a lot of strong exception guarantees (to the point of stdlib maintainer frustration apparently)
 
@Incomputable I didn't understand this if anything :D
 
IIRC string was added first, STL came later, thus string was kind of left out from love?
@ledonter "unless otherwise specified" did the job with string. That's the "one line" I was talking about
 
5:54 PM
ok)
 
@Incomputable no string isn't a generic templated container. It's fundamental types are all primitives
thus the operations it needs to preform are less constrained than vector
 
I see. So nobody still needed specialization of vector for ints or doubles? I believe the most used vector element type are ints, doubles, and strings, and vectors themselves
 
@Incomputable um... no the most used specialization of vector is.. oh right anything
there is no reason to do a custom specialization of vector for int, the only one that needs a custom specialization is vector<bool> and that's because it's not really a vector
 
the black sheep
 
The poorly named and performing bitset
 
5:59 PM
I found that clang 6 handles exceptions better than gcc 7, but both are still abysmally slow. I couldn't find any other way to return from two functions at once
 
Um, I had a question, I'm writing this code: https://hastebin.com/qutuwayozu.cpp

And I want to get away from using the raw pointers, would a unique_ptr be a better idea, and if so how exactly/what would I change to use it?
 
@Incomputable don't use exceptions for control flow
 
@Mgetz I could use goto, but I can't. The thing is templatized
 
@Annabelle std::unique_ptr<GameState> thisState; and then in the constructor initializer list std::make_unique<GameState>
 
? Yes the std::unique_ptr but I'm not sure how I would um change the stuff around in:
 
6:02 PM
@Annabelle I believe you're holding the stick from the wrong end. Writing something too abstract right away is rarely productive
 
GameStateMachine::changeState(GameState& newState)
Oh hmm..
@Incomputable I was just trying to make it cleaner/easier for me later on.
 
@Annabelle is GameState shared between components or does one component own the state?
 
GameState is a class that the states inherit from
It's um an abstract class
 
@Annabelle unique_ptr does that, it eliminates any need to write a destructor
 
class GameStateMachine;

class GameState {
public:
// When we enter the state.
virtual void enter(GameStateMachine stateMachine) = 0;
// When we update it.
virtual void update(GameStateMachine stateMachine) = 0;
// When we exit state, clean up.
virtual void exit() = 0;
};
 
6:04 PM
@Annabelle when do you call exit?
 
@Mgetz is that Herb Sutter?
 
When changing states @Mgetz
 
@Incomputable yes...
@Annabelle consider using a wrapper that ensures exit is called before leaving scope
 
Okay I think I understand enough now
I'll try implementing it
 
it doesn't hold an owning reference but it would call exit from the destructor
 
6:05 PM
@Mgetz, it was weird that he didn't give a talk on ACCU 2018
 
@Incomputable he has a day job and works on the C++ committee
 
should I cal C++17 modern C++, or post modern?
 
@Incomputable modern
post modern is haskell
 
@Mgetz shots fired
 
I don't get what you mean by std::make_unique<GameState> in the initializer list.
 
6:08 PM
@Annabelle that's a function which creates std::unique_ptr for you. The thing in <> is the type you want, and the arguments you pass in are arguments to the constructor of type in <>
 
       // Constructor.
     GameStateMachine::GameStateMachine()
     :thisState(std::make_unique<GameState>()) {

     }
@Annabelle tbh I'm thinking GameStateMachine shouldn't own the game state anyway...
but that's me
 
// Constructor.
GameStateMachine::GameStateMachine() {
	thisState(std::make_unique<GameState>());
}
That's the same thing, right?
 
@Annabelle no
initialization and assignment are different things in C++
the version you've written won't compile
 
@Annabelle No, that occurs after initialization but before construction finishes, if the std::make_unique fails your object won't get deconstructed
 
the initializer list initializes things, to avoid redundant default construction
 
6:11 PM
generally speaking you want to construct as much of your object during initialization as possible
 
Um can I get an analogy if you don't mind?
It's kinda confusing just reading the documents
 
during initialization nothing exists
after initialization the default constructors of everything have been called
so you then trigger another initialization of things you didn't initialize originally
I never said I was a good teacher
 
@Annabelle why don't you join cppslack? They have learn channel, they might give better explanation
@Mgetz, I feel you bro
 
@Incomputable don't assume gender, this is the internet
 
@Mgetz IIRC bro doesn't assume gener either. I've seen it applied for women too, so I guess it is gender neutral
 
6:16 PM
riiiight
 
@Annabelle I believe I found the right one. Imagine you're building a box with a lid. Instead of putting items before screwing the lid, you screw the lid, unscrew it and then put items and then screw the lid again. <- this is the assignment case
with initialization, it is like putting items right away and screwing the lid once
 
Okay
 
does it make sense?
 
Yes
 
do you know what SomeType variable = SomeType(args) do?
 
6:21 PM
Creates something on the heap...?
no that's with new keyword
Not sure then
 
@Annabelle not only. Heap is a storage type, which standard refers to as free store
the expression I've written invokes a copy constructor
even though it has = in it
some people think that if = is present, then it is automatically assignment
 
@Incomputable actually it doesn't
guaranteed copy elision
 
@Mgetz after C++17!
 
and even before that initial conversion of a prvalue to an lvalue didn't result in a copy
 
was it standard? I believe that if SomeType doesn't have copy constructor, it won't compile?
 
6:23 PM
so unless you're compiling with -std=C++98 that won't copy
@Incomputable in old versions of MSVC yes... but not in anything new
most compilers recognized you didn't need that and optimized it away
 
I believe it was used more often when new version of auto came around
I wonder what register keyword will be used for
 
@Incomputable no, because doing auto foo = bar() won't trigger a copy of bar
 
@Mgetz so auto has different rules for the expression?
 
@Incomputable it won't, it was ignored and is ignored in all compilers anyway
@Incomputable no it doesn't that's the whole point, the only thing auto does is deduce the type
 
@Mgetz I watched that. I remember the joke about forks
 
6:28 PM
Code breaks x.x
 
@Annabelle, as you can see, the best way to learn C++ today is by watching lectures and talking to people like Mgetz
 
yeah that first lecture is fantastic
 
@Annabelle breaks is quite overloaded word :) if you're not in a dependency hell, I guess there is a way out
 
I feel like i'm missing some unique_ptr stuff
 
@Annabelle don't pass around smart pointers
only pass a smart pointer when you're passing ownership
use the smart pointer to hold
then call .get() to get access to the raw pointer when passing it in non-owning contexts
 
6:31 PM
I asked about ownership semantics like 20 students, and nobody had any idea what I was talking about
 
I don't think I'm passing ownership except um
thisState = std::move(newState);
 
@Annabelle you shouldn't need to use move here...
post your code please
 
Hmm
 
you should have one place in your entire codebase you're doing std::unique_ptr<GameStateMachine>
when you pass that value to something else you use .get() to get the raw pointer
 
Oh... hmm
It's probably very messy/hard cause this stuff is really confusing to figure out
 
for what it's worth if(thisState != nullptr){ is unnecessary unless someone passed you an invalid state
 
@Annabelle ownership semantics is one of the pillars modern C++ stands on. If you'll grasp it once, you'll have easier time in the future
 
  std::unique_ptr<MenuState> menu = std::make_unique<MenuState>(myWindow);
  game.changeState(std::move(menu));
should be:
game.changeState(std::make_unique<MenuState>(myWindow));
 
What is the difference?
 
6:37 PM
you don't need to do the move because it's already an rvalue
 
@Annabelle technically none. It's just shorter
 
e.g. a temporary
~GameStateMachine() {}; is not needed
 
Okay.
 
@Incomputable not technically true, when menu (or the swapped version that happens from the move) gets destructed changes
that's your guide to crap you don't need to write
 
Thansk!
Saved it
How do I fix/change:
if(thisState != nullptr){
thisState->enter(*this);
}
The thisState->enter(*this); breaks with the unique_ptr etc
 
6:41 PM
@Annabelle virtual void enter(std::unique_ptr<GameStateMachine> stateMachine) = 0 should be virtual void enter(GameStateMachine& stateMachine) = 0;
you want to pass in a non-owning reference
again... only ever pass in a smart pointer if your changing who owns that item
 
Okay fixed that
I have two errors it seems now:
 
@Annabelle, inside std::make_unique<>, put the derived class
 
@Annabelle update menustate and graphicsstate
@Incomputable no that's not the issue
the issue is the implementations no longer match the base
 
@Mgetz well, isn't it the same as putting the right derived class?
 
MenuState doesn't show any errors or anything
// Game State Header.
#include "GameState.h"
// SFML Headers.
#include <SFML/Graphics.hpp>

class MenuState : public GameState {
private:
	sf::RenderWindow *gameWindow;
	sf::Text text;
	sf::Font font;
public:
	// Constructor.
	MenuState(sf::RenderWindow *window);
	// Destructor.
	~MenuState();
	// When we enter the state.
	void enter(GameStateMachine& stateMachine);
	// When we update it.
	void update(GameStateMachine& stateMachine);
	// When we exit state, clean up.
	void exit();
};
 
6:50 PM
@Incomputable does MenuState implement void enter(GameStateMachine& stateMachine) override final
 
Yes it's implemented
 
ah right I'm an idiot get rid of : thisState(std::make_unique<GameState>())
you can't have a default state of something that doesn't exist
that said... I'm still thinking you don't want GameStateMachine to own the gamestates
because that means they get destroyed when you change state
 
Right!
I don't want them destroyed.
How do I fix that?
 
yeah.. use smart pointers in your main... but a non-owning pointer inside GameStateMachine
that way they live until the end of main
 
@Mgetz, thanks for educating me along with Annabelle
 
6:55 PM
41 mins ago, by Mgetz
I never said I was a good teacher
 
Well I never wanted the state to be destroyed
And I want to be able to go from one state to another
from within a state
So how do I go about that?
For example menuState might call playState
and go to that, and I still want menu there? idk
 
looks like circular references
 
7:17 PM
@Mgetz Thanks for all the advice! I'm gonna go finish listening to that first lecture now. (Sidenote: C++98 and C++11/14/17) are very different, but also easier to use now.
 
@Annabelle have you seen this? It looks like selling out and refilling matches your need of ping-ponging between states
the gist seems to be holding some common data of states
 
7:34 PM
Saw it but don't really understand it.
Might try this:
19
Q: Game state management techniques?

vargonianFirst off, I'm not referring to scene management; I'm defining game state loosely as any sort of state in a game which has implications about whether or not user input should be enabled, or if certain actors should be temporarily disabled, etc. As a concrete example, let's say it's a game of the...

 
7:47 PM
Yo guys! How do floating point literals work? I just read some article which basically claimed that 1.3f may not compare equal to (float)1.3f under some circumstances. If this is true, I am not sure what I can believe in anymore. I mean, isn't the type of 1.3f already float? How would casting to float change the result if it does not do anything? What would be the point of the f if it might not do anything?
 
stop right there, and enjoy the vaning years of your life when you did not know about floating point arithmetics
 
the point is, I do know quite a bit about floating point arithmetics
 
yeah, I think I misread / read too fast your message :)
 
That's why I'm so baffled
lol
ah I forgot the article: nullprogram.com/blog/2018/05/01 and here is some relevant discussion: news.ycombinator.com/item?id=16974770
Someone quoted C99, 6.3.1.8.2: "The values of floating operands and of the results of floating expressions may be represented in greater precision and range than that required by the type; the types are not changed thereby."
But wouldn't that be also true for (float)1.3f just as well=
?
I am not sure what to believe in anymore...
 
Maybe it's just me being dumb, but isn't "The original ANSI C specification wasn’t clear about how intermediate floating point values get rounded, and implementations all did it differently." the gist of the matter?
 
7:54 PM
I think the behavior holds for newer implementations just as well, it just depends on FLT_EVAL_METHOD being set to 2 if I understand that correctly
But I also was not able to reproduce this behavior so I am doubly uncertain
I mean I also don't quite understand the concept of a result of some expression having higher precision than its type... It all just does not make sense to me tbh
 
nwp
8:42 PM
Typical machines have 80 bit floating point registers which is much more than the 32 bit float or the 64 bit double in order to reduce the impact of rounding errors.
So if you make a calculation you get different results depending on the precision used and the standard says that is allowed.
So when you have an expression such as 1.3f it cannot be represented in floating points of any precision. The machine is allowed to use the closest 80 bit value to 1.3 instead of the closest 32 bit value to 1.3 in order to reduce rounding errors.
@purefanatic Does that make sense?
 
on my end, it sure does. ta
... so... is Boost c++'s npm?
 
Well no, not really. I wrote the f for a reason. Now C++ says lol haha I'll give you a value that has the type float but is not actually a float, it's of higher precision
That's just stupid as fuck
 
float by itself is not a precision though, is it?
or is float always 32 bits, and 64 bits is refered to as double?
 
that's the case for IEEE-754 at least
or not, as we see in the case of 1.3f
which appears to be of type float, but isn't
I'm honestly considering just giving up on C++ right now
 
nwp
@purefanatic One could argue that spending processing power to give you a value with less precision is stupid as fuck. Just take the high precision value and be happy about it.
 
8:55 PM
Yeah but why is it not of the correct type then?
It just does not make any sense!
 
nwp
@purefanatic It is of the correct type. It explicitly says "the types are not changed thereby" in your quote.
@purefanatic That's not enough. Floating point arithmetic works the same in all sane languages which is how processors work. You need to give up on programming altogether to escape it.
 
That's my whole point!
 
or use slow arbitrary precision libs
 
No it does not, not even in C++, where floating point arithmetic seems to be dependent on some mysterious constant named FLT_EVAL_METHOD
Besides, I would not call C or C++ sane for various reasons, but that's not the point.
Let me elaborate on what I would call sane.
 
nwp
The core idea is that when you say "1.3" they assume you mean "1.3", not "1.3 rounded to some precision". The loss of precision is unfortunately not avoidable, but you try to minimize it.
 
9:01 PM
@purefanatic en.wikipedia.org/wiki/IEEE_754 seems to consider all floats, be them encoded in 16, 32 or 64 bits, as floats.
 
@FĂ©lixGagnon-Grenier I know floats, I just can't stand their handling in this language.
 
it just seemed to me that part of your furstration was in the passage from "float" to some other type of different precision, whereas I am trying to express that this passage is not really there; it's all float
 
@nwp Then what is the core idea in the f of 1.3f? Isn't it to give control to the programmer?
 
nwp
@purefanatic It says that you want a float. Which is relevant for implicit conversions and overload resolution. It doesn't mean you must suffer from loss of precision.
 
because 1.3 is a double the f means to keep it a float
 
9:05 PM
Well ok, but isn't "wanting a float" and "suffering from loss of precision" the same thing?
I would have wrote 1.3 if I wouldn't want to suffer from loss of precision
 
nwp
@purefanatic You still suffer from loss of precision, because you can't accurately represent 1.3 in a double either.
@purefanatic Ideally no. Ideally you use exactly 1.3 without any rounding and just specify the storage size.
Compilers try really hard to keep floats in registers and not put them into memory in order to avoid rounding.
 
How would that make sense? You seem to suggest that load and store instructions did floating point conversions
 
floats are faster compared to doubles though, which is why a lot of games will use single precision over doubles
 
other than addressing, memory and registers are the same for the CPU
 
not really, for one there are simd registers where you can do math on 4 floats at a time
 
nwp
9:13 PM
@purefanatic Well no, registers are much more limited. You got to use the registers you have, and sometimes you only have 80 bit floating registers.
 
@purefanatic This passage exists because 32-bit x86 has 80 bit float registers. There, given floats x, y, z, an expression x + y + z loads 32 bit values into 80 bit registers, sums them and only when storing in a variable, truncating them into 32 bit register
Obviously, this doesn't apply on any other platform, so the problem is trivially solved by only supporting 64-bit x86 and everything else except 32-bit x86
Also, this isn't language specific. You'll have this problem in Java, C#, D and Python too
 
all of them compile down to (mostly) the same machine code
 
Also, 1.3f and (float)1.3f will result in the same value
 
No.
Which is the reason I find this whole thing so unintuitive and bad
 
You're wrong. (float)1.3f is identity conversion (i.e. no-op)
 
nwp
9:16 PM
@purefanatic I'm fairly sure that just says that (float) must make the type a float. It doesn't say it must round.
 
I am still not sure this applies. How and where would float x = 1.3f differ?
Obviously, a conversion must take place, or not?
 
1.3f is a float and x is a float
so no
 
So you say my float x might be of higher precision than single? Do you at least understand my problems with this stuff?
 
nwp
One thing that could happen is that float x = 1.3f; puts the 32 bit rounded value into memory. Then doing x == 1.3f returns false because the left side is a 32 bit precision 1.3 promoted to an 80 bit precision float while the right side is an 80 bit rounded 1.3.
 
9:25 PM
Actually no, I'm not saying anything. I'm saying you're wrong
x is always a float
 
nwp
Another thing that could happen is that the compiler is smart and optimizes out x and just returns true.
 
it doesn't have magical bit patterns stored anywhere else
See it that way: I followed your link (eel.is/c++draft/expr#footnote-62), and it proves nothing
> An expression e can be explicitly converted to a type T if there is an implicit conversion sequence from e to T
 
Yes.
 
> The three forms of implicit conversion sequences mentioned above are defined in the following subclauses.
> No conversions required
regarding HN discussion, the comment that implied that float x = 1.3f; assert(x == 1.3f); may fail was immediately corrected by another one
 
Hm, so you mean the original article is also incorrect, which claims to have tested the code with GCC 7.3.0?
Because that would be very reassuring
 
9:37 PM
GCC tends to be buggy in the first place
Also, again, if you don't target 32-bit x86, this is never a problem
the original article's "all did it differently" links to a HN comment page
also doesn't claim that its behaviour is standard compliant
 
Yeah I noticed that too ^^ Ok, this actually helps sootheing myself a little bit
 
10:08 PM
Well thank you guys for your time! I'll try to not be in such an angry mood next time I ask a question around here, saves nerve cells ;)
 
I have a case where I'm currently using std::shared_ptr.... I know a way to remove it in favor of std::unique_ptr, but I don't like the way it feels
 
10:29 PM
Here's a rough sketch of my model: pastebin.com/mpKrJKqv . Basically, I'm using std::shared_ptr for std::weak_ptr as a way to refer to the object and be able to ignore it if it gets deleted. But I could work around it by instead having someone else manage the ownership of the object, and the original shared_ptr would be a reference to it (with a hook to automatically release the object)
 
00:00 - 23:0023:00 - 00:00

« first day (668 days earlier)      last day (2175 days later) »