Define a primitive data type: Difference between revisions

no edit summary
(→‎{{header|Euphoria}}: Euphoria example added)
No edit summary
Line 528:
 
Similarly, we could declare the subtype of floating point numbers with restricted exponent, and so on.
 
=={{header|Java}}==
The closest you can get to defining a primitive type in Java is making a new wrapper class with methods for math operations.
Line 604 ⟶ 605:
}
}</lang>
 
=={{header|JavaScript}}==
 
<lang JavaScript>function Num(n){
if(n < 1 || n > 10)
throw new TypeError("Out of range");
this._value = n;
}
Num.prototype.valueOf = function() { return this._value; }
 
var w = new Num(3), x = new Num(4);
 
WScript.Echo(w + x); //7
 
var y = new Num(0); //TypeError
var z = new Num(11); //TypeError
</lang>
 
=={{header|MATLAB}}==
Anonymous user