Click here to Skip to main content
15,178,226 members

Comments by Daniel Pfeffer (Top 35 by date)

Daniel Pfeffer 21-Apr-21 15:15pm View
   
Python and C (or C++) are very different languages. Rather than trying to translate Python code to C or C++, you will probably find it easier to write the program from the beginning. For your code, this should not be very difficult.

BTW, your prime discovery code is extremely inefficient. A few minutes thought should enable you to improve it considerably.
Daniel Pfeffer 8-Apr-21 13:25pm View
   
As far as it goes, your code appears to work. Now, answer these questions:

1. Is your multiplication operation commutative? (i.e. should both scalar*vector and vector*scalar be legal?)
2. Can the scalar*vector case be defined inside the class?
3. Is there any good reason for the vector*scalar case to be defined inside the class?

Now review the operator(s) that you have already written, asking these questions for each of them.
Daniel Pfeffer 18-Mar-21 13:55pm View
   
I don't see anywhere that you handle the carry correctly. Binary addition is (for each bit):

given carry, a(i), b(i), calculate new carry and c(i) = a(i) + b(i).

c(i) = a(i) ^ b(i) ^ carry
new carry = (a(i) & b(i)) | (a(i) & carry) | (b(i) & carry)

for bits 0 of the operands, set carry = 0.

Note that this is a special case of the generic code for addition in an arbitrary base.
Daniel Pfeffer 17-Mar-21 11:08am View
   
Try spelling Length correctly (not Lenght)
Daniel Pfeffer 28-Feb-21 4:29am View
   
This sounds like a homework problem. If you don't understand it, why not ask your teacher to explain it again to you? That's his/her job...
Daniel Pfeffer 28-Nov-18 1:24am View
   
Yes, the standard library for both languages enables this. Given that this is obviously homework (which the OP made a good attempt at solving), I didn't want to confuse the OP with extraneous details.
Daniel Pfeffer 26-Nov-18 6:17am View
   
Oops! So add a zero to the exponent.
Daniel Pfeffer 24-Nov-18 14:51pm View
   
We have an even function, f(x). We wish to develop an approximation, F(x) to f.

When developing an approximation to an even function, you can sometimes get odd components with a very small coefficient. These are due to round off errors in the calculations, and they spoil the evenness of the approximation.

One way to avoid this is to replace 'x' with 'x^2', and calculate a different approximation to f, using the new parameter. This guarantees that the approximation is also even.
Daniel Pfeffer 20-Nov-18 15:19pm View
   
I fail to see why dates.reverse() doesn't give you what you want. It reverses the order of the elements of the array, without caring what the values are. An array in ascending order would become an array in descending order.
If your array is not in order, you will have to write a custom sorting function. As you have discovered, dates in US format cannot be sorted as if they were strings.
Daniel Pfeffer 17-Oct-18 0:47am View
   
When simulating many physical systems, you calculate sin(omega*t), where omega is frequency and t is time. These numbers can get quite big - well over 100.0.

As for your other point, we'll have to agree to disagree. :)
Daniel Pfeffer 16-Oct-18 12:38pm View
   
x is the argument to your sin() calculation.

No, I didn't run the code; merely looking at the way you implemented the power series is enough. Were any of my comments about the code incorrect? :)
Daniel Pfeffer 16-Oct-18 7:10am View
   
1. pow(x, y) _may_ have an optimization for the case of integral y, but that is not guaranteed. Otherwise, it calculates exp(y*log(x)).
2. Even if the optimization exists, you will have between lg(n) and 2*lg(n) multiplications for _each_ power calculation, with all the associated errors and extra calculation.
3. Horner's rule - f(x) = (...((a[n]*x + a[n-1])*x + a[n-2])*x ...) +a[0] uses n multiplications and n additions to perform the calculation, which is both faster and more accurate.
4. A modern C or C++ compiler provides fma(). Using that reduces the calculation to n fma() operations, with a corresponding increase in accuracy.
5. There is also no need to recalculate the factorial at each stage. It may be calculated "for free" by setting a[2*k+1] = +/-1.0/(2*k*(2*k+1)), a[1] = 1.0.
6. Assuming x is even moderately large (say 100.0), your method will overflow well before you reach acceptable accuracy - you will need at least 150 elements (n = 300), and 300! will overflow well before you reach that.
Daniel Pfeffer 16-Oct-18 4:40am View
   
This will be extremely inaccurate for even small values of x. You should at the very least use Horner's rule in order to evaluate the polynomial. See my solution for other considerations.
Daniel Pfeffer 2-Sep-18 7:06am View
   
When you want to write code that runs on more than one type of Windows (i.e. Win16, Win32, and Win64), they save a lot of effort parsing the messages. I am converting FRACTINT for Windows (a Win16 medium model program) to run as a native Win32/Win64 program, and these macros help a lot.
Daniel Pfeffer 29-May-18 7:52am View
   
One possibility is that with more processors, less switching-in and switching-out of threads is necessary. This means that the internal data/instruction cache of each processor is not flushed so often, which in turn means that the functions in general execute more quickly.

Note that this is only a guess. It would be impossible to give you a better answer without a full analysis of the profiling data.
Daniel Pfeffer 29-May-18 4:57am View
   
Look at articles about polyominoes.

This sounds like a tiling problem (cover an area with tiles of differing shapes/sizes). A brute-force method would start by writing an algorithm to create all possible 10-tiles, and then writing an algorithm that tries to pack 10 of them in a particular area, but there are probably better methods of doing this.

Assume that you have any number of tiles of each shape. Don't forget rotations and mirrors of tile shapes!
Daniel Pfeffer 29-May-18 4:41am View
   
Deleted
Look at articles about polyominoes.

This sounds like a tiling problem (cover an area with tiles of differing shapes/sizes). A brute-force method would start by writing an algorithm to create all possible 10-tiles, and then writing an algorithm that tries to pack 10 of them in a particular area, but there are probably better methods of doing this.

Assume that you have any number of tiles of each shape. Don't forget rotations and mirrors of tile shapes!
Daniel Pfeffer 18-Feb-18 15:16pm View
   
How would you do this by hand?
For example, take the string "abc". How would you extract all of the substrings? Now do the same for "abcd". Do you see the pattern?

Now write it in code.
Daniel Pfeffer 24-May-17 7:03am View
   
Not quite. I am saying that if you don't understand how floating-point values are processed in your environment, then numerical software may not function as expected.

This applies to any language implementation - from Fortran to Python. In the case of C#, Microsoft is deliberately ambiguous. It could be that the same thing applies to Python, but I don'the know enough about the internals of the interpreter to tell you.
Daniel Pfeffer 27-Feb-17 11:47am View
   
What you want to write sounds like an extension for MS Office. In order to suggest the next word during ordinary typing, it would have to behave like the "spelling checker", that is it would have to monitor every keystroke entered. Such additions are typically written in VBA, which is a version of Visual Basic for MS Office applications.

There must be tons of stuff about VBA on the 'net. I suggest that you read up on macro extensions for MS Office, and pay close attention to methods for "hooking" the keyboard, that is reading the input text as it is typed.
Daniel Pfeffer 7-Feb-17 3:53am View
   
Deleted
Yes, you could. The C or C++ part should be written as a DLL, and you could then call it from a C# program.

A quick Google of "Calling a C++ DLL from C#" should give you plenty of information on how to do this.
Daniel Pfeffer 7-Feb-17 3:51am View
   
Reply

Yes, you could. The C or C++ part should be written as a DLL, and you could then call it from a C# program.

A quick Google of "Calling a C++ DLL from C#" should give you plenty of information on how to do this.
Daniel Pfeffer 7-Feb-17 3:50am View
   
Deleted
Yes, you could. The C or C++ part should be written as a DLL, and you could then call it from a C# program.

A quick Google of "Calling a C++ DLL from C#" should give you plenty of information on how to do this.
Daniel Pfeffer 19-Jan-17 10:55am View
   
Extraction of the integer part by assigning the 'double' to an 'int' is not a good idea. What if the integer part overflows an 'int'?

(e.g. the 'double' value is 2^31, and the 'int' is 32-bit twos complement.)
Daniel Pfeffer 6-Nov-16 9:41am View
   
Other things to check:
1. What is the definition of ARR_SIZE? (by your description, it should be at least 31)
2. result is an array of 10 elements. Are you certain that 'idx' cannot go over 9?
3. Check that the 'query' array has the size the you expect it to have.
...
If all else fails, try stepping through the code with a debugger. See if the results are what you expect at each step.
Daniel Pfeffer 1-May-16 8:56am View
   
One way would be to use std::multimap, which allows multiple instances of the same key. You would then have to iterate over all the instances of the key in order to check for the presence of the duplicate.
Another way would be to use a map of std::map<int, std::set<wstring> >, and then insert each duplicate file name in the set. You would then have a two-phase lookup: find files of the appropriate size, and then check the set for the presence of the file name.
Daniel Pfeffer 1-May-16 4:48am View
   
Are you using a 16-bit emulator (DOSbox or something similar)? If you are trying to do this in Windows or Linux, this can't be done by user programs.
Daniel Pfeffer 25-Nov-15 15:21pm View
   
Your question is unclear; perhaps you could post a short snippet of code to clarify it.

If you are referring to traditional "dumb pointers", these work just as before:

class Base {}
class Derived: public Base {}

void method(Base& base)
{
}

Derived d;
Derived* pd = new Derived();

method(d);
method(*pd);

should work fine.
Daniel Pfeffer 11-Aug-15 10:40am View
   
If dataCustodian does not contain any spaces or slashes, fullName[] will have only one element. This is possible e.g. if you have only a last name, but no first name. I don't see a test for this condition.
Daniel Pfeffer 23-Jul-15 5:31am View
   
See the following URL https://developer.vimeo.com/api/upload/videos and read about resumable HTTP PUT uploads. I assume that VimeoDotNet allows this type of upload...
Daniel Pfeffer 6-Jul-15 5:23am View
   
Sorry; I missed the last line of your comment. In my defence, I did give the OP precisely the help that he asked for, no more and no less.
Daniel Pfeffer 6-Jul-15 4:12am View
   
Look at http://www.codeproject.com/Questions/68575/How-to-print-more-pages-in-C-printdocument. It should give you some ideas...
Daniel Pfeffer 2-Mar-15 4:53am View
   
The easiest way to discover the emulator size is to compile and link the code once for floating-point (assume that you do have FP instructions), and another time for the emulator. IIRC, the emulators used for DOS programs in the '90s (x86 machines, not ARM) were on the order of a few tens of kilobytes.
Daniel Pfeffer 2-Mar-15 2:46am View
   
The only modification that I would make would be to overload the '+=' and '+' operators to perform the matrix addition.
Daniel Pfeffer 2-Mar-15 2:37am View
   
The whole point of an emulator is to provide floating-point capabilities on hardware which does not posses them natively. This was a popular approach up to the '90s, when most CPUs started to have floating-point instructions on-board. There is no reason why it cannot work for you, as well.

IMO, the only reasons not to use an emulator are:
1. You do not have the additional memory required for the emulator
2. The performance of the emulator is insufficient for your needs

Only if either of these is true, should you consider writing your own fixed-point implementation. As you have discovered, writing a numerically stable fixed-point package is a non-trivial task.