Jump to content

David Heffernan

Members
  • Content Count

    3710
  • Joined

  • Last visited

  • Days Won

    185

Everything posted by David Heffernan

  1. David Heffernan

    TStack<T>.Peek deeper than the topmost element

    You can look at the list of public methods and properties. Why do you need us to tell you that what you want isn't there? Didn't all the responses suggesting alternatives indicate that?
  2. David Heffernan

    TStack<T>.Peek deeper than the topmost element

    Push is Add. Pop is Extract(Count-1) and Peek is Items[Count-1] Contains won't help you because it checks the entire collection, not just the top two.
  3. David Heffernan

    TStack<T>.Peek deeper than the topmost element

    Adding push pop and peek to TList is incredibly simple. I thought you wanted access to them all because you talked about searching the collection for a specific item. Do you not need to do that?
  4. David Heffernan

    TStack<T>.Peek deeper than the topmost element

    Well, what's stopping you doing that? It's not a challenge. If you want random access to the entire collection, a stack isn't for you.
  5. David Heffernan

    TStack<T>.Peek deeper than the topmost element

    Seems like you want TList<T>
  6. I think it's far more likely to be environment variables being inherited.
  7. This sounds wrong. Messing with the system path and closing an ide tells me that you aren't creating and isolating your compile environments correctly. Note that Delphi is capable of building with any path and with any other ide open. You have solved nothing yet.
  8. David Heffernan

    Getters & Settters??

    Not true. FValue, in your example, is available as soon as the instance has been allocated. Realistically the earliest you get to use it is inside the constructor.
  9. David Heffernan

    IsZero or SameValue

    No
  10. David Heffernan

    IsZero or SameValue

    Yikes!! Even leaving aside Stefan's point, functions that use a relative tolerance, relative to the comparands, mean that your comparisons depend on the path through the array. I think it very likely that inserting some extra values away from the target could lead to a different value being found. There certainly are situations where comparing to tolerance is useful. However they need to be considered in detail and the tolerance choice and surrounding algorithm must be carefully thought out. A one size fits all function like this is not useful in my experience. Furthermore, I would say that a lot of times I have seen tolerance checking, it comes from a misunderstanding of floating point representations. Tolerances get used when they aren't needed. Sometimes it's not entirely the programmer to blame. For instance delphi's string conversion functions are broken because you can't rely on a round trip from float to string and back to float. So if you save as json or YAML or ini, say, then you don't get back the original value when you load from text. This is intolerable for a serious floating point developer. And it often drives people to compare to tolerance. My solution is to use conversion libraries that work correctly. Emba know about the problem but unless I am mistaken still have not fixed the problem.
  11. David Heffernan

    IsZero or SameValue

    This certainly changes things!
  12. David Heffernan

    IsZero or SameValue

    Right. They do what they are meant to do. It's just that they aren't actually useful for anything.
  13. David Heffernan

    IsZero or SameValue

    Then you are going to need to work out what your problem really is. Because it hasn't been stated here. If you want to work with numbers that have a finite number of decimal digits, then use a decimal type. It is precisely why such things exist.
  14. David Heffernan

    IsZero or SameValue

    They are invariably used as "solutions" to problems caused by floating point representability issues, but usually are the wrong solution.
  15. David Heffernan

    IsZero or SameValue

    {$APPTYPE CONSOLE} uses SysUtils; procedure Main; var i: Integer; val: Double; begin val := 0; for i := 0 to 80 do begin Writeln(FloatToStr(val)); val := val + 0.1; end; end; begin try Main; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln; end. Output: 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.99999999999999 6.09999999999999 6.19999999999999 6.29999999999999 6.39999999999999 6.49999999999999 6.59999999999999 6.69999999999999 6.79999999999999 6.89999999999999 6.99999999999999 7.09999999999999 7.19999999999999 7.29999999999999 7.39999999999999 7.49999999999999 7.59999999999999 7.69999999999999 7.79999999999999 7.89999999999999 7.99999999999999 So yeah, not looking such a good idea now. Why not use integers. You just need to count how many tenths you have. That's the job of an integer. Once you recognise this, then you are 90% of the way to realising the right solution.
  16. David Heffernan

    IsZero or SameValue

    What I propose works and it's better to avoid strings here.
  17. David Heffernan

    IsZero or SameValue

    Neither. Spawn of satan, should never have been published. In your case do all the behind the scenes work using integers and then divide by 10 just when you need the actual value. Or use a decimal type like currency.
  18. David Heffernan

    Compare two TIntegerDynArray

    I'd definitely remove the pointer check you just added. Surely that's just going to make things slower.
  19. David Heffernan

    Compare two TIntegerDynArray

    Don't think performance is an issue with TArray<T> and using it makes you code better able to work with other generic code.
  20. David Heffernan

    Compare two TIntegerDynArray

    Any reason why you aren't using TArray<Integer>?
  21. David Heffernan

    Compare two TIntegerDynArray

    This risks range check errors so I'd use Pointer(A)^ and similar for B. You could still save one of the lengths to a local to avoid getting it twice.
  22. David Heffernan

    Compare two TIntegerDynArray

    Not much point having three calls to Length and in fact the zero length check can be skipped and rely on CompareMem to know what to do when passed a size of zero.
  23. David Heffernan

    Compare two TIntegerDynArray

    First compare their length then do a CompareMem if the lengths are equal
  24. David Heffernan

    Function with 2 return values ?

    I once went into our local hardware store to buy a posidrive screwdriver, because I had to do something with a bunch of posidrive screws. The guy in the store scoffed at me and said that they didn't stock posidrive screwdrivers because posidrive screws were a stupid idea. This store is no longer in business.
×