This patch provides a way to make 1/2==0.5 optional without introducing any backward incompatibilities. It provides a pseudomodule "floatdivision" that, when imported, changes the behavior of the importing script at compile time: import floatdivision print 3/4 # 0.75 I confirm that, to the best of my knowledge and belief, this contribution is free of any claims of third parties under copyright, patent or other rights or interests ("claims"). To the extent that I have any such claims, I hereby grant to CNRI a nonexclusive, irrevocable, royalty-free, worldwide license to reproduce, distribute, perform and/or display publicly, prepare derivative versions, and otherwise use this contribution as part of the Python software and its related documentation, or any derivative versions thereof, at no cost to CNRI or its licensed users, and to authorize others to do so. I acknowledge that CNRI may, at its sole discretion, decide whether or not to incorporate this contribution in the Python software and its related documentation. I further grant CNRI permission to use my name and other identifying information provided to CNRI by me for use in connection with the Python software and its related documentation. Dave diff -c -r -x Entries* old\python/dist/src/Include/opcode.h python/dist/src/Include/opcode.h *** old\python/dist/src/Include/opcode.h Tue Mar 28 23:10:02 2000 --- python/dist/src/Include/opcode.h Mon Jun 12 14:41:06 2000 *************** *** 76,81 **** --- 76,82 ---- #define BINARY_AND 64 #define BINARY_XOR 65 #define BINARY_OR 66 + #define BINARY_FRACTION 67 /* 3/4 == 0.75 */ #define PRINT_EXPR 70 diff -c -r -x Entries* old\python/dist/src/Lib/dis.py python/dist/src/Lib/dis.py *** old\python/dist/src/Lib/dis.py Thu Mar 30 14:02:10 2000 --- python/dist/src/Lib/dis.py Mon Jun 12 15:52:20 2000 *************** *** 186,191 **** --- 186,192 ---- def_op('BINARY_AND', 64) def_op('BINARY_XOR', 65) def_op('BINARY_OR', 66) + def_op('BINARY_FRACTION', 67) def_op('PRINT_EXPR', 70) def_op('PRINT_ITEM', 71) diff -c -r -x Entries* old\python/dist/src/Python/ceval.c python/dist/src/Python/ceval.c *** old\python/dist/src/Python/ceval.c Mon May 08 14:06:50 2000 --- python/dist/src/Python/ceval.c Mon Jun 12 14:52:02 2000 *************** *** 787,792 **** --- 787,816 ---- PUSH(x); if (x != NULL) continue; break; + + case BINARY_FRACTION: + w = POP(); + v = POP(); + if (PyInt_Check(v) && PyInt_Check(w)) { + /* 3/4 == 0.75 */ + long vi, wi; + vi = PyInt_AS_LONG(v); + wi = PyInt_AS_LONG(w); + if (wi == 0) { + PyErr_SetString(PyExc_ZeroDivisionError, + "integer division"); + x=NULL; + } + else + x=PyFloat_FromDouble( (double)vi / (double)wi ); + } + else + x = PyNumber_Divide(v, w); + Py_DECREF(v); + Py_DECREF(w); + PUSH(x); + if (x != NULL) continue; + break; case BINARY_MODULO: w = POP(); diff -c -r -x Entries* old\python/dist/src/Python/compile.c python/dist/src/Python/compile.c *** old\python/dist/src/Python/compile.c Wed May 03 23:44:38 2000 --- python/dist/src/Python/compile.c Mon Jun 12 15:25:26 2000 *************** *** 329,334 **** --- 329,335 ---- #ifdef PRIVATE_NAME_MANGLING char *c_private; /* for private name mangling */ #endif + int c_floatdivision; /* generate BINARY_FRACTION; 3/4==0.75 */ }; *************** *** 463,468 **** --- 464,470 ---- c->c_last_addr = 0; c->c_last_line = 0; c-> c_lnotab_next = 0; + c->c_floatdivision = 0; return 1; fail: *************** *** 1482,1488 **** op = BINARY_MULTIPLY; break; case SLASH: ! op = BINARY_DIVIDE; break; case PERCENT: op = BINARY_MODULO; --- 1484,1493 ---- op = BINARY_MULTIPLY; break; case SLASH: ! if (c->c_floatdivision) ! op = BINARY_FRACTION; ! else ! op = BINARY_DIVIDE; break; case PERCENT: op = BINARY_MODULO; *************** *** 2179,2188 **** /* 'import' ... */ for (i = 1; i < NCH(n); i += 2) { REQ(CHILD(n, i), dotted_name); ! com_addopname(c, IMPORT_NAME, CHILD(n, i)); ! com_push(c, 1); ! com_addopname(c, STORE_NAME, CHILD(CHILD(n, i), 0)); ! com_pop(c, 1); } } } --- 2184,2200 ---- /* 'import' ... */ for (i = 1; i < NCH(n); i += 2) { REQ(CHILD(n, i), dotted_name); ! ! if (NCH( CHILD(n,i) )==1 && ! !strcmp("floatdivision", STR(CHILD(CHILD(n,i),0)))) ! { ! c->c_floatdivision++; ! } else { ! com_addopname(c, IMPORT_NAME, CHILD(n, i)); ! com_push(c, 1); ! com_addopname(c, STORE_NAME, CHILD(CHILD(n, i), 0)); ! com_pop(c, 1); ! } } } } *************** *** 3306,3311 **** --- 3318,3324 ---- case single_input: /* One interactive command */ /* NEWLINE | simple_stmt | compound_stmt NEWLINE */ c->c_interactive++; + /* c->c_floatdivision++; */ n = CHILD(n, 0); if (TYPE(n) != NEWLINE) com_node(c, n); *************** *** 3313,3318 **** --- 3326,3332 ---- com_push(c, 1); com_addbyte(c, RETURN_VALUE); com_pop(c, 1); + /* c->c_floatdivision--; */ c->c_interactive--; break; *************** *** 3482,3487 **** --- 3496,3503 ---- else sc.c_private = NULL; #endif + if (base) + sc.c_floatdivision = base->c_floatdivision; compile_node(&sc, n); com_done(&sc); if ((TYPE(n) == funcdef || TYPE(n) == lambdef) && sc.c_errors == 0) {