lib/LaTeXML/Common/Float.pm

filter: Statementstmt 56.6% 17 / 30 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 5 / 10 Podpod 80.0% 4 / 5 totaltotal 53.0% 26 / 49 CC 3 SCAR 10.7
CC
3
Cov
50%
multiply
6.0
floatformat
6.0
Float
2.0
CRAP 2.9
« lib/LaTeXML/Post/XMath.pm ↑ Summary lib/LaTeXML/Common/Color/Derived.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Common::Float | #
3 # | Representation of floating point objects | #
4 # |=====================================================================| #
5 # | Part of LaTeXML: | #
6 # | Public domain software, produced as part of work done by the | #
7 # | United States Government & not subject to copyright in the US. | #
8 # |---------------------------------------------------------------------| #
9 # | Bruce Miller <bruce.miller@nist.gov> #_# | #
10 # | http://dlmf.nist.gov/LaTeXML/ (o o) | #
11 # \=========================================================ooo==U==ooo=/ #
12 package LaTeXML::Common::Float;
13 4 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use base qw(LaTeXML::Common::Number);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 our @EXPORT = (qw(&Float));
19  
20 #======================================================================
21 # Exported constructor.
22  
23 sub Float {
24 0 ▶ my ($number) = @_;
Subroutine Float: not called CC=1 SCAR=6.9
Pod documented
25 0 return LaTeXML::Common::Float->new($number); }
26  
27 #======================================================================
28  
29 # Strictly speaking, Float isn't part of TeX, but it's handy.
30  
31 sub toString {
32 0 ▶ my ($self) = @_;
Subroutine toString: not called CC=1 SCAR=6.9
Pod documented
33 0 return floatformat($$self[0]); }
34  
35 sub multiply {
36 0 ▶ my ($self, $other) = @_;
Subroutine multiply: not called CC=2 SCAR=17.9
Pod documented
37 0 ▶ return (ref $self)->new($self->valueOf * (ref $other ? $other->valueOf : $other)); }
Branch: 1 branch
BranchTrueFalseTotal
ref $other ? : 0 0 0
38  
39 sub stringify {
40 0 ▶ my ($self) = @_;
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
41 0 return "Float[" . $$self[0] . "]"; }
42  
43 # Utility for formatting sane numbers.
44 sub floatformat {
45 0 ▶ my ($n) = @_;
Subroutine floatformat: not called CC=2 SCAR=17.9
Pod undocumented
46 0 my $s = sprintf("%.5f", $n);
47 0 ▶ $s =~ s/0+$// if $s =~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ /\./ 0 0 0
48 # $s =~ s/\.$//;
49 0 $s =~ s/\.$/.0/; # Seems TeX prints .0 which in odd corner cases, people use?
50 0 return $s; }
51  
52 #======================================================================
53 4 1;
54  
55 __END__
« lib/LaTeXML/Post/XMath.pm ↑ Summary lib/LaTeXML/Common/Color/Derived.pm »