/usr/share/perl5/LaTeXML/Number.pm is in latexml 0.7.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | # /=====================================================================\ #
# | LaTeXML::Number, LaTeXML::Dimension etc | #
# | Representation of Token(s) | #
# |=====================================================================| #
# | Part of LaTeXML: | #
# | Public domain software, produced as part of work done by the | #
# | United States Government & not subject to copyright in the US. | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov> #_# | #
# | http://dlmf.nist.gov/LaTeXML/ (o o) | #
# \=========================================================ooo==U==ooo=/ #
#**********************************************************************
package LaTeXML::Number;
use LaTeXML::Global;
use base qw(LaTeXML::Object);
use strict;
sub new {
my($class,$number)=@_;
bless [$number||"0"],$class; }
sub valueOf { $_[0]->[0]; }
sub toString { $_[0]->[0]; }
sub ptValue { int($_[0]->[0]/655.36)/100; }
sub unlist { $_[0]; }
sub revert { Explode($_[0]->toString); }
sub smaller { ($_[0]->valueOf < $_[1]->valueOf)?$_[0]:$_[1]; }
sub larger { ($_[0]->valueOf > $_[1]->valueOf)?$_[0]:$_[1]; }
sub absolute { (ref $_[0])->new(abs( $_[0]->valueOf));}
sub sign { ($_[0]->valueOf<0)?-1:(($_[0]->valueOf>0)?1:0); }
sub negate { (ref $_[0])->new(- $_[0]->valueOf); }
sub add { (ref $_[0])->new($_[0]->valueOf + $_[1]->valueOf); }
sub substract{ (ref $_[0])->new($_[0]->valueOf - $_[1]->valueOf); }
# arg 2 is a number
sub multiply { (ref $_[0])->new(int($_[0]->valueOf * (ref $_[1] ? $_[1]->valueOf : $_[1]))); }
sub stringify { "Number[".$_[0]->[0]."]"; }
# Utility for printing sane numbers.
sub simplify {
my $s = sprintf("%5f",$_[0]);
$s =~ s/0+$// if $s =~ /\./;
$s =~ s/\.$//;
$s; }
#**********************************************************************
# Strictly speaking, Float isn't part of TeX, but it's handy.
package LaTeXML::Float;
use LaTeXML::Global;
use base qw(LaTeXML::Number);
use strict;
sub toString { LaTeXML::Number::simplify($_[0]->[0]); }
sub multiply { (ref $_[0])->new($_[0]->valueOf * (ref $_[1] ? $_[1]->valueOf : $_[1])); }
sub stringify { "Float[".$_[0]->[0]."]"; }
#**********************************************************************
package LaTeXML::Dimension;
use LaTeXML::Global;
use base qw(LaTeXML::Number);
use strict;
sub new {
my($class,$sp)=@_;
$sp = "0" unless $sp;
if($sp =~ /^(\d*\.?\d*)([a-zA-Z][a-zA-Z])$/){ # Dimensions given.
$sp = $1 * $STATE->convertUnit($2); }
bless [$sp||"0"],$class; }
#sub toString { ($_[0]->[0]/65536).'pt'; }
sub toString { LaTeXML::Number::simplify($_[0]->[0]/65536).'pt'; }
sub stringify { "Dimension[".$_[0]->[0]."]"; }
#**********************************************************************
package LaTeXML::MuDimension;
use LaTeXML::Global;
use base qw(LaTeXML::Dimension);
# A mu is 1/18th of an em in the current math font.
# Sigh.... I'll just take it as 2/3pt
#sub toString { ($_[0]->[0]/65536 * 0.66).'mu'; }
sub toString { LaTeXML::Number::simplify($_[0]->[0]/65536 * 0.66).'mu'; }
sub stringify { "MuDimension[".$_[0]->[0]."]"; }
#**********************************************************************
package LaTeXML::Glue;
use LaTeXML::Global;
use base qw(LaTeXML::Dimension);
use strict;
our %fillcode=(fil=>1,fill=>2,filll=>3);
our @FILL=('','fil','fill','filll');
sub new {
my($class,$sp,$plus,$pfill,$minus,$mfill)=@_;
if((!defined $plus) && (!defined $pfill) && (!defined $minus) && (!defined $mfill)){
if($sp =~ /^(\d*\.?\d*)$/){}
elsif($sp =~ /^(\d*\.?\d*)(\w\w)(\s+plus\s*(\d*\.?\d*)(fil|fill|filll|[a-zA-Z][a-zA-Z]))?(\s+minus\s*(\d*\.?\d*)(fil|fill|filll|[a-zA-Z][a-zA-Z]))?$/){
my($f,$u,$p,$pu,$m,$mu)=($1,$2,$4,$5,$7,$8);
$sp = $f * $STATE->convertUnit($u);
if(!$pu){}
elsif($fillcode{$pu}){ $plus=$p; $pfill=$pu; }
else { $plus = $p * $STATE->convertUnit($pu); $pfill=0; }
if(!$mu){}
elsif($fillcode{$mu}){ $minus=$m; $mfill=$mu; }
else { $minus = $m * $STATE->convertUnit($mu); $mfill=0; }
}}
bless [$sp||"0",$plus||"0",$pfill||0,$minus||"0",$mfill||0],$class; }
#sub getStretch { $_[0]->[1]; }
#sub getShrink { $_[0]->[2]; }
sub toString {
my($self)=@_;
my ($sp,$plus,$pfill,$minus,$mfill)=@$self;
my $string = LaTeXML::Number::simplify($sp/65536).'pt';
$string .= ' plus '. ($pfill ? $plus .$FILL[$pfill] : LaTeXML::Number::simplify($plus/65536) .'pt') if $plus != 0;
$string .= ' minus '.($mfill ? $minus.$FILL[$mfill] : LaTeXML::Number::simplify($minus/65536).'pt') if $minus != 0;
$string; }
sub negate {
my($pts,$p,$pf,$m,$mf)=@{$_[0]};
(ref $_[0])->new(-$pts,-$p,$pf,-$m,$mf); }
sub add {
my($self,$other)=@_;
my($pts,$p,$pf,$m,$mf)=@$self;
if(ref $other eq 'LaTeXML::Glue'){
my($pts2,$p2,$pf2,$m2,$mf2)=@$other;
$pts += $pts2;
if($pf == $pf2){ $p+=$p2; }
elsif($pf < $pf2){ $p=$p2; $pf=$pf2; }
if($mf == $mf2){ $m+=$m2; }
elsif($mf < $mf2){ $m=$m2; $mf=$mf2; }
(ref $_[0])->new($pts,$p,$pf,$m,$mf); }
else {
(ref $_[0])->new($pts+$other->valueOf,$p,$pf,$m,$mf); }}
sub multiply {
my($self,$other)=@_;
my($pts,$p,$pf,$m,$mf)=@$self;
$other = $other->valueOf if ref $other;
(ref $_[0])->new($pts*$other,$p*$other,$pf,$m*$other,$mf); }
sub stringify { "Glue[".join(',',@{$_[0]})."]"; }
#**********************************************************************
package LaTeXML::MuGlue;
use LaTeXML::Global;
use base qw(LaTeXML::Glue);
sub toString {
my($self)=@_;
my ($sp,$plus,$pfill,$minus,$mfill)=@$self;
my $string = LaTeXML::Number::simplify($sp/65536 * 0.66)."mu";
$string .= ' plus '. ($pfill ? $plus .$FILL[$pfill] : LaTeXML::Number::simplify($plus/65536 * 0.66) .'mu') if $plus != 0;
$string .= ' minus '.($mfill ? $minus.$FILL[$mfill] : LaTeXML::Number::simplify($minus/65536 * 0.66).'mu') if $minus != 0;
$string; }
sub stringify { "MuGlue[".join(',',@{$_[0]})."]"; }
#**********************************************************************
package LaTeXML::BoxDimensions;
use LaTeXML::Global;
use base qw(LaTeXML::Object);
sub new {
my($class,%specs)=@_;
bless {%specs},$class; }
sub toString {
my($self)=@_;
join(' ',map(ToString($_).' '.ToString($$self{$_}), keys %{$self})); }
sub revert {
my($self)=@_;
map( (Explode($_),T_SPACE,$$self{$_}->revert), keys %{$self}); }
#**********************************************************************
package LaTeXML::Pair;
use LaTeXML::Global;
use base qw(LaTeXML::Object);
sub new {
my($class,$x,$y)=@_;
bless [$x,$y],$class; }
sub getX { $_[0][0]; }
sub getY { $_[0][1]; }
# multiply by anything; this keeps the same type of elements in the pair
sub multiplyN { (ref $_[0])->new($_[0][0]->multiply($_[1]),$_[0][1]->multiply($_[2] || $_[1])); }
# multiply by a dimension or such; this upgrades the elements in the pair to
# the type used in multiplication
sub multiply { return $_[0]->multiplyN($_[1], $_[2]) unless (ref $_[1] && (!$_[2] || ref $_[2]));
(ref $_[0])->new($_[1]->multiply($_[0][0]), ($_[2] || $_[1])->multiply($_[0][1])); }
sub swap { (ref $_[0])->new($_[0][1], $_[0][0]); }
sub ptValue { $_[0][0]->ptValue().','.$_[0][1]->ptValue(); }
sub toString { $_[0][0]->toString().','.$_[0][1]->toString(); }
sub stringify{ "Pair[".join(',',map($_->stringify, @{$_[0]}))."]"; }
sub revert {
my($self)=@_;
(T_OTHER('('),$$self[0]->revert,T_OTHER(','),$$self[1]->revert,T_OTHER(')')); }
#**********************************************************************
package LaTeXML::PairList;
use base qw(LaTeXML::Object);
sub new {
my($class,@pairs)=@_;
bless [@pairs],$class; }
sub getCount { $#{$_[0]} + 1; }
sub getPair { $_[0][$_[1]]; }
sub getPairs { @{$_[0]}; }
sub ptValue { join(' ', map($_->ptValue, @{$_[0]})); }
sub toString { join(' ', map($_->toString, @{$_[0]})); }
sub stringify { "PairList[".join(',', map($_->stringify, @{$_[0]}))."]"; }
sub revert { my @rev=(); map(push(@rev, $_->revert), @{$_[0]}); @rev; }
1;
__END__
=pod
=head1 NAME
C<LaTeXML::Number> - representation of numbers, dimensions, skips and glue.
=head1 DESCRIPTION
This module defines various dimension and number-like data objects
=over 4
=item C<LaTeXML::Number>
represents numbers,
=item C<LaTeXML::Float>
=begin latex
\label{LaTeXML::Float}
=end latex
represents floating-point numbers,
=item C<LaTeXML::Dimension>
=begin latex
\label{LaTeXML::Dimension}
=end latex
represents dimensions,
=item C<LaTeXML::MuDimension>
=begin latex
\label{LaTeXML::MuDimension}
=end latex
represents math dimensions,
=item C<LaTeXML::Glue>
=begin latex
\label{LaTeXML::Glue}
=end latex
represents glue (skips),
=item C<LaTeXML::MuGlue>
=begin latex
\label{LaTeXML::MuGlue}
=end latex
represents math glue,
=item C<LaTeXML::Pair>
=begin latex
\label{LaTeXML::Pair}
=end latex
represents pairs of numbers
=item C<LaTeXML::Pairlist>
=begin latex
\label{LaTeXML::PairList}
=end latex
represents list of pairs.
=back
=head2 Common methods
The following methods apply to all objects.
=over 4
=item C<< @tokens = $object->unlist; >>
Return a list of the tokens making up this C<$object>.
=item C<< $string = $object->toString; >>
Return a string representing C<$object>.
=item C<< $string = $object->ptValue; >>
Return a value representing C<$object> without the measurement unit (pt)
with limited decimal places.
=back
=head2 Numerics methods
These methods apply to the various numeric objects
=over 4
=item C<< $n = $object->valueOf; >>
Return the value in scaled points (ignoring shrink and stretch, if any).
=item C<< $n = $object->smaller($other); >>
Return C<$object> or C<$other>, whichever is smaller
=item C<< $n = $object->larger($other); >>
Return C<$object> or C<$other>, whichever is larger
=item C<< $n = $object->absolute; >>
Return an object representing the absolute value of the C<$object>.
=item C<< $n = $object->sign; >>
Return an integer: -1 for negatives, 0 for 0 and 1 for positives
=item C<< $n = $object->negate; >>
Return an object representing the negative of the C<$object>.
=item C<< $n = $object->add($other); >>
Return an object representing the sum of C<$object> and C<$other>
=item C<< $n = $object->subtract($other); >>
Return an object representing the difference between C<$object> and C<$other>
=item C<< $n = $object->multiply($n); >>
Return an object representing the product of C<$object> and C<$n> (a regular number).
=back
=head1 AUTHOR
Bruce Miller <bruce.miller@nist.gov>
=head1 COPYRIGHT
Public domain software, produced as part of work done by the
United States Government & not subject to copyright in the US.
=cut
|