9

Did the BCPL programming language support floating point? If not, then how did programmers use it to add two floating point numbers?

1
  • Metacomco BCPL for the Sinclair QL (1984) did sortof support floating point in vectors (but not as a stand-alone type)
    – tofro
    Commented Apr 26, 2019 at 16:52

3 Answers 3

6

BCPL did include floating point, but only as an extension and some smaller systems chose not to implement it. The Arnor Z80 BCPL compiler I learned on did not support FP.

The Tenex BCPL manual (1974) describes its floating point operations and representations as being relatively standard: one could add two floats with the + operator, as expected.

The bcpltape distribution (1984) notes in its TRIPOS BCPL Standard manual that:

       1.10.1979                                                  67
                               BCPL Standard
       A13 Floating point
           ______________
          There  are  two  possible  schemes  for  a  floating point
       package in BCPL:  on implementations where the cell  size  is
       big  enough  to hold the machine representation of a floating
       point number  the  Floating  Point  Language  Packet  may  be
       implemented and where this is not possible the Floating Point
       Procedure Packet may be  implemented.   In  either  case  the
       Floating Point I/O Procedures should be implemented.

BCPL's Floating Point Language Packet - for machines large enough to hold FP values in a memory cell - prefixed the corresponding integer operation with the character #, such as #+, #-, etc. So two numbers could be added using

C:=A#+B

The Floating Point Procedure Packet - for machines where FP values were held as a vector of cells - used special functions, including (again from the Tripos manual):

       Arithmetic Functions
       ____________________
          FPLUS(A,B,C)    C:=A#+B     resultis C
          FMINUS(A,B,C)   C:=A#-B     resultis C
          FNEG(A,B)       B:=#-A      resultis B
          FMULT(A,B,C)    C:=A#*B     resultis C
          FDIV(A,B,C)     C:=A#/B     resultis C
          FABS(A,B)       B:=#ABS A   resultis B

Floating point support was clearly implementation-specific, and would need to be reviewed on attempting to port software from one site to another.

3
  • 1
    maybe I should have said “BCPL could include floating point …”, as Martin Richards was seemingly dead-set against it until very recently. Other implementations were free to add it as they saw fit.
    – scruss
    Commented Apr 26, 2019 at 15:42
  • Or maybe something like: The BCPL language (as developed by Martin Richards) didn't itself include floating point support (until 2014 for floating point literals and 2018 for the FLT package) but there were other implementations which provided it as an extension.
    – paxdiablo
    Commented Mar 13, 2023 at 0:55
  • that would be fair, although in the 1970s, Martin Richards wasn't the only source of BCPL compilers. Other people added features that they needed, and those were standard on some installations
    – scruss
    Commented Mar 13, 2023 at 21:58
4

No, but Martin Richards has recently added floating point operators, with a funny kind of type inference to distinguish between integer and floating point arithmetic. From https://www.cl.cam.ac.uk/~mr10/bcplman.pdf, page 32:

BCPL was originally designed for the implemention of compilers and other system software such as text editors, pagination programs and operating systems. These applications typically did not require floating point and so the language did not include any floating point features. Indeed, many early machines on which BCPL ran had word lengths of 16 or 24 bits which were of insufficient length for useful floating point numbers. Even on 32-bit machines the precision of floating point numbers is limited to about 6 decimal digits which is insuffient for serious scientific calculations. For 50 years I resisted putting floating point into BCPL but have recently given in.

1
  • interesting to see that Richards added it for the BCPL interface with the OpenGL graphics library on the Raspberry Pi
    – scruss
    Commented Apr 26, 2019 at 15:36
2

No, BCPL did not support floating point, unless the system's native word was interpreted as a floating point value. It also didn't support any other types.

From the BCPL manual, section 1.0, point 2:

All data items have Rvalues which are bit patterns of the same length and the type of an Rvalue depends only on the context of its use and not on the declaration of the data item. This simplifies the compiler and improves the object code efficiency but as a result there is no type checking.

An "Rvalue" is, basically, a value that can be used on the right-hand side of an assignment. It's the opposite of an "Lvalue", which (again basically) is something that can be assigned to.

Considering its intended use:

BCPL is a simple recursive programming language designed for compiler writing and system programming [...]

it seems doubtful that floating-point processing would be an important enough feature to include, especially in a world where many systems might not be floating-point capable at all. The manual also doesn't mention "float", and "decimal" only appears once in the meaning of "base 10".

1
  • 1
    When I used floats in BCPL, they were defined as 2-word vectors. There were routines to assign values, do arithmetic and print floats. The arithmetic was worked out in reverse polish before it was coded. It was pretty awful to use
    – cup
    Commented Apr 27, 2019 at 18:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .