The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

class TestCase::Literal::FloatingPoint {
static method decimal_notation : int () {
# 0-9
{
my $all_numbers : double = 0.12345678912345;
unless ($all_numbers isa double) {
return 0;
}
unless ($all_numbers == 0.12345678912345) {
return 0;
}
}
# "-" at the beginning
{
my $minus = -0.25;
unless ($minus == -0.25) {
return 0;
}
}
# Suffix "f"
{
my $suffix_f : float = 0.25f;
unless ($suffix_f isa float) {
return 0;
}
unless ($suffix_f == 0.25f) {
return 0;
}
}
# Suffix "F"
{
my $suffix_F : float = 0.25F;
unless ($suffix_F isa float) {
return 0;
}
unless ($suffix_F == 0.25F) {
return 0;
}
}
# Suffix "d"
{
my $suffix_d : double = 0.12345678912345d;
unless ($suffix_d isa double) {
return 0;
}
unless ($suffix_d == 0.12345678912345d) {
return 0;
}
}
# Suffix "D"
{
my $suffix_D : double = 0.12345678912345D;
unless ($suffix_D isa double) {
return 0;
}
unless ($suffix_D == 0.12345678912345d) {
return 0;
}
}
# Suffix without a floating point part and an exponent part
{
my $suffix_d : double = 13d;
unless ($suffix_d isa double) {
return 0;
}
unless ($suffix_d == 13.0) {
return 0;
}
}
# Separator
{
# Simple
{
my $separator = 0.12_34;
unless ($separator == 0.1234) {
return 0;
}
}
# More complex
{
my $separator = -10_._12_34_e_-_12;
unless ($separator == -10.1234e-12) {
return 0;
}
}
}
# A exponent part
{
my $exponant_e_plus = 1.0e-2;
unless ($exponant_e_plus isa double) {
return 0;
}
unless ($exponant_e_plus == 0.01) {
return 0;
}
}
# A exponent part "e" "+"
{
my $exponant_e_plus = 0.12e+7;
unless ($exponant_e_plus isa double) {
return 0;
}
unless ($exponant_e_plus == 0.12e+7) {
return 0;
}
}
# A exponent part "E" "-"
{
my $exponant_E_minus = 0.12E-7;
unless ($exponant_E_minus isa double) {
return 0;
}
unless ($exponant_E_minus == 0.12E-7) {
return 0;
}
}
# A exponent part sign is empty
{
my $exponant_e_nosign = 0.12e7;
unless ($exponant_e_nosign == 0.12e7) {
return 0;
}
}
# A exponent part. A floating point part doesn't exist
{
my $exponant_no_point = 12e7;
unless ($exponant_no_point == 12e7) {
return 0;
}
}
# Combination with the unary "+" operator
{
my $plus = +0.25;
unless ($plus == +0.25) {
return 0;
}
}
# A floating point part, an exponent part and a suffix "f"
{
my $suffix_f : float = 0.25e0f;
unless ($suffix_f isa float) {
return 0;
}
unless ($suffix_f == 0.25f) {
return 0;
}
}
return 1;
}
static method hex_notation : int () {
# 0-9a-zA-Z
{
my $all_numbers1 = 0x0.123456789p0;
my $all_numbers2 = 0x0.abcdep0;
my $all_numbers3 = 0x0.ABCDEFp0;
unless ($all_numbers1 isa double) {
return 0;
}
unless ($all_numbers1 == 0x0.123456789p0) {
return 0;
}
unless ($all_numbers2 == 0x0.abcdep0) {
return 0;
}
unless ($all_numbers3 == 0x0.ABCDEFp0) {
return 0;
}
}
# suffix "f"
{
my $hex_suffix_f = 0x0.FFp0f;
unless ($hex_suffix_f isa float) {
return 0;
}
unless ($hex_suffix_f == 0x0.FFp0f) {
return 0;
}
}
# suffix "F"
{
my $hex_suffix_F = 0x0.FFp0F;
unless ($hex_suffix_F isa float) {
return 0;
}
unless ($hex_suffix_F == 0x0.FFp0F) {
return 0;
}
}
# suffix "d"
{
my $hex_suffix_d = 0x0.FFp0d;
unless ($hex_suffix_d isa double) {
return 0;
}
unless ($hex_suffix_d == 0x0.FFp0) {
return 0;
}
}
# suffix "D"
{
my $hex_suffix_D = 0x0.FFp0D;
unless ($hex_suffix_D isa double) {
return 0;
}
unless ($hex_suffix_D == 0x0.FFp0) {
return 0;
}
}
# Value test
{
my $hex_equals_decimal = 0x0.Fp0;
unless ($hex_equals_decimal == 0.9375) {
return 0;
}
}
# The exponent part
{
my $hex_exponent_p = 0x0.Fp-4;
unless ($hex_exponent_p == 0.05859375) {
return 0;
}
my $hex_exponent_P = 0x0.FP-4;
unless ($hex_exponent_P == 0.05859375) {
return 0;
}
my $hex_exponent_nosign = 0x0.Fp4;
unless ($hex_exponent_nosign == 0xFp0) {
return 0;
}
my $hex_exponent_plus = 0x0.Fp+4;
unless ($hex_exponent_plus == 0xFp0) {
return 0;
}
}
{
my $hex_separator = 0x0.F_Fp0;
unless ($hex_separator == 0x0.FFp0) {
return 0;
}
}
# Separator
{
# Simple
{
my $hex_separator = 0x0.F_Fp0;
unless ($hex_separator == 0x0.FFp0) {
return 0;
}
}
# More complex
{
my $hex_separator = 0x_0_._F_F_p_+_0;
unless ($hex_separator == 0x0.FFp0) {
return 0;
}
}
}
return 1;
}
}