> For the record: I hate the current policy of defaulting to NVs for
> arithmetic ops. If I say '2' I do mean an IV of 2, not an NV of
> 2.000000000000000. Currently if I say
>
> $a = 2;
> $b = 3;
> $c = $a + $3;
>
> the $c will be an NV of of 5.000000000000000, or thereabouts, een
> while $a and $b are IVs. I think one should stay within one
> type/class of numbers for as long as possible.
Assuming that the perl parser generated IV SVs rather than NVs for
the 2 constants 2,3, then my scheme would handle this fine; the IV
version of add() would be called, and an IV SB would result.
However, my current scheme crashes and burns for the following:
$a = 2;
$b = 33;
$c = $a ** $b;
The way perl5 handles these cases is that $a + $b, $a * $b etc just
silengly ignore any overlow and return an int, while $a ** $b appears
to automatically upgrade to a float. My system currently says nothing
about upgrades, although it would be faily simple to specifiy that
certain standard int ops should automatically pass their args
to the std real type if theres any change of overflow.
> Similarly for literals:
> if I say
>
> $x =
10715086071862673209484250490600018105614048117055336074437503883703510511249361
22493198378815695858127594672917553146825187145285692314043598457757469857480393
45677748242309854210746050623711418779541821530464749835819412673987675591655439
46077062914571196477686542167660429831652624386837205668069376;
>
> I would prefer getting a bigint, not an NV. I am happy with requiring a
>
> use bigint;
>
> for this to happen, though.
I presume that with bigint in force, even
$x = 2
would make $x a bigint?
One way to implenment this is for there to be a vtable entry for each
class called say from_string(), which would return an SV of its own type
from a numeric literal.
[ NB - I'm not clear whether conversion from a string like '2' to a constant
SV value is performed - during parsing or execution. If necessary,
replace the word 'parse' as appropriate below...]
The parsing process would have a concept of 'who is responsible for parsing
numeric literals in the current block' - ie a current pointer to someone's
vtable.
On startup this would point to vtable_standard_nv;
'use integer' would change it to vtable_standard_iv; 'use bigint'
would change it to vtable_bigint etc. Then when a numeric literal needs
converting to an SV, the current from_string() method is called.