language agnostic - Pretending that a 64-bit integer has unlimited range -


i implementing compiler proprietary language.

the language has 1 built-in integer type, unlimited range. variables represented using smaller types, example if a , b integer variables b ever assigned value of expression a % 100000 or a & 0xffffff, b can represented int32 instead.

i considering implementing following optimization. suppose sees equivalent of c# method:

public static void main(string[] args) {     bigint = 0;     while (true)     {         dostuff(i++);     } } 

mathematically speaking, transforming following not valid:

public static void main(string[] args) {     int64 = 0;     while (true)     {         dostuff(i++);     } } 

because have replaced bigint int64, overflow if loop runs forever. suspect can ignore possibility because:

  • i initialized 0 , modified repeatedly adding 1 it, means take 263 iterations of loop make overflow
  • if dostuff useful work, take centuries (extrapolated crude tests) i overflow. machine program runs on not last long. not architecture won't last long either, don't need worry running on vm migrated new hardware.
  • if dostuff not useful work, operator notice wasting cpu cycles , kill process

so scenarios do need worry about?
compilers use hack?

well.. seems me answered question.

but doubt question has useful outcome.

if built-in integer has unlimited range default should not inefficient typical usage such loop counter.

i think expanding value range (and allocate more memory variable) after actual overflow occur won't hard such language.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -