Terry Burton
2018-07-04 22:25:36 UTC
Hi,
I'm currently looking at what it would take to implement (for Barcode Writer in Pure PostScript) a somewhat "unique" barcode standard that is in the process of being drafted.
In its current form, the error correction and interleaving routines of this symbology rely upon a well-defined source of stable, pseudo-randomised, 32-bit numbers generated according to a variant of Knuth's MMIX LCG. This is essentially a loop in which seed is a 64-bit, unsigned integer with well-defined overflow behaviour:
forever {
seed = 6364136223846793005 * seed + 1
emit seed >> 32
}
Firstly, it is quite a challenge to emulate this efficiently in PostScript using (typically) 32 bit, signed integers that are implicitly converted into reals upon overflow. (I'm aware that recent GhostScript has 64-bit, *signed* integers.) I wonder whether anyone has handled this kind of thing in PostScript before? Clearly creating a naive "bigint" library (i.e. do all operations on strings/arrays) would suck when it comes to performance. Nevertheless partitioning the 64-bit number into 16-bit ranges and carefully handling the tricky carries and overflows from the arithmetic multiply and add operations may ultimately yield sufficient performance. I haven't attempted this yet on the basis that something well-tested may already exist!
Secondly, prior to use each pseudorandom 32-bit, unsigned output is scaled to precise integer within the desired range (variable) by dividing by 2^32 then multiplying by the width of the range. I'm not even convinced that all C implementations would result in stable output because whilst they may implement the IEEE 754 for floating point representation they may also "cheap out" on proper rounding of division. For PostScript, synthesising the floating point division of an initial 32-bit, unsigned integer by "MAX_INT" then performing a multiply operation on the result seems like it would be a horrendous mess prone to round-off errors.
(To remedy the first point I'll be recommending that the standard change to a different PRNG compatible with shorter data types and does not rely of C-like datatypes. To remedy the second I'll recommend scaling the PRNG output to a desired range using iteration rather than division, e.g. https://stackoverflow.com/a/10984975/2568535.)
But in the meantime, advice from anyone familiar with handling C-like datatype semantics in PostScript is gratefully received :-)
Thanks,
Terry
I'm currently looking at what it would take to implement (for Barcode Writer in Pure PostScript) a somewhat "unique" barcode standard that is in the process of being drafted.
In its current form, the error correction and interleaving routines of this symbology rely upon a well-defined source of stable, pseudo-randomised, 32-bit numbers generated according to a variant of Knuth's MMIX LCG. This is essentially a loop in which seed is a 64-bit, unsigned integer with well-defined overflow behaviour:
forever {
seed = 6364136223846793005 * seed + 1
emit seed >> 32
}
Firstly, it is quite a challenge to emulate this efficiently in PostScript using (typically) 32 bit, signed integers that are implicitly converted into reals upon overflow. (I'm aware that recent GhostScript has 64-bit, *signed* integers.) I wonder whether anyone has handled this kind of thing in PostScript before? Clearly creating a naive "bigint" library (i.e. do all operations on strings/arrays) would suck when it comes to performance. Nevertheless partitioning the 64-bit number into 16-bit ranges and carefully handling the tricky carries and overflows from the arithmetic multiply and add operations may ultimately yield sufficient performance. I haven't attempted this yet on the basis that something well-tested may already exist!
Secondly, prior to use each pseudorandom 32-bit, unsigned output is scaled to precise integer within the desired range (variable) by dividing by 2^32 then multiplying by the width of the range. I'm not even convinced that all C implementations would result in stable output because whilst they may implement the IEEE 754 for floating point representation they may also "cheap out" on proper rounding of division. For PostScript, synthesising the floating point division of an initial 32-bit, unsigned integer by "MAX_INT" then performing a multiply operation on the result seems like it would be a horrendous mess prone to round-off errors.
(To remedy the first point I'll be recommending that the standard change to a different PRNG compatible with shorter data types and does not rely of C-like datatypes. To remedy the second I'll recommend scaling the PRNG output to a desired range using iteration rather than division, e.g. https://stackoverflow.com/a/10984975/2568535.)
But in the meantime, advice from anyone familiar with handling C-like datatype semantics in PostScript is gratefully received :-)
Thanks,
Terry