Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ longer(3X) — OSF1 1.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

errno(2)

signal(2)

exp(3M)

pow(3M)

sqrt(3M)

strtol(3C)

LONGER(3X)  —  Subroutines

NAME

longer - 64-bit integer class

SYNOPSIS


#include <codelibs/boolean.h>
#include <codelibs/longer.h>
 class longer
{
public:
longer();
longer(int a)
longer(long a);
longer(long a, long b);
longer(double);
 long msw() const;
long lsw() const;
 operator long() const;
operator int() const;
operator double() const;
 longer operator+(longer) const;
longer operator-(longer) const;
 longer operator∗(longer) const;
longer operator/(longer) const;
longer operator%(longer) const;
 longer operator^(longer) const;
longer operator&(longer) const;
longer operator|(longer) const;
 longer operator<<(int) const;
longer operator>>(int) const;
longer lsr(int) const;
 longer operator-() const;
 longer operator~() const;
int operator!() const;
 boolean operator==(longer) const;
boolean operator!=(longer) const;
boolean operator<(longer) const;
boolean operator>(longer) const;
boolean operator<=(longer) const;
boolean operator>=(longer) const;
boolean ult(longer) const;
boolean ugt(longer) const;
boolean ule(longer) const;
boolean uge(longer) const;
 longer operator+=(longer);
longer operator-=(longer);
 longer operator∗=(longer);
longer operator/=(longer);
longer operator%=(longer);
 longer operator^=(longer);
longer operator&=(longer);
longer operator|=(longer);
 longer operator<<=(int);
longer operator>>=(int);
 longer operator++();
longer operator--();
};
 #define MAXLONGER    // largest legal value a longer can contain
#define MINLONGER    // smallest legal value for a longer
 longer strtolonger(const char ∗s, char ∗∗end, int base);
longer atolonger(const char ∗s);
const char ∗longertostr(longer, int base);
 longer pow(longer base, longer exp);
longer gcd(longer, longer);
longer sqrt(longer);
 CC ... -lcodelibs
 

DESCRIPTION

The class longer provides a 64-bit signed integer class for C++.  A longer value must be within the range of MINLONGER..MAXLONGER to be valid.  Values outside this range may cause unpredictable behaviour.  Longer values returned by any functions or member-functions described in this document will always be within this legal range unless indicated otherwise. 

Constructors

The nullary constructor for longer does no initialization and thus leaves the variable undefined.  Contructors from types int, long, and double are provided.  The int and long contructors always sign extend to create the 64-bit value.  The double constructor rounds to the nearest integer value.  In addition, a constructor from two longs is provided. 

Type conversion operators

Type convertion operators are provided to allow type cast of longers to ints, longs, or doubles. The type conversion operators are standard in that they perform similarly to the intrinsic type conversion from int to short, or double.

Operators

The standard operators for ints are also provided for longers. These include +, -, ∗, /, %, ^, &, |, <<, >>, -, ~, ~, ==, !=, <, >, <=, >=, +=, -=, ∗=, /=, %=, ^=, &=, |=, <<=, >>=, ++, and --. All of these operators assume signed operands. The increment operators ++ and -- are designed to be post-increment and pre-decrement (respectively) for the most typical usage.  Division by zero is undefined and will cause a floating point exception by causing the signal SIGFPE to be raised.  See signal(2) for more details on how to catch Unix signals.

Member functions

Member functions for unsigned versions of the >>, <, >, <=, and >= operators are provided.  They are named lsr, ult, ugt, ule, and uge, respectively.

The member functions lsw and msw can be used to access the least significant and most significant 32-bit portions of a longer.

Functions

strtolonger and atolonger are similar to the standard functions strtol and atoi, except that they work with longers rather than longs or ints. base is the base of the number.  If it is zero then the base is determined from the string; a leading zero signifies base octal, a leading ’0x’ signifies hexadecimal, otherwise, decimal is used.  longertostr is used to convert a longer to a string.  The conversion can take place in any base.  The string is returned in a static buffer that is overwritten on subsequent calls. 

pow computes the power function of base raised to the exp. The return values and errno are set according to the following table.  See errno(2) for more details.

c = pow((longer)a, (longer)b);
argument range return value errno
a <= 0 0 EDOM
b < 0 0 EDOM
b == 0 1 <no change>
c <= MAXLONGER c <no change>
c > MAXLONGER MAXLONGER ERANGE

gcd returns the greatest common divisor of its two arguments.  This is done using the Euclidean method. 

sqrt returns the square root of its parameter.  The value is truncated so that the longer value two (2) is returned for the function call sqrt((longer)8). If a double value is needed rather than a longer, use the standard sqrt(3M) with appropriate typecasts.

SEE ALSO

errno(2), signal(2), exp(3M), pow(3M), sqrt(3M). strtol(3C).
The C Programming Language, by Brian W. Kernighan, Dennis M. Ritchie;
The C++ Programming Language, by Bjarne Stroustrup;
The Art of Computer Programming, by Donald E. Knuth.

  —  codelibs  —  C++

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026