Previous: , Up: System Libraries   [Index]


8.2 floatlib

INTERCAL-72 C-INTERCAL CLC-INTERCAL J-INTERCAL
yes all versions no all versions

INTERCAL also has a floating-point library, called ‘floatlib’, presently available only in base 2. It is used by several of the demonstration programs shipped with the distribution. In versions after 0.28 it is included automatically at the end of your program by the compiler whenever your program refers to a line from (5000) to (5999) without defining any line in that range in the program.

Here is a summary of routines in floatlib.i:

Line Description
(5000) :3 <- :1 plus :2
(5010) :3 <- :1 minus :2
(5020) :2 <- the integer part of :1, :3 <- the fractional part of :1
(5030) :3 <- :1 times :2
(5040) :3 <- :1 divided by :2
(5050) :3 <- :1 modulo :2
(5060) :2 <- :1 cast from a two’s-complement integer into a floating-point number
(5070) :2 <- :1 cast from a floating-point number into the nearest two’s-complement ineger
(5080) :2 <- :1 cast from a floating-point number into a decimal representation in scientific notation
(5090) :2 <- :1 cast from a decimal representation in scientific notation into a floating-point number
(5100) :2 <- the square root of :1
(5110) :2 <- the natural logarithm of :1
(5120) :2 <- e to the power of :1 (the exponential function)
(5130) :3 <- :1 to the power of :2
(5200) :2 <- sin :1
(5210) :2 <- cos :1
(5220) :2 <- tan :1
(5400) :1 <- uniform random number between zero and one exclusive
(5410) :2 <- :1 times phi
(5419) :2 <- :1 divided by phi

Note: All of the above routines except (5020), (5060), (5080), (5200), (5210), and (5400) also modify .5 as follows: .5 will contain #3 if the result overflowed or if the arguments were out of domain, #2 if the result underflowed, #1 otherwise. (See below.)

The INTERCAL floating-point library uses the IEEE format for 32-bit floating-point numbers, which uses bit 31 as a sign bit (1 being negative), bits 30 through 23 hold the exponent with a bias of 127, and bits 22 through 0 contain the fractional part of the mantissa with an implied leading 1. In mathematical notation:

N = (1.0 + fraction) * 2^(exponent - 127) * -1^sign

Thus the range of floating-point magnitudes is, roughly, from 5.877472*10^-39 up to 6.805647*10^38, positive and negative. Zero is specially defined as all bits 0. (Actually, to be precise, zero is defined as bits 30 through 0 as being 0. Bit 31 can be 1 to represent negative zero, which the library generally treats as equivalent to zero, though don’t hold me to that.)

Note that, contrary to the IEEE standard, exponents 0 and 255 are not given special treatment (besides the representation for zero). Thus there is no representation for infinity or not-a-numbers, and there is no gradual underflow capability. Conformance with widely-accepted standards was not considered to be a priority for an INTERCAL library. (The fact that the general format conforms to IEEE at all is due to sheer pragmatism.)


Previous: , Up: System Libraries   [Index]