Potential additions to the Math class [Katy King]

Potential additions to the Math class [Katy King]

  • Comments 36

In preparation for the next version of the product, we've collected suggestions for additions to the Math class and related classes.  To give you an idea of the kinds of things people ask us for, here are a list of some of the requests we've received.  We’re curious to know which of  these (if any) seem interesting to this audience, and why?  (Namely, what are you working on that you could leverage the specific capability listed?)  Is there anything missing from the list which would be useful?

  • Implement single-precision trig (and other) overloads.  For many functions that currently take a Double, add overloads that take a Single.
  • Inverse hyperbolic functions (ACosh, ASinh, and ATanh)
  • More trig functions (csc, sec, cot)
  • Min and Max overloads that take more than two arguments
  • Other functions that take a variable number of args - Sum() and Average(), for example
  • Complex number support
  • Bitshifting - RightShift and LeftShift on integral types (not currently available in VB)
  • Arbitrary-precision decimal numbers (BigDecimal)
  • Factorial
  • Permutations, Combinations (see <http://mathforum.org/dr.math/faq/faq.comb.perm.html> for definitions)
  • Math.Pow() overload for Decimal
  • Convert between degrees and radians
  • Support for vectors and vector math (probably not in the Math class)
  • Add new values to the MidpointRounding enum - which ones?
  • Provide a different math model for operations, that throws instead of obeying IEEE (returning NaN/Infinity).  (Note that it is extremely unlikely that we will change our model at this point.)
  • All of the above sound good. In many languages, the Math routines are the stepchild no one loves; it would be great for Whidbey to set the standard on this.

    The one thing that I would find really cool, (though like vector math it would be a separate set of classes rather than in the Math class), would be support for Directed Acyclic Graphs (DAGs).

    Your programmers will know what they are and the things they can be used for much better than I can explain, but I worked for a company that made extensive use of them (for example, in the user mgmt and workflow modules) in its B2B product, and they allowed for so many things that would be difficult or impossible using hierarchies and other structures.

    If your team were intersted enough, I could give more detailed examples. WinFS uses DAGs, and they're also useful for many types of theoretical comp sci.

    It's exactly the sort of wheel that is not easy to invent, and yet is reinvented over and over. Microsoft providing a standard, high-performance implementation would be great and, at least temporarily, give the .Net BCL a feature unique among its competitors.
  • The current version of VB does support bitshifting and I have production code in use that uses the bitshift operators.

    This must be an old suggestion from someone who was using the 1.0 (VB 2002) release instead of 1.1 (VB 2003).
  • Most of the mentioned features are nice especially the inverse hyperbolics and converting between degrees, radians and gradians. You might also consider adding support for comparing floating point values within a default (and a specified) epsilon - think AlmostEquals. :-)

  • Biggest gains for me out of that list:
    1. BigDecimal; when you nee dit, you need it, and you really miss not having it.
    2. Radians/Degrees; more limited in broad appeal, but very handy and better for th Framework to offer it IMHO.
    3. Min/Max/Sum + vector operations: I see these as a more general need. Don't know if Math class is the best place for them, but with iterators now in C# it would be great for me to have an iterator for a series and be able to compute a sum/avg/min/max etc over the series. Please do this generically with an IEnumerable and not just for arrays or a certain number of explicit paramters.
    4. Overhauling floating point. You mention this is unlikely, but it should be given serious thought. IEEE semantics can just plain suck if someone really doesn't want them. From a programmer point of view, why can I have checked/unchecked sections of code as with ints? Maybe the compiler does funny business behind the scenes, fine. All I can say is that problems with floating point handling are common because 'intuitive' things don't make sense to developer. I would work through scenarios in a usability lab and really see how hard it is, even for university-educated grads who are Einstein developers. Then make it easier.


  • If you're planning on adding vector math routins and complex numbers why not also add quaternions (usefull for 3D applications) etc...

    In fact, I dont see why the managed directx math routins can't be a part of the framework (Some of us want to use 3D math and geometry routins without using DirectX...)
  • It would be great if you could provide a rounding method that rounds up for >=.5 and down otherwise. We use this in the European financial sector.

    e.g.
    public static decimal Round(decimal d)
    {
    return decimal.Truncate((d<0.0m)?(d-0.5m):(d+0.5m));
    }

    Thanks.
  • Vector and vector operations, Matrix and matrix operations(+, -, *, det). It would be great to have all implementation of Vector and Matrix generic-based.
  • I think that having support for arbitrary precision integers in the framework would be a great idea. Putting that support in the Math class is a bad idea however.

    If you would implement arbitrary precision arithmetic, think about the areas where it would be used. The only area that I can think of that requires arbitrary precision integer arithmetic (that can not be done with System.Decimal) is the implementation of an ever increasing amount of cryptography-related algorithms.

    It is important to realize what the most important operations in that field are. Efficient execution of operations modulo some base is probably the most obvious one, and some way of capturing the pre-computations necessary to make those calculations efficient needs to be provided. In particular modular exponentiation and modular inversion should be provided. Also, prime testing and prime generation are features often required in such applications.
  • Take a look at the C/C++ floating point support

    MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_floating.2d.point_support.asp

    There is quite a lot missing from the Math class, which in much more essential than convenience stuff like degrees to radians
  • Conversion between degrees and radians would be the biggest win for us. We do a lot of it now (and thus have routines for it), but to offload this effort to the Framework would help clean up our namespace.

    Many of the others would be nice, but I can't quite put my finger on a business case for them at the moment.
  • Permutations and combinations.
    BigDecimal.
    Radians/degrees conversion.
  • The most useful for me would be:
    1. Conversion between decimal and degrees. This would be convenient. In fact my preferred embodiment would be to encapsulate this in an "Angle" class with properties "Degrees" and "Radians". I've been on a number of projects that have had bugs related to incorrect interpretation of a "double".
    2. Variable argument versions of: Sum(), Average(), Min(), Max()
    3. Single precision trig functions. Would be convenient.
    4. Complex Number support. Don't need it now, but would sure prefer not to write or source my own if/when I do.
    5. Vector and vector math. This might be useful if:
    a. There is also a matrix class, or I can implement my own by wrapping vector class in a straightforward manner.
    b. Performance is close to an unmanaged implementation. My experience is that my hand-tuned unsafe C# implementation of a vector-matrix multiplication was still a factor of 2 slower than using P/Invoke with a native C implementation.
  • I want to add my vote to Min and Max taking more than two arguments.
  • Hmmm -

    singleprec trig - xlnt

    hyperbolics - check

    more trig - check, keeps me out of the receipes book :-)

    list base min & max - yeah, thats nice

    sum() is nice - average() mebbe, but what if I need other measures like median, stddev, etc - a more generalized stats class might be nice

    complex numbers - oh great, go out and steal math's version of hello world. oh, ok - it's useful

    bitshifting - why not just get rid of VB ? :-) I would add to this a mechanism to make it easier to convert floats to longs and a mechanism to convert doubles to longlongs - some of us have math routines where we need to set constants _very_ exactly - your testers most likely have this need too

    bignums - love em

    factorials - as long as it's optimized

    perms and combs - nahh - factorials is already pushing it - do this only if you want to do an algebra lib, and then there's a lot of other stuff you need to consider

    decimal pow - hmm, why not make decimal completely symettric ?

    convert between degrees and radians - you don't need a function for this, just a couple of constant properties giving multipliers - if you're looking at making degrees wrap, i.e. 0 = 360, thats a different AND NASTY issue - graphics guys run into this a lot when we do texture wraps, solution requires context - hence I'd just stick with providing convienience constant multipliers

    vectors and vector math - hmmm, I have those and they're big classs, and as soon as you do vectors, matrices come too - yes in general, but it's a big challenge dot , cross, triple cross, normalization, polar to cartesian and v.v., basis vectors, basis function, etc - very big list, and then come even stranger things

    midpoint rounding - expose control for full IEEE 764 mechanisms

    NO NO NO NO don't change math model - HaNs are perfect, if we need to throw
    if(value != value)
    throw("math all bollixed") works fine

    Other issues
    SIMD!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Other means to optimize calc pipeline

    In general, most of us who need the high level stuff have done it - what we could really use is having the low level run optimally - giving us a way to set up parallelized simd would be a huge gain
  • BigInt would be my #1 request.
Page 1 of 3 (36 items) 123