Class: FloatVal

Inherits:
BaseVal show all
Defined in:
lib/tecsgen/core/value.rb

Overview

FloatVal: 実数値を扱うクラス

Instance Method Summary collapse

Methods inherited from BaseVal

#&, #<<, #>>, #^, #lAND, #lOR, #not, #unsupport, #|, #~@

Methods inherited from Node

#cdl_error, #cdl_error2, #cdl_error3, #cdl_info, #cdl_info2, #cdl_warning, #cdl_warning2, #get_locale, #locale_str, #set_locale

Constructor Details

#initialize(val) ⇒ FloatVal

@val

Float



517
518
519
520
# File 'lib/tecsgen/core/value.rb', line 517

def initialize(val)
  super()
  @val = val.to_f
end

Instance Method Details

#%(val) ⇒ Object



543
544
545
546
547
548
549
550
# File 'lib/tecsgen/core/value.rb', line 543

def %(val)
  v2 = val.to_f   # to_f を2回評価しない
  if v2 == 0.0
    cdl_error("V1018 % : divieded by zero")
    return FloatVal.new(1.0)
  end
  return FloatVal.new(@val.to_f % v2)
end

#*(val) ⇒ Object



530
531
532
# File 'lib/tecsgen/core/value.rb', line 530

def *(val)
  FloatVal.new(@val * val.to_f)
end

#+(val) ⇒ Object



552
553
554
# File 'lib/tecsgen/core/value.rb', line 552

def +(val)
  FloatVal.new(@val + val.to_f)
end

#+@Object



526
527
528
# File 'lib/tecsgen/core/value.rb', line 526

def +@
  self
end

#-(val) ⇒ Object



556
557
558
# File 'lib/tecsgen/core/value.rb', line 556

def -(val)
  FloatVal.new(@val - val.to_f)
end

#-@Object



522
523
524
# File 'lib/tecsgen/core/value.rb', line 522

def -@
  FloatVal.new(- @val)
end

#/(val) ⇒ Object



534
535
536
537
538
539
540
541
# File 'lib/tecsgen/core/value.rb', line 534

def /(val)
  v2 = val.to_f   # to_f を2回評価しない
  if v2 == 0.0
    cdl_error("V1017 / : divieded by zero")
    return FloatVal.new(1.0)
  end
  return FloatVal.new(@val.to_f / v2)
end

#<(val) ⇒ Object



564
565
566
# File 'lib/tecsgen/core/value.rb', line 564

def <(val)
  BoolVal.new(@val < val.to_f)
end

#<=(val) ⇒ Object



572
573
574
# File 'lib/tecsgen/core/value.rb', line 572

def <=(val)
  BoolVal.new(@val <= val.to_f)
end

#>(val) ⇒ Object



560
561
562
# File 'lib/tecsgen/core/value.rb', line 560

def >(val)
  BoolVal.new(@val > val.to_f)
end

#>=(val) ⇒ Object



568
569
570
# File 'lib/tecsgen/core/value.rb', line 568

def >=(val)
  BoolVal.new(@val >= val.to_f)
end

#cast(type) ⇒ Object



584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/tecsgen/core/value.rb', line 584

def cast(type)
  t = type.get_original_type # typedef の元を得る
  if t.is_a? IntType
    val = t.check_and_clip(@val, :FloatType)
    return IntegerVal.new(val)
  elsif t.is_a? FloatType
    return self
  else
    cdl_error("V1019 floating value cannot cast to $1", type)
    return self
  end
end

#eq(val) ⇒ Object

val



576
577
578
# File 'lib/tecsgen/core/value.rb', line 576

def eq(val) # == val
  BoolVal.new(@val == val.to_f)
end

#neq(val) ⇒ Object

!= val



580
581
582
# File 'lib/tecsgen/core/value.rb', line 580

def neq(val) # != val
  BoolVal.new(@val != val.to_f)
end

#to_bObject



597
598
599
600
# File 'lib/tecsgen/core/value.rb', line 597

def to_b
  cdl_error("V1020 convert floating value to bool without cast")
  @val.to_i
end

#to_fObject



611
612
613
# File 'lib/tecsgen/core/value.rb', line 611

def to_f
  @val
end

#to_iObject



602
603
604
605
# File 'lib/tecsgen/core/value.rb', line 602

def to_i
  cdl_error("V1021 convert floating value to integer without cast")
  @val.to_i
end

#to_sObject



607
608
609
# File 'lib/tecsgen/core/value.rb', line 607

def to_s
  @val.to_s
end