Miva Merchant Script Compiler#
Develop custom modules by compiling MivaScript files with the Script Compiler.
MivaScript 5.50 uses decimal floating point math internally. This is a change from all prior versions of MivaScript, which used binary floating point math. This change permits accurate and error-free conversion between numeric values and strings.
The internal implementation uses the mpdecimal
library https://www.bytereef.org/mpdecimal/index.html. This library is used by the python decimal module and php-decimal, among many other industry standard solutions.
mpdecimal
is used under the following license:
Copyright (c) 2008-2024 Stefan Krah. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS’’ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
MivaScript specifies MPD_DECIMAL64
, which provides 16 digits of precision and exponent values from -383 to 384. This is roughly equivalent in capability to the C double type used in previous versions of MivaScript. Rounding is specified as round-half-even (banker’s rounding).
All arithmetic instructions (add, sub, div, mul, etc…) now operate on decimal datatypes
.
Database libraries now detect DECIMAL columns and perform lossless string to decimal conversions without going through a binary floating point datatype.
Numeric constants with a decimal point are still encoded in compiled MivaScript files as binary floating point values. On use, these values are converted to a string, then a decimal floating point number. This storage and conversion could lead to a loss of precision. If so, impacted source code could be modified to store the value as a string instead. For example:
<MvEVAL EXPR = "{ l.variable + 0.12345678 }">
could become:
<MvEVAL EXPR = "{ l.variable + '0.12345678' }">
The compiler will output a “CW_3: Operator type does not match constant type; inefficiency or unexpected rounding may occur” warning, which can be suppressed with the “-w 3” parameter to mvc.
The following builtin functions use binary floating point data types. Values passed to these functions will be converted to binary floating point and their results will be converted back into decimal floating point. This may also lead to a loss of precision:
abs, acos, asin, atan, atan2, ceil, cos, cosh, exp, floor, fmod, log, log10, power, rnd, sin, sinh, sqrt, tan, tanh, miva_ieee754_normalize