return the value of the Numeric object as a Java int - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : OpenMaple : Java Application Programming Interface : Numeric Class : OpenMaple/Java/Numeric/intValue

Numeric.intValue - return the value of the Numeric object as a Java int

Calling Sequence

int intValue() throws MapleException

Description

• 

The intValue function returns the value represented in the Numeric as a Java int.  If the value does not fit exactly into a Java int, an error is raised.

• 

To determine if the value fits within a Java int, use the isInt function.

Examples

import com.maplesoft.openmaple.*;

import com.maplesoft.externalcall.MapleException;

class Example

{

    public static void main( String notused[] ) throws MapleException

    {

    String mapleArgs[];

    Engine engine;

    Numeric n;

    int i;

    mapleArgs = new String[1];

    mapleArgs[0] = "java";

    engine = new Engine( mapleArgs, new EngineCallBacksDefault(),

        null, null );

    n = (Numeric)engine.evaluate( "2^33:" );

    System.out.println( n.isInt() );

    try

    {

        n.intValue();

    }

    catch ( MapleException me )

    {

        System.out.println( me.getMessage() );

    }

    n = (Numeric)engine.evaluate( "2^20:" );

    System.out.println( n.isInt() );

    i = n.intValue();

    System.out.println( i );

    }

}

Executing this code produces the following output.

false

Error, value too large for integer[4]

true

1048576

See Also

ExternalCalling/Java/MapleException, OpenMaple, OpenMaple/Java/API, OpenMaple/Java/Numeric, OpenMaple/Java/Numeric/byteValue, OpenMaple/Java/Numeric/doubleValue, OpenMaple/Java/Numeric/floatValue, OpenMaple/Java/Numeric/isInt, OpenMaple/Java/Numeric/longValue, OpenMaple/Java/Numeric/shortValue


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam