Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Avenging Dentist posted:

I doubt that the Source engine dictates that you use a language feature that does not exist.

He's got the x/y problem.

"I want to do X. I think Y is a good way to do X, so I'll ask how to do Y rather than ask how to do X."
e: :monar:

click

Adbot
ADBOT LOVES YOU

narfanator
Dec 16, 2008
While you could set up the new values to be equal to what they would be if included in the original enum, methinks you don't want to do that. I'm willing to bet "base_last" is used for bounds checking or similar activities elsewhere, which means, ideally, your new enums (which would presumably have values equal to existing ones, or be out-of-bounds) would result in warnings and errors, down to the worst case of OHGODDOOM.

e: I agree with Otto. But, Otto, what's with the OHGOD siggy?

huge sesh
Jun 9, 2008

The engine uses continuations of enums for a bunch of other things in the a.i. system and it works just fine. However, for activities using a different enum breaks this nested macro that I have to use:
code:
#define REGISTER_PRIVATE_ACTIVITY( _n ) _n = ActivityList_RegisterPrivateActivity( #_n );

#define ADD_CUSTOM_ACTIVITY_NAMED(derivedClass,activityName,activityEnum)\
	REGISTER_PRIVATE_ACTIVITY(activityEnum);\
	CAI_BaseNPC::AddActivityToSR(activityName,activityEnum);
        //static void CAI_BaseNPC::AddActivityToSR(const char* actName, int conID)

#define ADD_CUSTOM_ACTIVITY(derivedClass,activityEnum) ADD_CUSTOM_ACTIVITY_NAMED(derivedClass,#activityEnum,activityEnum)

#define DECLARE_ACTIVITY( id ) \
	ADD_CUSTOM_ACTIVITY( CNpc, id );

...


enum {
  ACT_WHATEVER = LAST_SHARED_ACTIVITY,
  ACT_TALK,
};

  DECLARE_ACTIVITY( ACT_TALK );
I get error C2440: '=' : cannot convert from 'Activity' to '' if I try to do that.

What is done elsewhere in the code is to declare the non-shared activity as an uninitialized int. Then the compiler doesn't know the value of the non-shared activities, so I can't, say, use a switch statement with different activities as cases.

I guess it was foolish of me to expect that there was some magic way to alias one enum onto another, but sometimes it seems like anything is possible with typedefs :)

ehnus
Apr 16, 2003

Now you're thinking with portals!

huge sesh posted:


What is done elsewhere in the code is to declare the non-shared activity as an uninitialized int. Then the compiler doesn't know the value of the non-shared activities, so I can't, say, use a switch statement with different activities as cases.

Sure you can, just handle the enum as an int

code:
enum A 
{
    ACTIVITY_1,
    ACTIVITY_2,
    LAST_ACTIVITY
};

enum B 
{
    ACTIVITY_3 = LAST_ACTIVITY,
    ACTIVITY_4
};

void themagichappenshere(unsigned activityType)
{
    switch (activityType)
    {
        case ACTIVITY_1:
            break;
        case ACTIVITY_2:
            break;
        case ACTIVITY_3:
            break;
        case ACTIVITY_4:
            break;
        default:
            break;
    }
}

YellowJello
Dec 9, 2008

I've just been assigned a project in my programming class and my professor tells the class that he is done teaching and everything else that we need to know is in the book. The problem is that the book explains it very poorly.

code:
A:	DEFINITION:	Mean, Median, Mode, Variance, and Standard Deviation.

	1.	Mean, or the average value, is the most important and commonly used measure of 
		central tendency. It is given as M = (x1+x2+x3+...+xn) / n.

	2.	Median  (of a sample) is the middle value based on order of magnitude.  For example, 
		the median of the following sample set {1 2 3 4 5 6 7} is 4. However, in the set 
		{1 2 3 4 5 6 7 8} either 4 or 5 could be used as the median.  In this assignment, 
		we use the first one.

	3.	Mode is the value that occurs most frequently.  There may be more than one mode.  
		For this assignment choose the first one found.

	4.	Variance is often used to reflect the scatter, spread, or dispersion of the data.  
		It is V = [(x1-M)2 + (x2-M)2 + (x3-M)2 + ... + (xn-M)2] / d
		Where d = (n -1) when n is large enough.  However, use d = n in this assignment.

	5.	Standard Deviation is the square root of the Variance.


B:	ASSIGNMENT:	Write a C program that uses the pseudorandom-number generator to find 
			the above five values according to the following steps:

	1.	The user enters a positive integer, say n, which is the size of the sample.  
		Assume that n is no greater than 50.

	2.	Generate n integers and use the remainder operator to have all these number 
		become no greater than 5.

B.1	Part I:
	3.1	Print out the n numbers followed by Mean, Variance, and the Standard Deviation.

B.2	Part II:
	3.2	Print out these n numbers in ascending order and followed by the five values 
		defined above in A.

	4.	Repeat step 1 through 3 until the n's value is outside the range of 1 and 50.

C:	NOTE:	Modulize your program.  Use functions for finding Variance and Mode, and for 
		printing the contents of the array.  

		To test the correctness of your program, use the following integer arrays 
		first before using the random numbers V1[]={1,4,2,1,1,2,2,2,3,5,5,0}, 
		V2[]={0,2,0,0,0,3,1,2,4,5,5,2}.
My question is if anyone knows the best way to do code like this. I've tried searching some stuff on Google, but nothing really helpful comes up. Also, if you notice any grammar or english problems in the assignment, it's because my professor is Chinese or something. You should be able to tell what he's saying.

*Sorry about the layout, but it's fixed now.

YellowJello fucked around with this message at 20:06 on Apr 8, 2009

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

YellowJello posted:

My question is if anyone knows the best way to do code like this. I've tried searching some stuff on Google, but nothing really helpful comes up.

This is a straightforward intro programming task. What have you tried? What are you having trouble with?

Section B of the assignment gives you a very good skeleton of what your program should do. Why don't you try writing the code for step 1, then the code for step 2, and so on, and ask us a question when you get stuck along the way?

agscala
Jul 12, 2008

if you're trying to interpret the questions, I interpreted them as such:

user inputs the size of the dataset, if it's > 50 or < 1, end.
make an array of psuedorandom numbers of the size the user specified, the integers have to be <= 5.
print the numbers out
print the numbers out, sorted
print mean, median, mode, variance, and standard deviation
break it into functions for printing stuff if you haven't done so already

Anything past this, you're on your own.

narfanator
Dec 16, 2008
The big questions are:

How am I storing my data?
When I need to pass my data, what form am I passing it in?
What tasks need to happen more than once?
What tasks need to happen more than once, but with differences?

The wrong answer for the first question is "A set of named integer variables". You're going to want to use an array, a vector, or, if you have some additional reason to do so, a class or struct that contains an array or vector as well as some other stuff. (Maybe you want to put your initial data, and your mean, etc, in one handy package.)

The second question comes up when you want to break your code up into functions ("modularize"); you'll need to get info from whatever function you're in, to the one you're calling, and back out again. You probably want to use whatever data type you're already keeping the data in, but maybe not.

The last two questions help you figure out what to turn into their own functions, rather than coding multiple times. You also might look up "functional programming" and "encapsulation" for more about the whys and wherefores for doing stuff in this way.

When you need to get them ordered, you want to look up sorting algorithms. The ones you're looking for are "Merge Sort" and/or "Quick Sort"; like most of CS, Wikipedia has decent articles on these.
Or you could use vectors and just use the standard library sort, but that's boring.

Oh! For the numbers, you want:
rand() - Produces a random number, between zero and toobigIdontcare. int val = rand() % range; is the typical usage.
srand() - seeds the psuedo random number generator. If you don't seed, every time you run your program, you'll get the exact same "random" numbers (which can be useful for testing). The typical trick is to do srand(time(NULL)); to use time(), include "time.h".

Chuu
Sep 11, 2004

Grimey Drawer
I am wondering if someone can gutcheck me and make sure I'm not doing something incredibly stupid here.

code:
blob* SomeClass::doSomething()
{
    ...code...
    return otherclass->doSomethingElse();
}


void SomeClass::~SomeClass()
{
}
doSomething() is one of the very few places in this program where performance is absolutely critical. This is also completely asynchronous but it's currently written to be thread safe.

The problem is with the destructor. If the class is destroyed when you're inside the doSomethingElse() call, you seg fault.

There are a lot of solutions to this problem, but the thing is this piece of code really is performance critical, and every trivial solution I can think of essentially requires a mutex to be checked sometime within doSomething() method. I really need to avoid that performance penalty.

The final solution probably involves counters which guarantee atomic operations, one implementation is this: this. On the platforms I care about the specialization ACE_Atomic_Op<ACE_Thread_Mutex,long> is implemented as hand-coded assembly and uses x86's atomic ops and should avoid most of the expense of a Mutex's context switch (can't really avoid using volatile variables though, oh well).

I'm not really sure how I would use this though. Something like this is the first thing that came to mind but there has to be some pattern that avoid object creation/destruction on every call.

Also I do not think there is a race condition, but I really would like other eyes to see if there might be one I'm missing.

code:

struct Counter{
     Counter(ACE_Atomic_Op<ACE_Thread_Mutex,long>& _counter) : counter(_counter){++counter;}
     ~Counter(){--counter;}
  ACE_Atomic_Op<ACE_Thread_Mutex,long>& counter;
};

blob* SomeClass::doSomething()
{
    if(!fake_guard) {return NULL;} //The return NULL; is safe

    Counter count(fake_semaphore);
    ...code...
    return otherclass->doSomethingElse();
}


void SomeClass::~SomeClass()
{
   fake_guard = false;
   while(fake_semaphore != 0)
   {
       sleep(...);
   }
   //Destroy everything
}

ACE_Atomic_Op<ACE_Thread_Mutex,long> fake_semaphore;
ACE_Atomic_Op<ACE_Thread_Mutex,long> fake_guard;  //Set to "true" in constructor
Any ideas?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
So, you've got one thread (possibly many threads) making a method call on an object, and a totally different thread which asynchronously tries to delete the object despite the object being used live in the other thread, and you want to solve this by using atomic operations to block the deleter until a particular method call is complete. Magically, there is no danger of the deleter deleting the object before the method call. Do I have this right?

There is basically no way to diagnose the possibility of race conditions without some level of actual detail about (1) why a thread is deleting objects being used live by a totally different thread and (2) what constraints all these threads are operating under.

Also, there is no overhead for creating and destroying objects here, and I am dismayed at the idea that someone purportedly doing performance work doesn't understand that.

floWenoL
Oct 23, 2002

I'm also betting that you have done no profiling.

Chuu
Sep 11, 2004

Grimey Drawer
I guess the replies mean I am doing something incredibly stupid. As for the overhead comment, well, heh, I don't really have a good excuse other than it's not a good idea coding at 4:00 am.

I've done some basic profiling by throwing the mutex in and seeing what happens, execution time goes up by about 15%. I just threw the post together looking for ideas. I don't have access to the dataset I need on this computer to run it through gprof right now and see what's actually happening.

As for the rest of rjm's, that pretty much is the scenario, and I have little control over it. The callback method is registered with a library and from that point I have pretty much no control over when it's going to be called. The first thing I do in the actual destructor is deregister the callback so I'm guaranteed that I receive no further calls, but I have to worry about calls that haven't returned yet.

The code living outside the destructor has already been pretty throughly vetted to be thread safe. It's just that code didn't clean up after itself properly, but since the lifetime of the object was pretty much the same as the application this resource leak wasn't really a high priority. I want to use it somewhere else though where it will be created/destroyed dynamically, which means I pretty much have to fix it.

Chuu fucked around with this message at 10:50 on Apr 9, 2009

DoctorTristan
Mar 11, 2006

I would look up into your lifeless eyes and wave, like this. Can you and your associates arrange that for me, Mr. Morden?
Okay, this has got me stumped. I have a class, EA2Skeleton, that contains a public member segmentStore, a standard vector of pointers to another class. The copy constructor has to do some weird stuff with the elements of segmentStore, I've tried to implement this as:

code:
EA2Skeleton::EA2Skeleton ( const EA2Skeleton& skel ) {
        //This is fine
        std::vector<EA2SkeletonSegment*>::iterator it = segmentStore.begin();

        //This gives me errors
        std::vector<EA2SkeletonSegment*>::iterator skelit = ((skel).segmentStore).begin();

        //does some stuff with the iterators after this

        }
However I get the compiler error:

code:
 ea2skeleton.cpp: In copy constructor 'ea2::EA2Skeleton::EA2Skeleton(const ea2::EA2Skeleton&)':
ea2skeleton.cpp:33: error: conversion from
'__gnu_cxx::__normal_iterator<ea2::EA2SkeletonSegment* const*, std::vector<ea2::EA2SkeletonSegment*, std::allocator<ea2::EA2SkeletonSegment*> > >' 
to non-scalar type 
'__gnu_cxx::__normal_iterator<ea2::EA2SkeletonSegment**, std::vector<ea2::EA2SkeletonSegment*, std::allocator<ea2::EA2SkeletonSegment*> > >'
I guess the problem is something to do with the type of the const reference, but I'm not sure how to fix it.

digibawb
Dec 15, 2004
got moo?
Use a const_iterator for the const object.

Tomed2000
Jun 24, 2002

I've just started getting back into C++ and I've been coding small console apps with Visual C++ 2008 Express and I keep running into weird linking problems while building my projects.

Note that I usually have a header file (.h) and the definitions file (.cpp) for my class then a separate driver file for main. I was testing out program in the driver when I found out that I needed to modify the class. I do a few changes and then I go back to building the project and I get weird runtime errors. I step through the code and notice that the changes I made didn't take.

I try a bunch of stuff like closing/opening the program, rebuilding the project, etc but I finally delete all of the project files created by VC++, create a new project adding my file back in, and it finally works.

Is this a common problem or am I doing something wrong? Should I be using a difference compiler?

Tomed2000 fucked around with this message at 17:23 on Apr 9, 2009

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
You'll have to go into more detail. Give a small example of a header, a .cpp, your main.cpp, and what kind of change you made.

Tomed2000
Jun 24, 2002

Alright.

Here are snippets of my files.

driver.cpp:
code:
#include "Comparator.h"
int main()
{
  Comparator comp1(1,2);
  return 0;
}
Comparator.h:
code:
class Comparator
{
public:
  Comparator(int topInput, int bottomInput);

private:
  int top;
  int bottom;
};
Comparator.cpp:
code:
#include "Comparator.h"

Comparator::Comparator(int topInput, int bottomInput)
{
  top = topInput;
  bottom = bottomInput;
}
Notice that I want to create a Comparator object comp1 with top=1 and bottom=2.



I find out later that I actually want to initialize top and bottom to be topInput-1 and topInput-2 so I do a small change to Comparator.cpp:
code:
#include "Comparator.h"

Comparator::Comparator(int topInput, int bottomInput)
{
  top = topInput-1;
  bottom = bottomInput-1;
}
I rebuild the entire project and run this code again. However, it still reads the constructor definition the same as before with top = topInput and bottom = bottomInput. Not until I created an entirely new project and rebuilt everything from scratch that I finally got it to recognize the change in Comparator.cpp.

Tomed2000 fucked around with this message at 17:46 on Apr 9, 2009

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Chuu posted:

As for the rest of rjm's, that pretty much is the scenario, and I have little control over it. The callback method is registered with a library and from that point I have pretty much no control over when it's going to be called. The first thing I do in the actual destructor is deregister the callback so I'm guaranteed that I receive no further calls, but I have to worry about calls that haven't returned yet.

Okay, this is better but still not quite enough information. For future reference, here's the basic information you should always give about any concurrency question:
(1) What are all the threads doing?
(2) How many threads are there of each type (one or many)?
That is, you need to learn how to describe the problem as opposed to your proposed solution. We cannot possibly judge the solutions without understanding the problem.

Let me try to guess, though — you have a pool of worker threads draining a queue, and there's an asynchronous callback that tells you when... nothing else is going to be enqueued? a subsystem has gone down and you shouldn't make calls against it anymore? something else? Are you in charge of draining the queue, or is the queue also managed by some other library? Is SomeClass::doSomething() the only thing that gets done while draining the queue, or is it only one of several possibilities? Are there multiple instances of SomeClass live among the worker threads? Where do they get the reference to this instance of SomeClass that's being deleted, anyway — taken from the queue, fetched from global data, given to them at initialization, something else?

Speaking very broadly, I've found it's generally best for shutdown callbacks to simply set flags and let the normal worker threads tear down the objects they're working with — but again, it's very difficult to say without understanding more about how this system works.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Tomed2000, I have no idea if this'll fix your linker error (probably not), but does your header file have a sentinel? They look something like this (I don't know if VS has any special skullduggery, this is what I've always done):
code:
#ifndef _FILENAME_H
#define _FILENAME_H

// rest of header file goes here

#endif /* _FILENAME_H */
This is to ensure that any header file is never included into the final build more than once... might help your error. Again, probably has nothing to do with it, but it's worth a shot and it's a good habit anyway.

(edit) I just realized those are snippets, not the whole file. Ignore me. :downs:

Ciaphas fucked around with this message at 20:32 on Apr 9, 2009

newsomnuke
Feb 25, 2007

Ledneh posted:

Tomed2000, I have no idea if this'll fix your linker error (probably not), but does your header file have a sentinel? They look something like this (I don't know if VS has any special skullduggery, this is what I've always done):
You can use #pragma once with MSVC (and others I believe, though it's non-standard). I've found that MSVC does get confused with builds now and again as to whether object files are up to date, and if you get some strange linker error it's always worth trying rebuilding from scratch.

Ok, question: when constructors are compiled, is the code from any super-class constructors copied into the function, or are the constructors called separately, when instantiating a class?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Same thing as any other function — if the source is available, the optimizer has the option of inlining it, but is not required to do so. The semantics don't change either way.

newsomnuke
Feb 25, 2007

rjmccall posted:

Same thing as any other function — if the source is available, the optimizer has the option of inlining it, but is not required to do so. The semantics don't change either way.
Sorry, I don't think that's what I meant. If you have:
code:
class Base
{
	Base()
	{
		x = 5;
	}
};

class Derived : public Base
{
	Derived() : Base()
	{
		y = 6;
	}
};
Does Derived::Derived get transformed to

code:
Derived::Derived()
{
	x = 5;
	y = 6;
}
or do both Base::Base and Derived::Derived get called when you create a Derived?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

ultra-inquisitor posted:

Sorry, I don't think that's what I meant.

I think rjmccall's answer is exactly accurate. If the compiler has the source of the base class available, it may optionally inline the base constructor into the child constructor, or it may generate a call.

newsomnuke
Feb 25, 2007

ShoulderDaemon posted:

I think rjmccall's answer is exactly accurate. If the compiler has the source of the base class available, it may optionally inline the base constructor into the child constructor, or it may generate a call.
Oh d'oh, it's late.

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik
does anyone know a good way of changing HSB color to RGB without using floating point math?

POKEMAN SAM
Jul 8, 2004

Zaxxon posted:

does anyone know a good way of changing HSB color to RGB without using floating point math?

Have you tried doing the math with 0-255 values as opposed to 0-1 values? Failing that, you could always use a Rational type to do all the math then at the end convert that to an int in 0-255 (or whatever your scale is) without using any floating point math.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

What would be the easiest way to print out a float that's constantly updating onto the terminal?

I just started writing in C++ and this is pretty much all I know how to do:

getProgress just returns a float value.

code:
while(tservice->unfinishedDownloads())
{
    std::cout << tservice->getProgress(1);
}
Thanks in advance :smith:

Zakalwe
May 12, 2002

Wanted For:
  • Terrorism
  • Kidnapping
  • Poor Taste
  • Unlawful Carnal Gopher Knowledge

drcru posted:

What would be the easiest way to print out a float that's constantly updating onto the terminal?

I just started writing in C++ and this is pretty much all I know how to do:

getProgress just returns a float value.

code:
while(tservice->unfinishedDownloads())
{
    std::cout << tservice->getProgress(1);
}
Thanks in advance :smith:

Nothing wrong with waht you just wrote apart from the whole "what the hell does 1 mean in this context" thing and the lack of a space or a std::endl. I assume you want to replace the number in your terminal rather than scroll? Not supported in C++. You'll need to use an external terminal aware library like ncurses to do that

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Thanks for the prompt reply, that's exactly what I want to do.

I was afraid that I'd have to use another library but it's better than flooding my screen with 0.000 0.000 0.000 0.000 0.0001 eh?

Thanks again.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Non-standard and fairly brittle (works in Windows and Linux):

code:
cout << "\r" << whatever << flush;

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

That seems to have worked too. Thanks.

Justinius
May 31, 2005
I'm working on project and I've hit a problem I don't know how to solve.

I have the following:


#include <iostream>
#include <vector>

using namespace std;

typedef vector< vector<double> > A2D; //dynamic 2D array ugly but is useful

class TestClass
{
public:
int some_value;
A2D some_matrix(0, vector<double> (0,0));
};

int main()
{
cout<<"hello world"<<endl;
}


This doesn't compile throwing up a lot of errors saying what amounts to that it doesn't know what A2D is at all

ctz
Feb 6, 2003

Avenging Dentist posted:

Non-standard and fairly brittle (works in Windows and Linux):

code:
cout << "\r" << whatever << flush;

I believe the behaviour of a carriage return written to a terminal is standard according to POSIX.

And you can (must!) fix the brittleness by guaranteeing that `whatever' is of constant length. In particular, you'll get wrong output from use like:

code:
  cout << "\r" << float(1.234234) << flush;
  cout << "\r" << float(1.1) << flush;

ctz fucked around with this message at 17:46 on Apr 11, 2009

Pooball
Sep 21, 2005
Warm and squishy.
Justinius:
That's not how you call member's constructor. Try:
code:
A2D some_matrix;
TestClass() : some_matrix(0, vector<double> (0,0)) { }
This is completely pointless though; the fill constructor doesn't set a default, if that's what you're trying to do.

agscala
Jul 12, 2008

Justinius posted:

A2D some_matrix(0, vector<double> (0,0));

from your typedef don't you already have a vector-in-vector setup? Why are you initializing your 2D vector full of more vectors? As far as I know, it already has vector<double>'s in it and it's like you're already ready to rock with just

code:
A2D some_matrix;

Justinius
May 31, 2005
Pooball, you nailed it on the head.

I was trying to set a default and that was what was causing that issue.

Thanks.

Agscala,

believe it or not if you want to declare an initialized A2D with say 5 rows and 6 columns set to 0 the declaration looks like this

A2D some_mat(5, vector<double> (6, 0));

Thanks for the fast replies everyone.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

ctz posted:

I believe the behaviour of a carriage return written to a terminal is standard according to POSIX.

And you can (must!) fix the brittleness by guaranteeing that `whatever' is of constant length. In particular, you'll get wrong output from use like:

code:
  cout << "\r" << float(1.234234) << flush;
  cout << "\r" << float(1.1) << flush;

How do I properly format floats or set them to a smaller precision?

Right now I'm just trying std::count.precision(3);

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

drcru posted:

How do I properly format floats or set them to a smaller precision?

Right now I'm just trying std::count.precision(3);

And?

agscala
Jul 12, 2008

drcru posted:

How do I properly format floats or set them to a smaller precision?

Right now I'm just trying std::count.precision(3);

<iomanip> and setprecision() I believe

Adbot
ADBOT LOVES YOU

Contero
Mar 28, 2004

drcru posted:

How do I properly format floats or set them to a smaller precision?

Right now I'm just trying std::count.precision(3);

Use printf :colbert:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply