Extreme Optimization > QuickStart Samples > Elementary Functions QuickStart Sample (Managed C++)

Extreme Optimization QuickStart Samples

Elementary Functions QuickStart Sample (Managed C++)

Illustrates the use of the elementary functions implemented by the Elementary class (Extreme.Mathematics namespace) in Managed Extensions for C++.

C# code VB.NET code Back to QuickStart Samples

// This is the main project file for VC++ application project 
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;
// We use many classes from the Extreme.Mathematics namespace.
using namespace Extreme::Mathematics;

// Illustrates the use of the elementary functions implemented
// by the ElementaryFunctions class in the Extreme.Mathematics.Curve namespace of 
// the Extreme Optimization Mathematics Library for .NET.
int _tmain()
{
    // This QuickStart sample deals with elementary 
    // functions, implemented in the ElementaryFunctions class.

    //
    // ElementaryFunctions functions
    //

    // Evaluating Log(1+x) directly causes significant
    // round-off error when x is close to 0. The
    // Log1PlusX function allows high precision evaluation
    // of this expression for values of x close to 0:
    Console::WriteLine("Logarithm of 1+1e-12");
    Console::WriteLine("  Math.Log: {0}", __box(Math::Log(1+1e-12)));
    Console::WriteLine("  Log1PlusX: {0}", __box(ElementaryFunctions::Log1PlusX(1e-12)));

    // In a similar way, Exp(x) - 1 has a variant, 
    // ExpXMinus1, for values of x close to 0:
    Console::WriteLine("Exponential of 1e-12 minus 1.");
    Console::WriteLine("  Math.Exp: {0}", __box(Math::Exp(1e-12) - 1));
    Console::WriteLine("  ExpMinus1: {0}", __box(ElementaryFunctions::ExpMinus1(1e-12)));

    // The hypotenuse of two numbers that are very large
    // may cause an overflow when not evaluated properly:
    Console::WriteLine("Hypotenuse:");
    double a = 3e200;
    double b = 4e200;
    Console::Write("  Simple method: ");
    try
    {
        double sumOfSquares = a*a + b*b;
        Console::WriteLine(__box(Math::Sqrt(sumOfSquares)));
    }
    catch (OverflowException *)
    {
        Console::WriteLine("Overflow!");
    }
    Console::WriteLine("  ElementaryFunctions::Hypot: {0}",
        __box(ElementaryFunctions::Hypot(a, b)));

    // Raising numbers to integer powers is much faster
    // than raising numbers to real numbers. The
    // overloaded Pow method implements this:
    Console::WriteLine("2.5^19 = {0}", __box(ElementaryFunctions::Pow(2.5, 19)));
    // You can raise numbers to negative integer powers
    // as well:
    Console::WriteLine("2.5^-19 = {0}", __box(ElementaryFunctions::Pow(2.5,-19)));

    Console::Write("Press Enter key to exit...");
    Console::ReadLine();
    return 0;
}
Overview
Introduction
Features
Documentation
QuickStart Samples
Sample Applications
Downloads
Get it now!
Download trial version
How to Buy
Information
Resources
Contact Us
Search

"The Extreme Optimization Statistics Library for .NET is a major boon for those doing statistical work in .NET. I strongly recommend this product."
- Marc Brooks

"I have made it my mission to institutionalize the value of good API design.  I strongly believe that this is key to making developers more productive and happy on our platform. It is clear that you value good API design in your work, and take to heart developer productivity and synergy with the .NET framework."
- Brad Abrams,
Lead Program Manager, Microsoft.

This is a partial list of companies who are using our libraries:
ABB Robotics
Allstate
Applied Materials
Arcam
Astra Schedule
Babson College
Canadian Council on Learning
Canyon Associates
Caxton Associates
CECity
Constellation Energy
CreditSights
DeepOcean
Duke University
Dynamotive
Elecsoft
Engelhard Corporation
Epcor
Equipoise Software
Galileo International
GAM UK
Gammex
GlaxoSmithKline
Global Matrix
The Hartford
Infinera Corporation
Intel
JDS Uniphase
LaBranche & Co.
Learning & Skills Council
Jacobs Consultancy
Litman Gregory
Lucas Systems
Malvern Instruments
Medrio
Merck & Co.
Mintera.
Monitor Software
MorningStar
NanoString Technologies
Paletta Invent
Parametric Portfolio Associates
Prosanos
RATA Associates
RiskShield
Ramboll
Standard & Poor's
Strategic Analysis Corporation
Univ. of Alicante
Univ. of South Carolina
vielife
Xerox
US Army