Update copyright year range in all GDB files.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.pascal / floats.exp
CommitLineData
b811d2c2 1# Copyright 2007-2020 Free Software Foundation, Inc.
b1c32d35
PM
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
b1c32d35
PM
16load_lib "pascal.exp"
17
17b77626 18standard_testfile .pas
b1c32d35
PM
19
20if {[gdb_compile_pascal "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
5b362f04 21 untested "failed to compile"
17b77626 22 return -1
b1c32d35
PM
23}
24
17b77626
TT
25clean_restart ${testfile}
26
b1c32d35
PM
27set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
28set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
29
30if { [gdb_breakpoint ${srcfile}:${bp_location1}] } {
31 pass "setting breakpoint 1"
32}
33if { [gdb_breakpoint ${srcfile}:${bp_location2}] } {
34 pass "setting breakpoint 2"
35}
36
37# Verify that "start" lands inside the right procedure.
38if { [gdb_start_cmd] < 0 } {
39 untested start
40 return -1
41}
42
43gdb_test "" ".* at .*${srcfile}.*" "start"
44
cdc7edd7
LM
45gdb_test "cont" "Breakpoint .*:${bp_location1}.*" "going to first breakpoint"
46gdb_test "print r" ".* = 0" "print r before assigned to 1.25"
b1c32d35 47
cdc7edd7
LM
48gdb_test "next" "r := 1\\.25;" "next to 'r := 1.25' line"
49gdb_test "next" "s := 2\\.2;" "next to 's := 2.2' line"
50gdb_test "next" "t := -3\\.2;" "next to 't := -3.2' line"
51gdb_test "next" "u := 78\\.3;" "next to 'u := 78.3' line"
52gdb_test "next" "l := 1;" "next to 'l := 1' line"
53gdb_test "next" "i := 1;" "next to 'i := 1' line"
b1c32d35
PM
54
55# At that point,
56# r should be equal to 1.25
57gdb_test "print r" " = 1\\.25"
58# s should be equal to 2.2
59gdb_test "print s" " = 2\\.(199.*|2|200.*)"
60# t should be equal to -3.2
61gdb_test "print t" " = -3\\.(199.*|2|200.*)"
62# u should be equal to 78.3
63gdb_test "print u" " = 78\\.(3|300.*|299.*)"
64
65# Test addition
66gdb_test "print r + s" " = 3\\.4(499.*|5|500.*)"
67gdb_test "print r + t" " = -1\\.9(499.*|5|500.*)"
68
69#Test addition with float constants
70gdb_test "print r + 1.5" " = 2\\.7(499.*|5|500.*)"
71gdb_test "print r + 0.03" " = 1\\.2(799.*|8|800.*)"
c087fcd3 72gdb_test "print r + (-0.2)" " = 1\\.0(499.*|5|500.*)"
b1c32d35
PM
73gdb_test "print r + 1.5E+3" " = 1501\\.2(499.*|5|500.*)"
74gdb_test "print r + 1.5E+2" " = 151\\.2(499.*|5|500.*)"
c087fcd3 75gdb_test "print r + 1.5E+1" " = 16\\.2(499.*|5|500.*)"
b1c32d35
PM
76gdb_test "print r + 1.5E+0" " = 2\\.7(499.*|5|500.*)"
77gdb_test "print r + 1.5E-1" " = 1\\.(399.*|4|400.*)"
78gdb_test "print r + 1.5E-2" " = 1\\.26(499.*|5|500.*)"
79gdb_test "print r + 1.5E-3" " = 1\\.251(499.*|5|500.*)"
80
81# Test addition with integer variables
82gdb_test "print r + l" " = 2\\.2(499.*|5|500.*)"
83gdb_test "print l + t" " = -2\\.(199.*|2|200.*)"
84
85# Test addition with integer constants
86gdb_test "print r + 10" " = 11\\.2(499.*|5|500.*)"
87gdb_test "print r + 5" " = 6\\.2(499.*|5|500.*)"
88gdb_test "print r + 1" " = 2\\.2(499.*|5|500.*)"
c087fcd3 89gdb_test "print r + 0" " = 1\\.2(499.*|5|500.*)"
b1c32d35
PM
90gdb_test "print r + (-1)" " = 0\\.2(499.*|5|500.*)"
91gdb_test "print r + (-5)" " = -3\\.7(499.*|5|500.*)"
92gdb_test "print r + (-10)" " = -8\\.7(499.*|5|500.*)"
93
94# Test substraction
95gdb_test "print r - s" " = -0\\.9(499.*|5|500.*)"
96gdb_test "print r - t" " = 4\\.4(499.*|5|500.*)"
97
98# Test unany minus
99gdb_test "print -r" " = -1\\.2(499.*|5|500.*)"
100gdb_test "print (-r)" " = -1\\.2(499.*|5|500.*)"
101gdb_test "print -(r)" " = -1.2(499.*|5|500.*)"
102gdb_test "print -(r + s)" " = -3\\.4(499.*|5|500.*)"
103
104# Test multiplication
105gdb_test "print 2 * r" " = 2\\.(499.*|5|500.*)"
106gdb_test "print 2.0 * r" " = 2\\.(499.*|5|500.*)"
107gdb_test "print 1000*r" " = 12(49\\.99.*|50|50\\.00.*)"
108
109#Test division
110gdb_test "print r / 2" " = 0\\.62(499.*|5|500.*)"
111gdb_test "print 35 / 2" " = 17\\.(499.*|5|500.*)"
112
113# 'set r' does not work, as there are set sub-commands starting with 'r'
114# Thus we need to use 'set var r'
115gdb_test "set var r := 2.56" " := 2\\.56"
cdc7edd7 116gdb_test "print r" " = 2\\.5(599.*|6|600.*)" "testing new r value"
b1c32d35
PM
117
118gdb_test "cont" \
119 "Breakpoint .*:${bp_location2}.*" \
120 "Going to second breakpoint"
cdc7edd7
LM
121gdb_test "next" "r := cos\\(u\\);" "advance to 'r := cos(u)' line"
122gdb_test "print u" " = 3\\.14159.*" "test pi value"
123gdb_test "next" "s := sin\\(u\\);" "advance to 's := sin(u)' line"
124gdb_test "print r" " = -1" "test cos(pi) is equal to -1"
125gdb_test "next" "" "go past 's := sin(u)' line"
b1c32d35
PM
126
127set msg "Test sin(pi) is equal to 0"
128
129gdb_test_multiple "print s" $msg {
130 -re ".* = (0|-?\[0-9\]\\.\[0-9\]*\[eE\](-?\[0-9\]*))\[\r\n\]+$gdb_prompt $" {
131 set value "$expect_out(1,string)"
132 verbose "value is $value" 1
133 if [info exists expect_out(2,string)] {
134 set expo $expect_out(2,string)
135 verbose "expo found: $expo" 1
136 } else {
137 set expo "0"
4ec70201 138 regsub ".*\[eE\]" "$value" "" expo
b1c32d35 139 }
4ec70201 140 regsub "^-" "$expo" "" mexpo
b1c32d35
PM
141 verbose "expo is $expo" 1
142 verbose "mexpo is $mexpo" 1
143 if { $value == 0 } {
144 pass $msg
145 } elseif {$mexpo > 8} {
146 pass "$msg '$value' is close to zero"
147 } else {
148 fail "$msg '$value' too large"
149 }
150 verbose "Still here" 1
151 }
152}
This page took 1.609103 seconds and 4 git commands to generate.